]> git.baikalelectronics.ru Git - kernel.git/commitdiff
integrity: Fix memory leakage in keyring allocation error path
authorGUO Zihua <guozihua@huawei.com>
Fri, 11 Nov 2022 10:13:17 +0000 (18:13 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Jan 2023 10:41:03 +0000 (11:41 +0100)
[ Upstream commit 39419ef7af0916cc3620ecf1ed42d29659109bf3 ]

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

Fixes: b072e1c2e6eb ("KEYS: Use structure to capture key restriction function and data")
Signed-off-by: GUO Zihua <guozihua@huawei.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
security/integrity/digsig.c

index ea1aae3d07b3cb083a0e2e4e939e0d502acdd914..12bae47142113139605e021a4db160666fb95f1e 100644 (file)
@@ -121,6 +121,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;
@@ -141,7 +142,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;
 }
 
 int __init integrity_add_key(const unsigned int id, const void *data,