From: John Johansen Date: Thu, 17 Dec 2015 02:09:10 +0000 (-0800) Subject: apparmor: fix refcount race when finding a child profile X-Git-Tag: v4.7.4~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a913c940039ce803939bb81f3c3be3aab0d43b5c;p=thirdparty%2Fkernel%2Fstable.git apparmor: fix refcount race when finding a child profile commit de7c4cc947f9f56f61520ee7edaf380434a98c8d upstream. When finding a child profile via an rcu critical section, the profile may be put and scheduled for deletion after the child is found but before its refcount is incremented. Protect against this by repeating the lookup if the profiles refcount is 0 and is one its way to deletion. Signed-off-by: John Johansen Acked-by: Seth Arnold Signed-off-by: Greg Kroah-Hartman --- diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c index 705c2879d3a94..7347fcc4f4517 100644 --- a/security/apparmor/policy.c +++ b/security/apparmor/policy.c @@ -766,7 +766,9 @@ struct aa_profile *aa_find_child(struct aa_profile *parent, const char *name) struct aa_profile *profile; rcu_read_lock(); - profile = aa_get_profile(__find_child(&parent->base.profiles, name)); + do { + profile = __find_child(&parent->base.profiles, name); + } while (profile && !aa_get_profile_not0(profile)); rcu_read_unlock(); /* refcount released by caller */