Skip to contentSkip to conversation

integrity: Fix memory leakage in keyring allocation error path

PATCH Applied GUO Zihua 2 participants 2 messages Nov 11, 2022 – Nov 16, 2022

Subsystems (4)
lore
Share & tools
lore

GUO Zihua

author
#0 lore raw

PATCH v2 1/1 integrity: Fix memory leakage in keyring allocation error path

Key restriction is alloced in integrity_init_keyring(). However, if keyring allocation failed, it is not freed, causing memory leaks.

Fixes 2b6aa412ff23 ("KEYS: Use structure to capture key restriction function and data")

---

v2:
Added Fixes tag. Changed subject. V1 patch is here: https://patchwork.kernel.org/project/linux-integrity/patch/[email protected]/

---
 security/integrity/digsig.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
security/integrity/digsig.c +5 -1
index 8a82a6c7f48a..f2193c531f4a 100644
@@ -126,6 +126,7 @@ int __init integrity_init_keyring(const unsigned int id)
 {
 	struct key_restriction *restriction;
 	key_perm_t perm;
+	int ret;
 
 	perm = (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_VIEW
 		| KEY_USR_READ | KEY_USR_SEARCH;
@@ -154,7 +155,10 @@ int __init integrity_init_keyring(const unsigned int id)
 		perm |= KEY_USR_WRITE;
 
 out:
-	return __integrity_init_keyring(id, perm, restriction);
+	ret = __integrity_init_keyring(id, perm, restriction);
+	if (ret)
+		kfree(restriction);
+	return ret;
 }
 
 static int __init integrity_add_key(const unsigned int id, const void *data,
Signature · 1 line
2.17.1
maintainer Applied
#1 lore raw
Quoted 5 lines · GUO Zihua

Key restriction is alloced in integrity_init_keyring(). However, if keyring allocation failed, it is not freed, causing memory leaks.

Fixes 2b6aa412ff23 ("KEYS: Use structure to capture key restriction function and data")

Thanks, applied.

Mimi