Skip to content
/ linux Public

Commit 24bb7d1

Browse files
rlee287Sasha Levin
authored andcommitted
apparmor: return -ENOMEM in unpack_perms_table upon alloc failure
[ Upstream commit 74b7105 ] In policy_unpack.c:unpack_perms_table, the perms struct is allocated via kcalloc, with the position being reset if the allocation fails. However, the error path results in -EPROTO being retured instead of -ENOMEM. Fix this to return the correct error code. Reported-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com> Fixes: fd1b2b9 ("apparmor: add the ability for policy to specify a permission table") Reviewed-by: Tyler Hicks <code@tyhicks.com> Signed-off-by: Ryan Lee <ryan.lee@canonical.com> Signed-off-by: John Johansen <john.johansen@canonical.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 0dc19bc commit 24bb7d1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

security/apparmor/policy_unpack.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,10 @@ static ssize_t unpack_perms_table(struct aa_ext *e, struct aa_perms **perms)
683683
if (!aa_unpack_array(e, NULL, &size))
684684
goto fail_reset;
685685
*perms = kcalloc(size, sizeof(struct aa_perms), GFP_KERNEL);
686-
if (!*perms)
687-
goto fail_reset;
686+
if (!*perms) {
687+
e->pos = pos;
688+
return -ENOMEM;
689+
}
688690
for (i = 0; i < size; i++) {
689691
if (!unpack_perm(e, version, &(*perms)[i]))
690692
goto fail;

0 commit comments

Comments
 (0)