Skip to content

Commit

Permalink
apparmor: fix potential label refcnt leak in aa_change_profile
Browse files Browse the repository at this point in the history
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: 9fcf78c ("apparmor: update domain transitions that are subsets of confinement at nnp")
Signed-off-by: Xiyu Yang <[email protected]>
Signed-off-by: Xin Tan <[email protected]>
Signed-off-by: John Johansen <[email protected]>
  • Loading branch information
sherlly authored and John Johansen committed May 21, 2020
1 parent b85051e commit a0b845f
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions security/apparmor/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,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;
}
Expand All @@ -1346,8 +1347,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 */
Expand Down

0 comments on commit a0b845f

Please sign in to comment.