Skip to content

Commit

Permalink
apparmor: fix race condition in null profile creation
Browse files Browse the repository at this point in the history
There is a race when null- profile is being created between the
initial lookup/creation of the profile and lock/addition of the
profile. This could result in multiple version of a profile being
added to the list which need to be removed/replaced.

Since these are learning profile their is no affect on mediation.

Signed-off-by: John Johansen <[email protected]>
  • Loading branch information
John Johansen committed Sep 22, 2017
1 parent d07881d commit 290638a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions security/apparmor/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,8 @@ struct aa_profile *aa_fqlookupn_profile(struct aa_label *base,
struct aa_profile *aa_new_null_profile(struct aa_profile *parent, bool hat,
const char *base, gfp_t gfp)
{
struct aa_profile *profile;
struct aa_profile *p, *profile;
const char *bname;
char *name;

AA_BUG(!parent);
Expand All @@ -523,7 +524,8 @@ struct aa_profile *aa_new_null_profile(struct aa_profile *parent, bool hat,

name:
/* lookup to see if this is a dup creation */
profile = aa_find_child(parent, basename(name));
bname = basename(name);
profile = aa_find_child(parent, bname);
if (profile)
goto out;

Expand All @@ -544,7 +546,13 @@ struct aa_profile *aa_new_null_profile(struct aa_profile *parent, bool hat,
profile->policy.dfa = aa_get_dfa(nulldfa);

mutex_lock(&profile->ns->lock);
__add_profile(&parent->base.profiles, profile);
p = __find_child(&parent->base.profiles, bname);
if (p) {
aa_free_profile(profile);
profile = aa_get_profile(p);
} else {
__add_profile(&parent->base.profiles, profile);
}
mutex_unlock(&profile->ns->lock);

/* refcount released by caller */
Expand Down

0 comments on commit 290638a

Please sign in to comment.