diff --git a/security/apparmor/include/policy_ns.h b/security/apparmor/include/policy_ns.h index cc6e84151812..4f8359875476 100644 --- a/security/apparmor/include/policy_ns.h +++ b/security/apparmor/include/policy_ns.h @@ -117,6 +117,22 @@ static inline struct aa_ns *aa_get_ns(struct aa_ns *ns) return ns; } +/** + * aa_get_ns_not0 - increment references count on @ns found via lookup + * @ns: namespace to increment reference count of (MAYBE NULL) + * + * Returns: pointer to @ns, if @ns is NULL returns NULL, + * NULL if @ns is being freed + * Requires: @ns must be held with valid refcount when called + */ +static inline struct aa_ns *aa_get_ns_not0(struct aa_ns *ns) +{ + if (ns && aa_get_profile_not0(ns->unconfined)) + return ns; + + return NULL; +} + /** * aa_put_ns - decrement refcount on @ns * @ns: namespace to put reference of diff --git a/security/apparmor/policy_ns.c b/security/apparmor/policy_ns.c index 45e66b14c2d5..7d5c768493e8 100644 --- a/security/apparmor/policy_ns.c +++ b/security/apparmor/policy_ns.c @@ -207,7 +207,7 @@ struct aa_ns *aa_lookupn_ns(struct aa_ns *view, const char *name, size_t n) struct aa_ns *ns = NULL; rcu_read_lock(); - ns = aa_get_ns(__aa_lookupn_ns(view, name, n)); + ns = aa_get_ns_not0(__aa_lookupn_ns(view, name, n)); rcu_read_unlock(); return ns;