diff options
author | GUO Zihua <guozihua@huawei.com> | 2022-11-11 18:13:17 +0800 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2023-01-14 10:15:29 +0100 |
commit | 3bd737289c26be3cee4b9afaf61ef784a2af9d6e (patch) | |
tree | 07cfcc9c85ef15e85cd7a0b6320b07fe9194e198 /security | |
parent | 102df01caf5ebf8948d00de1ae53fd730a454905 (diff) | |
download | linux-stable-3bd737289c26be3cee4b9afaf61ef784a2af9d6e.tar.gz linux-stable-3bd737289c26be3cee4b9afaf61ef784a2af9d6e.tar.bz2 linux-stable-3bd737289c26be3cee4b9afaf61ef784a2af9d6e.zip |
integrity: Fix memory leakage in keyring allocation error path
[ Upstream commit 39419ef7af0916cc3620ecf1ed42d29659109bf3 ]
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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'security')
-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 0f518dcfde05..de442af7b336 100644 --- a/security/integrity/digsig.c +++ b/security/integrity/digsig.c @@ -120,6 +120,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; @@ -140,7 +141,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, |