[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20221109094618.64265-1-guozihua@huawei.com>
Date: Wed, 9 Nov 2022 17:46:18 +0800
From: GUO Zihua <guozihua@...wei.com>
To: <zohar@...ux.ibm.com>, <dmitry.kasatkin@...il.com>
CC: <paul@...l-moore.com>, <jmorris@...ei.org>, <serge@...lyn.com>,
<linux-integrity@...r.kernel.org>,
<linux-security-module@...r.kernel.org>,
<linux-kernel@...r.kernel.org>
Subject: [PATCH] integrity: Free key restriction when keyring allocation fails
Key restriction is alloced in integrity_init_keyring(). However, if
keyring allocation failed, it is not freed, causing memory leaks.
Signed-off-by: GUO Zihua <guozihua@...wei.com>
---
security/integrity/digsig.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/security/integrity/digsig.c b/security/integrity/digsig.c
index 8a82a6c7f48a..f2193c531f4a 100644
--- a/security/integrity/digsig.c
+++ b/security/integrity/digsig.c
@@ -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,
--
2.17.1
Powered by blists - more mailing lists