Commit 30603941 authored by John Johansen's avatar John Johansen
Browse files

apparmor: fix: limit the number of levels of policy namespaces



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: c88d4c7b ("AppArmor: core policy routines")
Reported-by: default avatarQualys Security Advisory <qsa@qualys.com>
Reviewed-by: default avatarRyan Lee <ryan.lee@canonical.com>
Reviewed-by: default avatarCengiz Can <cengiz.can@canonical.com>
Signed-off-by: default avatarJohn Johansen <john.johansen@canonical.com>
parent ab092646
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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
+2 −0
Original line number Diff line number Diff line
@@ -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);