Skip to content

Commit

Permalink
integrity: Fix memory leakage in keyring allocation error path
Browse files Browse the repository at this point in the history
[ Upstream commit 39419ef ]

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

Fixes: 2b6aa41 ("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>
  • Loading branch information
GUO Zihua authored and gregkh committed Dec 31, 2022
1 parent accc799 commit c591c48
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion security/integrity/digsig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c591c48

Please sign in to comment.