linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [v2] evm: Fix memleak in init_desc
@ 2021-01-10  8:02 Dinghao Liu
       [not found] ` <7288d0ce-e900-d942-fb6b-eabb63649591@web.de>
  2021-01-13 15:16 ` [PATCH] [v2] evm: Fix memleak " Mimi Zohar
  0 siblings, 2 replies; 3+ messages in thread
From: Dinghao Liu @ 2021-01-10  8:02 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Mimi Zohar, James Morris, Serge E. Hallyn, Dmitry Kasatkin,
	linux-integrity, linux-security-module, linux-kernel

When kmalloc() fails, tmp_tfm allocated by
crypto_alloc_shash() has not been freed, which
leads to memleak.

Fixes: d46eb3699502b ("evm: crypto hash replaced by shash")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---

Changelog:

v2: - Remove checks against tmp_tfm before freeing.
---
 security/integrity/evm/evm_crypto.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/security/integrity/evm/evm_crypto.c b/security/integrity/evm/evm_crypto.c
index 168c3b78ac47..a6dd47eb086d 100644
--- a/security/integrity/evm/evm_crypto.c
+++ b/security/integrity/evm/evm_crypto.c
@@ -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) {
@@ -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);
 	}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-13 15:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-10  8:02 [PATCH] [v2] evm: Fix memleak in init_desc Dinghao Liu
     [not found] ` <7288d0ce-e900-d942-fb6b-eabb63649591@web.de>
2021-01-11 13:46   ` [PATCH v2] evm: Fix memory leak " Mimi Zohar
2021-01-13 15:16 ` [PATCH] [v2] evm: Fix memleak " Mimi Zohar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).