Skip to content

Commit

Permalink
evm: Fix memleak in init_desc
Browse files Browse the repository at this point in the history
[ Upstream commit ccf11db ]

tmp_tfm is allocated, but not freed on subsequent kmalloc failure, which
leads to a memory leak.  Free tmp_tfm.

Fixes: d46eb36 ("evm: crypto hash replaced by shash")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
[zohar@linux.ibm.com: formatted/reworded patch description]
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
dinghaoliu authored and gregkh committed Mar 4, 2021
1 parent 977630f commit b005820
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions security/integrity/evm/evm_crypto.c
Expand Up @@ -73,7 +73,7 @@ static struct shash_desc *init_desc(char type, uint8_t hash_algo)
{
long rc;
const char *algo;
struct crypto_shash **tfm, *tmp_tfm;
struct crypto_shash **tfm, *tmp_tfm = NULL;
struct shash_desc *desc;

if (type == EVM_XATTR_HMAC) {
Expand Down Expand Up @@ -118,13 +118,16 @@ static struct shash_desc *init_desc(char type, uint8_t hash_algo)
alloc:
desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(*tfm),
GFP_KERNEL);
if (!desc)
if (!desc) {
crypto_free_shash(tmp_tfm);
return ERR_PTR(-ENOMEM);
}

desc->tfm = *tfm;

rc = crypto_shash_init(desc);
if (rc) {
crypto_free_shash(tmp_tfm);
kfree(desc);
return ERR_PTR(rc);
}
Expand Down

0 comments on commit b005820

Please sign in to comment.