Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: d46eb3699502b ("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>

authored by

Dinghao Liu and committed by
Mimi Zohar
ccf11dba 7c53f6b6

+5 -2
+5 -2
security/integrity/evm/evm_crypto.c
··· 73 73 { 74 74 long rc; 75 75 const char *algo; 76 - struct crypto_shash **tfm, *tmp_tfm; 76 + struct crypto_shash **tfm, *tmp_tfm = NULL; 77 77 struct shash_desc *desc; 78 78 79 79 if (type == EVM_XATTR_HMAC) { ··· 118 118 alloc: 119 119 desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(*tfm), 120 120 GFP_KERNEL); 121 - if (!desc) 121 + if (!desc) { 122 + crypto_free_shash(tmp_tfm); 122 123 return ERR_PTR(-ENOMEM); 124 + } 123 125 124 126 desc->tfm = *tfm; 125 127 126 128 rc = crypto_shash_init(desc); 127 129 if (rc) { 130 + crypto_free_shash(tmp_tfm); 128 131 kfree(desc); 129 132 return ERR_PTR(rc); 130 133 }