]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
apparmor: fix: limit the number of levels of policy namespaces
authorJohn Johansen <john.johansen@canonical.com>
Tue, 3 Mar 2026 19:08:02 +0000 (11:08 -0800)
committerJohn Johansen <john.johansen@canonical.com>
Mon, 9 Mar 2026 23:05:43 +0000 (16:05 -0700)
Currently the number of policy namespaces is not bounded relying on
the user namespace limit. However policy namespaces aren't strictly
tied to user namespaces and it is possible to create them and nest
them arbitrarily deep which can be used to exhaust system resource.

Hard cap policy namespaces to the same depth as user namespaces.

Fixes: c88d4c7b049e8 ("AppArmor: core policy routines")
Reported-by: Qualys Security Advisory <qsa@qualys.com>
Reviewed-by: Ryan Lee <ryan.lee@canonical.com>
Reviewed-by: Cengiz Can <cengiz.can@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
security/apparmor/include/policy_ns.h
security/apparmor/policy_ns.c

index d646070fd966bece5d102e9d11adb8e2f06b2466..cc6e8415181209567f5a28fb38e2e53593684183 100644 (file)
@@ -18,6 +18,8 @@
 #include "label.h"
 #include "policy.h"
 
+/* Match max depth of user namespaces */
+#define MAX_NS_DEPTH 32
 
 /* struct aa_ns_acct - accounting of profiles in namespace
  * @max_size: maximum space allowed for all profiles in namespace
index 01b653a3609bc88bc083d567c99636b479b6c246..5a907a875d8f6c635241dbccfe68417735bfca44 100644 (file)
@@ -223,6 +223,8 @@ static struct aa_ns *__aa_create_ns(struct aa_ns *parent, const char *name,
        AA_BUG(!name);
        AA_BUG(!mutex_is_locked(&parent->lock));
 
+       if (parent->level > MAX_NS_DEPTH)
+               return ERR_PTR(-ENOSPC);
        ns = alloc_ns(parent->base.hname, name);
        if (!ns)
                return ERR_PTR(-ENOMEM);