Skip to content

Commit 51dd64b

Browse files
Xiu Jianfengmimizohar
authored andcommitted
Revert "evm: Fix memleak in init_desc"
This reverts commit ccf11db. Commit ccf11db ("evm: Fix memleak in init_desc") said there is memleak in init_desc. That may be incorrect, as we can see, tmp_tfm is saved in one of the two global variables hmac_tfm or evm_tfm[hash_algo], then if init_desc is called next time, there is no need to alloc tfm again, so in the error path of kmalloc desc or crypto_shash_init(desc), It is not a problem without freeing tmp_tfm. And also that commit did not reset the global variable to NULL after freeing tmp_tfm and this makes *tfm a dangling pointer which may cause a UAF issue. Reported-by: Guozihua (Scott) <guozihua@huawei.com> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent b13bacc commit 51dd64b

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

security/integrity/evm/evm_crypto.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static struct shash_desc *init_desc(char type, uint8_t hash_algo)
7575
{
7676
long rc;
7777
const char *algo;
78-
struct crypto_shash **tfm, *tmp_tfm = NULL;
78+
struct crypto_shash **tfm, *tmp_tfm;
7979
struct shash_desc *desc;
8080

8181
if (type == EVM_XATTR_HMAC) {
@@ -120,16 +120,13 @@ static struct shash_desc *init_desc(char type, uint8_t hash_algo)
120120
alloc:
121121
desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(*tfm),
122122
GFP_KERNEL);
123-
if (!desc) {
124-
crypto_free_shash(tmp_tfm);
123+
if (!desc)
125124
return ERR_PTR(-ENOMEM);
126-
}
127125

128126
desc->tfm = *tfm;
129127

130128
rc = crypto_shash_init(desc);
131129
if (rc) {
132-
crypto_free_shash(tmp_tfm);
133130
kfree(desc);
134131
return ERR_PTR(rc);
135132
}

0 commit comments

Comments
 (0)