提交 46f6f18b 编写于 作者: X Xiu Jianfeng 提交者: Zheng Zengkai

Revert "evm: Fix memleak in init_desc"

stable inclusion
from stable-v5.10.132
commit 9d883b3f000d405d19b3484e3d8d97796e6854c6
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5YS3T

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=9d883b3f000d405d19b3484e3d8d97796e6854c6

--------------------------------

commit 51dd64bb upstream.

This reverts commit ccf11dba.

Commit ccf11dba ("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: NGuozihua (Scott) <guozihua@huawei.com>
Signed-off-by: NXiu Jianfeng <xiujianfeng@huawei.com>
Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>

 Conflicts:
	security/integrity/evm/evm_crypto.c
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
上级 cce45fde
...@@ -73,7 +73,7 @@ static struct shash_desc *init_desc(char type, uint8_t hash_algo) ...@@ -73,7 +73,7 @@ static struct shash_desc *init_desc(char type, uint8_t hash_algo)
{ {
long rc; long rc;
const char *algo; const char *algo;
struct crypto_shash **tfm, *tmp_tfm = NULL; struct crypto_shash **tfm, *tmp_tfm;
char evm_hmac[CRYPTO_MAX_ALG_NAME]; char evm_hmac[CRYPTO_MAX_ALG_NAME];
struct shash_desc *desc; struct shash_desc *desc;
...@@ -122,16 +122,13 @@ static struct shash_desc *init_desc(char type, uint8_t hash_algo) ...@@ -122,16 +122,13 @@ static struct shash_desc *init_desc(char type, uint8_t hash_algo)
alloc: alloc:
desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(*tfm), desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(*tfm),
GFP_KERNEL); GFP_KERNEL);
if (!desc) { if (!desc)
crypto_free_shash(tmp_tfm);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
}
desc->tfm = *tfm; desc->tfm = *tfm;
rc = crypto_shash_init(desc); rc = crypto_shash_init(desc);
if (rc) { if (rc) {
crypto_free_shash(tmp_tfm);
kfree(desc); kfree(desc);
return ERR_PTR(rc); return ERR_PTR(rc);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册