Commit ccf11dba authored by Dinghao Liu's avatar Dinghao Liu Committed by Mimi Zohar

evm: Fix memleak in init_desc

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

Fixes: d46eb369 ("evm: crypto hash replaced by shash")
Signed-off-by: default avatarDinghao Liu <dinghao.liu@zju.edu.cn>
[zohar@linux.ibm.com: formatted/reworded patch description]
Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
parent 7c53f6b6
...@@ -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; struct crypto_shash **tfm, *tmp_tfm = NULL;
struct shash_desc *desc; struct shash_desc *desc;
if (type == EVM_XATTR_HMAC) { if (type == EVM_XATTR_HMAC) {
...@@ -118,13 +118,16 @@ static struct shash_desc *init_desc(char type, uint8_t hash_algo) ...@@ -118,13 +118,16 @@ 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%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment