Skip to content

Commit 290638a

Browse files
committed
apparmor: fix race condition in null profile creation
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]>
1 parent d07881d commit 290638a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

security/apparmor/policy.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,8 @@ struct aa_profile *aa_fqlookupn_profile(struct aa_label *base,
500500
struct aa_profile *aa_new_null_profile(struct aa_profile *parent, bool hat,
501501
const char *base, gfp_t gfp)
502502
{
503-
struct aa_profile *profile;
503+
struct aa_profile *p, *profile;
504+
const char *bname;
504505
char *name;
505506

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

524525
name:
525526
/* lookup to see if this is a dup creation */
526-
profile = aa_find_child(parent, basename(name));
527+
bname = basename(name);
528+
profile = aa_find_child(parent, bname);
527529
if (profile)
528530
goto out;
529531

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

546548
mutex_lock(&profile->ns->lock);
547-
__add_profile(&parent->base.profiles, profile);
549+
p = __find_child(&parent->base.profiles, bname);
550+
if (p) {
551+
aa_free_profile(profile);
552+
profile = aa_get_profile(p);
553+
} else {
554+
__add_profile(&parent->base.profiles, profile);
555+
}
548556
mutex_unlock(&profile->ns->lock);
549557

550558
/* refcount released by caller */

0 commit comments

Comments
 (0)