1
0
Fork 0

apparmor: fix potential label refcnt leak in aa_change_profile

commit a0b845ffa0 upstream.

aa_change_profile() invokes aa_get_current_label(), which returns
a reference of the current task's label.

According to the comment of aa_get_current_label(), the returned
reference must be put with aa_put_label().
However, when the original object pointed by "label" becomes
unreachable because aa_change_profile() returns or a new object
is assigned to "label", reference count increased by
aa_get_current_label() is not decreased, causing a refcnt leak.

Fix this by calling aa_put_label() before aa_change_profile() return
and dropping unnecessary aa_get_current_label().

Fixes: 9fcf78cca1 ("apparmor: update domain transitions that are subsets of confinement at nnp")
Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
5.4-rM2-2.2.x-imx-squashed
Xiyu Yang 2020-04-05 13:11:55 +08:00 committed by Greg Kroah-Hartman
parent 97d817b9ef
commit 054934aa9f
1 changed files with 1 additions and 2 deletions

View File

@ -1334,6 +1334,7 @@ int aa_change_profile(const char *fqname, int flags)
ctx->nnp = aa_get_label(label);
if (!fqname || !*fqname) {
aa_put_label(label);
AA_DEBUG("no profile name");
return -EINVAL;
}
@ -1352,8 +1353,6 @@ int aa_change_profile(const char *fqname, int flags)
op = OP_CHANGE_PROFILE;
}
label = aa_get_current_label();
if (*fqname == '&') {
stack = true;
/* don't have label_parse() do stacking */