Commit 39419ef7 authored by GUO Zihua's avatar GUO Zihua Committed by Mimi Zohar

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: 2b6aa412 ("KEYS: Use structure to capture key restriction function and data")
Signed-off-by: default avatarGUO Zihua <guozihua@huawei.com>
Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
parent 8c1d6a05
......@@ -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,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment