diff options
author | GUO Zihua <guozihua@huawei.com> | 2022-11-11 11:13:17 +0100 |
---|---|---|
committer | Mimi Zohar <zohar@linux.ibm.com> | 2022-11-16 17:47:47 +0100 |
commit | 39419ef7af0916cc3620ecf1ed42d29659109bf3 (patch) | |
tree | a8860ea73819ff37094484b419c843ff0d53f65a /security/integrity | |
parent | ima: Fix memory leak in __ima_inode_hash() (diff) | |
download | linux-39419ef7af0916cc3620ecf1ed42d29659109bf3.tar.xz linux-39419ef7af0916cc3620ecf1ed42d29659109bf3.zip |
integrity: Fix memory leakage in keyring allocation error path
Key restriction is allocated 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")
Signed-off-by: GUO Zihua <guozihua@huawei.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
Diffstat (limited to 'security/integrity')
-rw-r--r-- | security/integrity/digsig.c | 6 |
1 files changed, 5 insertions, 1 deletions
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, |