Skip to contentSkip to conversation

userns: per-namespace capability bounding set

PATCH In review Hallgrimur H. Gunnarsson 6 participants 23 messages Nov 19 – Nov 24

Subsystems (9)
lore
Share & tools
lore
#0 lore raw

v2 cover userns: per-namespace capability bounding set

When an unprivileged process creates a new user namespace, it is granted a full set of capabilities (CAP_FULL_SET) scoped to that namespace. While isolated to the namespace, these capabilities allow unprivileged local users to reach deep kernel subsystems (most notably networking configuration and raw sockets via CAP_NET_ADMIN and CAP_NET_RAW) that historically assumed a trusted caller and have accounted for a large share of local privilege escalation vulnerabilities.

Many sandboxes and workloads use unprivileged user namespaces strictly for UID/GID, mount, PID, or network isolation and never need high-risk capabilities like CAP_NET_ADMIN. Likewise, system administrators, service managers, and container runtimes often want to enforce a capability ceiling across descendant user namespaces while still permitting exceptions for authorized workloads.

Prior work by Jonathan Calmels [1, 2] proposed a per-thread userns capability set (cap_userns), while v1 of this series [3] proposed a capability bounding set (cap_bset) in struct user_namespace configured via a global sysctl and clone3().

During v1 review, both Christian Brauner and Andy Lutomirski had reservations about the sysctl and clone3() approach, and Andy pointed out the need to cover the single-deep container case. Christian then proposed combining per-cred cap_userns with the per-namespace cap_bset ceiling [4].

This series implements that combined approach:

1. Per-namespace cap_bset and per-cred cap_userns (Patch 1) Introduce user_namespace->cap_bset and cred->cap_userns, controlled via prctl(PR_CAP_USERNS) and SECBIT_CAP_USERNS_STRICT (named _STRICT rather than SECURE_NO_USERNS_CAP_RAISE as it also disables the default cap_permitted exemption). Clamp namespace creation, set_cred_user_ns(), and parent-owner checks in cap_capable_helper() against these ceilings.

One refinement over the v1 review sketch: set_cred_user_ns() also intersects cred->cap_userns with user_ns->cap_bset on namespace entry. Since userns transitions only move downward in the hierarchy, excluded bits are permanently inert anyway. Clearing them keeps CapUns and PR_CAP_USERNS_IS_SET accurate after setns() and gives all six task capability masks a uniform user_ns->cap_bset subset invariant.

2. Ptrace and dumpability bounding (Patch 2)
Require the tracee's cred_userns_bset() to be a subset of the tracer's in the same-namespace ptrace check (complementing the cross-userns owner check in cap_capable_helper()), and update cred_cap_issubset() so widening the effective userns ceiling resets mm->dumpable and pdeath_signal.

3. Introspection via /proc/<pid>/status (Patch 3)
Expose cred->cap_userns as CapUns in /proc/<pid>/status. Leave AUDIT_CAPSET unchanged, as capset() never modifies cap_userns (matching cap_bset, where prctl() changes are covered by syscall auditing).

4. Selftests (Patch 4)
Add kselftests covering PR_CAP_USERNS, CapUns, nested monotonicity, creator capability retention, SECBIT_CAP_USERNS_STRICT, setns() clamping, parent-owner bounding, ptrace restrictions, and dumpability resets.

Changes in v2:
- Replace the global sysctl, CLONE_NEWUSER_BSET / struct clone_args extension, and NS_USER_GET_INFO ioctl with per-cred cap_userns, prctl(PR_CAP_USERNS), SECBIT_CAP_USERNS_STRICT, and CapUns in /proc/<pid>/status.
- Drop CLONE_NEWNET_LOOPBACK and UNSHARE_NEWNET_LOOPBACK to handle in a separate series.
- Clamp set_cred_user_ns() (including cred->cap_userns) against user_ns->cap_bset and cred_userns_bset(cred).
- In cap_capable_helper(), bound implicit parent-owner capabilities by the owned namespace's cap_bset, and grant them only when that cap_bset is a subset of cred_userns_bset(cred).
- Bound same-namespace ptrace checks in cap_ptrace_access_check() and cap_ptrace_traceme() and credential subset checks in cred_cap_issubset() by userns capability ceilings.
- Rebase onto v7.4-rc1, preserving SECURE_ALL_UNPRIVILEGED handling in set_cred_user_ns().
- Link to v1: https://lore.kernel.org/r/[email protected]

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lwn.net/Articles/978846/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/20261111-behagen-faktisch-entgegen-e2e714373895@brauner/

Hallgrimur H. Gunnarsson (4):
userns: introduce capability bounding set for user namespaces
capability: bound ptrace and cred subset checks by userns ceilings
proc: expose userns capability mask as CapUns in /proc/<pid>/status selftests/capabilities: add userns capability bounding set tests

 Documentation/filesystems/proc.rst            |    2 +
 Documentation/security/credentials.rst        |   12 +-
 fs/proc/array.c                               |    4 +-
 include/linux/cred.h                          |   22 +
 include/linux/user_namespace.h                |   12 +
 include/uapi/linux/prctl.h                    |    7 +
 include/uapi/linux/securebits.h               |   16 +-
 init/init_task.c                              |    1 +
 kernel/cred.c                                 |   13 +-
 kernel/user.c                                 |    1 +
 kernel/user_namespace.c                       |   33 +-
 security/commoncap.c                          |   80 +-
 security/keys/process_keys.c                  |    1 +
 .../testing/selftests/capabilities/.gitignore |    1 +
 tools/testing/selftests/capabilities/Makefile |    2 +-
 .../capabilities/userns_bounding_set_test.c   | 1064 +++++++++++++++++
 16 files changed, 1246 insertions(+), 25 deletions(-)
 create mode 100644 tools/testing/selftests/capabilities/userns_bounding_set_test.c

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

Signature · 1 line
2.56.1.708.g77570a6a1d-goog
#1 lore raw

PATCH v2 1/4 userns: introduce capability bounding set for user namespaces

When a process creates a new user namespace, it receives a full set of capabilities (CAP_FULL_SET) scoped to that namespace. While namespaced in scope, several of these capabilities (such as CAP_NET_ADMIN and CAP_NET_RAW) expose broad kernel attack surface that many sandboxes and containers never need. However, there is currently no configurable way to withhold such capabilities from user namespaces while still granting them to workloads that require them.

Introduce a per-user-namespace capability bounding set (user_ns->cap_bset) and a per-credential userns capability set (cred->cap_userns) queried and modified via prctl(PR_CAP_USERNS). Lowering or clearing capabilities in cap_userns (PR_CAP_USERNS_LOWER and PR_CAP_USERNS_CLEAR_ALL) requires CAP_SETPCAP in the current user namespace or no_new_privs, while raising a capability (PR_CAP_USERNS_RAISE) requires holding it in cap_permitted.

By default, a credential's userns capability ceiling (cred_userns_bset) combines cap_userns with cap_permitted (matching what the task could raise via PR_CAP_USERNS_RAISE), so privileged tasks retain capabilities they already hold even when cap_userns has been lowered. Setting SECBIT_CAP_USERNS_STRICT enforces cap_userns strictly, ignores cap_permitted, and disables PR_CAP_USERNS_RAISE, allowing privileged launchers or outer containers to spawn trimmed descendant user namespaces without dropping their own cap_permitted. Both SECBIT_CAP_USERNS_STRICT and its lock bit persist across user namespace transitions.

When a new user namespace is created, set its cap_bset to the intersection of its parent's cap_bset and the creator's ceiling (parent_ns->cap_bset & cred_userns_bset(cred)), so capability bounding sets decrease monotonically down the namespace hierarchy.

On user namespace entry (during creation or via setns()), clamp the task's permitted, effective, and bounding sets to user_ns->cap_bset & cred_userns_bset(cred) instead of granting CAP_FULL_SET, and intersect cap_userns with user_ns->cap_bset. Because user namespace transitions only move downward in the hierarchy, bits absent from user_ns->cap_bset can never be acquired in descendant namespaces. Clearing them keeps cap_userns and PR_CAP_USERNS_IS_SET accurate after setns() and keeps all six task capability sets as subsets of user_ns->cap_bset.

In cap_capable_helper(), bound implicit parent-owner capabilities by the owned namespace's cap_bset, and grant them only when that cap_bset is a subset of cred_userns_bset(cred), preventing tasks from exercising privileges over less-restricted descendant namespaces.

Initialize both init_user_ns.cap_bset and init_cred.cap_userns to CAP_FULL_SET, preserving existing behavior unless cap_userns is explicitly restricted.

---
 Documentation/security/credentials.rst | 12 ++++-
 include/linux/cred.h                   | 22 +++++++++
 include/linux/user_namespace.h         | 12 +++++
 include/uapi/linux/prctl.h             |  7 +++
 include/uapi/linux/securebits.h        | 16 +++++-
 init/init_task.c                       |  1 +
 kernel/user.c                          |  1 +
 kernel/user_namespace.c                | 33 +++++++++----
 security/commoncap.c                   | 68 ++++++++++++++++++++++++--
 security/keys/process_keys.c           |  1 +
 10 files changed, 158 insertions(+), 15 deletions(-)
Documentation/security/credentials.rst +10 -2
index a39a2a2f67aa..2645cc81515a 100644
@@ -149,6 +149,7 @@ The Linux kernel supports the following types of credentials:
 	- Set of inheritable capabilities
 	- Set of effective capabilities
 	- Capability bounding set
+	- Set of userns capabilities
 
      These are only carried by tasks.  They indicate superior capabilities
      granted piecemeal to a task that an ordinary task wouldn't otherwise have.
@@ -170,12 +171,19 @@ The Linux kernel supports the following types of credentials:
      ``execve()``, especially when a binary is executed that will execute as
      UID 0.
 
+     The userns capabilities (manipulated via ``prctl(PR_CAP_USERNS)``) define
+     a ceiling on the capabilities a task may acquire when creating or entering
+     a user namespace, and prevent exercising implicit owner capabilities via
+     any owned user namespace whose bounding set exceeds this ceiling.
+     Capabilities held in the permitted set remain included in this ceiling by
+     default unless ``SECBIT_CAP_USERNS_STRICT`` is set.
+
  3. Secure management flags (securebits).
 
      These are only carried by tasks.  These govern the way the above
      credentials are manipulated and inherited over certain operations such as
-     execve().  They aren't used directly as objective or subjective
-     credentials.
+     execve() and user namespace transitions. They aren't used directly as
+     objective or subjective credentials.
 
  4. Keys and keyrings.
 
include/linux/cred.h +22 -0
index 49c26af37349..20857d11e032 100644
@@ -14,6 +14,7 @@
 #include <linux/atomic.h>
 #include <linux/refcount.h>
 #include <linux/uidgid.h>
+#include <linux/securebits.h>
 #include <linux/sched.h>
 #include <linux/sched/user.h>
 
@@ -128,6 +129,7 @@ struct cred {
 	kernel_cap_t	cap_effective;	/* caps we can actually use */
 	kernel_cap_t	cap_bset;	/* capability bounding set */
 	kernel_cap_t	cap_ambient;	/* Ambient capability set */
+	kernel_cap_t	cap_userns;	/* userns capability set */
 #ifdef CONFIG_KEYS
 	unsigned char	jit_keyring;	/* default keyring to attach requested
 					 * keys to */
@@ -178,6 +180,26 @@ static inline bool cap_ambient_invariant_ok(const struct cred *cred)
 					  cred->cap_inheritable));
 }
 
+/**
+ * cred_userns_bset - Ceiling on capabilities a userns may grant @cred
+ * @cred: Credentials to evaluate
+ *
+ * By default, capabilities already held in cap_permitted are also allowed
+ * (matching what @cred could raise via PR_CAP_USERNS_RAISE). When
+ * SECBIT_CAP_USERNS_STRICT is set, cap_userns is enforced strictly and
+ * cap_permitted is ignored. Because both cap_userns and cap_permitted are
+ * bounded by cred->user_ns->cap_bset, the returned mask never exceeds the
+ * enclosing user namespace's bounding set.
+ *
+ * Return: Capability mask @cred may acquire in or exercise over a userns.
+ */
+static inline kernel_cap_t cred_userns_bset(const struct cred *cred)
+{
+	if (cred->securebits & SECBIT_CAP_USERNS_STRICT)
+		return cred->cap_userns;
+	return cap_combine(cred->cap_userns, cred->cap_permitted);
+}
+
 static inline const struct cred *override_creds(const struct cred *override_cred)
 {
 	const struct cred *old = current->cred;
include/linux/user_namespace.h +12 -0
index 91232053775d..5f31390aa583 100644
@@ -3,6 +3,7 @@
 #define _LINUX_USER_NAMESPACE_H
 
 #include <linux/kref.h>
+#include <linux/capability.h>
 #include <linux/nsproxy.h>
 #include <linux/ns_common.h>
 #include <linux/rculist_nulls.h>
@@ -84,6 +85,7 @@ struct user_namespace {
 	int			level;
 	kuid_t			owner;
 	kgid_t			group;
+	kernel_cap_t		cap_bset;
 	struct ns_common	ns;
 	unsigned long		flags;
 	/* parent_could_setfcap: true if the creator if this ns had CAP_SETFCAP
@@ -183,6 +185,11 @@ static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
 	return ns;
 }
 
+static inline bool userns_has_cap(const struct user_namespace *ns, int cap)
+{
+	return cap_raised(ns->cap_bset, cap);
+}
+
 extern int create_user_ns(struct cred *new);
 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
 extern void __put_user_ns(struct user_namespace *ns);
@@ -221,6 +228,11 @@ static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
 	return &init_user_ns;
 }
 
+static inline bool userns_has_cap(const struct user_namespace *ns, int cap)
+{
+	return true;
+}
+
 static inline int create_user_ns(struct cred *new)
 {
 	return -EINVAL;
include/uapi/linux/prctl.h +7 -0
index b6ec6f693719..137a5d0a6704 100644
@@ -416,4 +416,11 @@ struct prctl_mm_map {
 # define PR_CFI_DISABLE		_BITUL(1)
 # define PR_CFI_LOCK		_BITUL(2)
 
+/* Control the userns capability mask */
+#define PR_CAP_USERNS			82
+# define PR_CAP_USERNS_IS_SET		1
+# define PR_CAP_USERNS_RAISE		2
+# define PR_CAP_USERNS_LOWER		3
+# define PR_CAP_USERNS_CLEAR_ALL	4
+
 #endif /* _LINUX_PRCTL_H */
include/uapi/linux/securebits.h +15 -1
index 3fba30dbd68b..cc8ed81683e2 100644
@@ -69,12 +69,26 @@
 #define SECBIT_EXEC_DENY_INTERACTIVE_LOCKED \
 			(issecure_mask(SECURE_EXEC_DENY_INTERACTIVE_LOCKED))
 
+/*
+ * When set, creating or entering a user namespace only grants capabilities
+ * present in cap_userns (ignoring cap_permitted), and PR_CAP_USERNS_RAISE
+ * is disabled.
+ */
+#define SECURE_CAP_USERNS_STRICT		12
+#define SECURE_CAP_USERNS_STRICT_LOCKED		13 /* make bit-12 immutable */
+
+#define SECBIT_CAP_USERNS_STRICT \
+			(issecure_mask(SECURE_CAP_USERNS_STRICT))
+#define SECBIT_CAP_USERNS_STRICT_LOCKED \
+			(issecure_mask(SECURE_CAP_USERNS_STRICT_LOCKED))
+
 #define SECURE_ALL_BITS		(issecure_mask(SECURE_NOROOT) | \
 				 issecure_mask(SECURE_NO_SETUID_FIXUP) | \
 				 issecure_mask(SECURE_KEEP_CAPS) | \
 				 issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE) | \
 				 issecure_mask(SECURE_EXEC_RESTRICT_FILE) | \
-				 issecure_mask(SECURE_EXEC_DENY_INTERACTIVE))
+				 issecure_mask(SECURE_EXEC_DENY_INTERACTIVE) | \
+				 issecure_mask(SECURE_CAP_USERNS_STRICT))
 #define SECURE_ALL_LOCKS	(SECURE_ALL_BITS << 1)
 
 #define SECURE_ALL_UNPRIVILEGED (issecure_mask(SECURE_EXEC_RESTRICT_FILE) | \
init/init_task.c +1 -0
index ce7c2b07d855..a5c4bf902dcc 100644
@@ -92,6 +92,7 @@ static struct cred init_cred = {
 	.cap_permitted		= CAP_FULL_SET,
 	.cap_effective		= CAP_FULL_SET,
 	.cap_bset		= CAP_FULL_SET,
+	.cap_userns		= CAP_FULL_SET,
 	.user			= INIT_USER,
 	.user_ns		= &init_user_ns,
 	.group_info		= &init_groups,
kernel/user.c +1 -0
index 21bafdc11379..97d95e733a8c 100644
@@ -68,6 +68,7 @@ struct user_namespace init_user_ns = {
 	},
 	.owner = GLOBAL_ROOT_UID,
 	.group = GLOBAL_ROOT_GID,
+	.cap_bset = CAP_FULL_SET,
 	.flags = USERNS_INIT_FLAGS,
 #ifdef CONFIG_KEYS
 	.keyring_name_list = LIST_HEAD_INIT(init_user_ns.keyring_name_list),
kernel/user_namespace.c +24 -9
index cd748e1cbace..96cdc29f3611 100644
@@ -4,6 +4,7 @@
 #include <linux/export.h>
 #include <linux/nsproxy.h>
 #include <linux/slab.h>
+#include <linux/capability.h>
 #include <linux/sched/signal.h>
 #include <linux/user_namespace.h>
 #include <linux/proc_ns.h>
@@ -44,18 +45,30 @@ static void dec_user_namespaces(struct ucounts *ucounts)
 
 static void set_cred_user_ns(struct cred *cred, struct user_namespace *user_ns)
 {
-	/* Start with the same capabilities as init but useless for doing
-	 * anything as the capabilities are bound to the new user namespace.
-	 * The exec securebits grant nothing, they are restrictions the task
-	 * placed on itself. Keep them and their locks.
+	unsigned int keep_secbits;
+	kernel_cap_t caps;
+
+	/*
+	 * Preserve unprivileged and userns-strict securebits and their locks
+	 * across user namespace transitions.
+	 */
+	keep_secbits = SECURE_ALL_UNPRIVILEGED | SECBIT_CAP_USERNS_STRICT;
+	cred->securebits &= keep_secbits | (keep_secbits << 1);
+	cred->securebits |= SECUREBITS_DEFAULT;
+
+	/*
+	 * Invariant: for every credential in a user namespace, all six task
+	 * capability masks (effective, permitted, inheritable, ambient, bset,
+	 * and userns) are subsets of user_ns->cap_bset.
 	 */
-	cred->securebits = SECUREBITS_DEFAULT |
-		(cred->securebits & (SECURE_ALL_UNPRIVILEGED | SECURE_ALL_UNPRIVILEGED << 1));
+	caps = cap_intersect(user_ns->cap_bset, cred_userns_bset(cred));
+
 	cred->cap_inheritable = CAP_EMPTY_SET;
-	cred->cap_permitted = CAP_FULL_SET;
-	cred->cap_effective = CAP_FULL_SET;
+	cred->cap_permitted = caps;
+	cred->cap_effective = caps;
 	cred->cap_ambient = CAP_EMPTY_SET;
-	cred->cap_bset = CAP_FULL_SET;
+	cred->cap_bset = caps;
+	cred->cap_userns = cap_intersect(user_ns->cap_bset, cred->cap_userns);
 #ifdef CONFIG_KEYS
 	key_put(cred->request_key_auth);
 	cred->request_key_auth = NULL;
@@ -148,6 +161,8 @@ int create_user_ns(struct cred *new)
 	set_userns_rlimit_max(ns, UCOUNT_RLIMIT_SIGPENDING, rlimit(RLIMIT_SIGPENDING));
 	set_userns_rlimit_max(ns, UCOUNT_RLIMIT_MEMLOCK, rlimit(RLIMIT_MEMLOCK));
 	ns->ucounts = ucounts;
+	ns->cap_bset = cap_intersect(parent_ns->cap_bset,
+				     cred_userns_bset(new));
 
 	/* Inherit USERNS_SETGROUPS_ALLOWED from our parent */
 	mutex_lock(&userns_state_mutex);
security/commoncap.c +65 -3

88 lines not on this page · raw message

security/keys/process_keys.c +1 -0
index 3af71c6322af..183fe18a8f62 100644
@@ -1026,6 +1026,7 @@ void key_change_session_keyring(struct callback_head *twork)
 	new->cap_effective	= old->cap_effective;
 	new->cap_ambient	= old->cap_ambient;
 	new->cap_bset		= old->cap_bset;
+	new->cap_userns		= old->cap_userns;
 
 	new->jit_keyring	= old->jit_keyring;
 	new->thread_keyring	= key_get(old->thread_keyring);
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
#2 lore raw

Re: [PATCH v2 1/4] userns: introduce capability bounding set for user namespaces

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] userns: cap_ptrace_access_check() denies owner access without CAP_SYS_PTRACE --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] userns: cap_ptrace_access_check() denies owner access without CAP_SYS_PTRACE
--

commit e4e71a2ec01bd6f7552fbbff2f1b525d5dbf74f6
Author: Hallgrimur H. Gunnarsson <[email protected]>

userns: introduce capability bounding set for user namespaces

This commit introduces a per-user-namespace capability bounding set (user_ns->cap_bset) and a per-credential userns capability set (cred->cap_userns) controlled via prctl(PR_CAP_USERNS) and SECBIT_CAP_USERNS_STRICT.

Quoted 13 lines
security/commoncap.c +2 -2
index d47ab30223435..ddac8e9176808 100644
@@ -88,11 +88,15 @@ static inline int cap_capable_helper(const struct cred *cred,
 		if (ns->level <= cred_ns->level)
 			return -EPERM;
 
-		/* 
+		/*
 		 * The owner of the user namespace in the parent of the
-		 * user namespace has all caps.
+		 * user namespace has all caps within the owned namespace's

security/commoncap.c static inline int cap_capable_helper(const struct cred *cred, · line 102

Quoted 10 lines
security/commoncap.c +5 -1
+		 * bounding set, as long as it does not exceed the caller's
+		 * userns capability ceiling.
 		 */
-		if ((ns->parent == cred_ns) && uid_eq(ns->owner, cred->euid))
+		if (ns->parent == cred_ns && uid_eq(ns->owner, cred->euid) &&
+		    cap_issubset(ns->cap_bset, cred_userns_bset(cred)) &&
+		    userns_has_cap(ns, cap))
 			return 0;
 
 		/*

[Severity: Medium]
Does bounding implicit owner capabilities by userns_has_cap(ns, cap) break cap_ptrace_access_check() and cap_ptrace_traceme() for a parent namespace owner when CAP_SYS_PTRACE is excluded from the child namespace's cap_bset?

When an unprivileged task lowers CAP_SYS_PTRACE (or uses PR_CAP_USERNS_CLEAR_ALL) before creating a child user namespace, cap_ptrace_access_check() skips the capability subset check because cred->user_ns != child_cred->user_ns and falls back to ns_capable(child_cred->user_ns, CAP_SYS_PTRACE):

security/commoncap.c:cap_ptrace_access_check() {
    ...
	if (cred->user_ns == child_cred->user_ns &&
	    cap_issubset(child_cred->cap_permitted, *caller_caps))
		goto out;
	if (ns_capable(child_cred->user_ns, CAP_SYS_PTRACE))
		goto out;
	ret = -EPERM;
    ...
}

Because CAP_SYS_PTRACE is not in child_cred->user_ns->cap_bset, ns_capable() now returns false even when the child task has an empty cap_permitted set or only capabilities covered by the owner's userns ceiling. The parent owner is then denied ptrace_may_access() and PTRACE_TRACEME on its own same-UID child tasks in that namespace, breaking PTRACE_ATTACH, opening /proc/<child>/ns/*, setns(pidfd, ...), and pidfd_getfd().

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH v2 1/4] userns: introduce capability bounding set for user namespaces

Quoted 4 lines · On Thu, Nov 19, 2026 at 11:11:50AM +0000, [email protected] wrote:

[Severity: Medium]
Does bounding implicit owner capabilities by userns_has_cap(ns, cap) break cap_ptrace_access_check() and cap_ptrace_traceme() for a parent namespace owner when CAP_SYS_PTRACE is excluded from the child namespace's cap_bset?

This is working as intended. Implicit parent-owner capabilities in cap_capable_helper() are uniformly bounded by the owned namespace's cap_bset.

Concretely, this only prevents an unprivileged parent task from getting implicit CAP_SYS_PTRACE via ownership of a child userns where CAP_SYS_PTRACE was explicitly stripped. Holding explicit CAP_SYS_PTRACE in an ancestor userns (or owning an ancestor userns that still includes CAP_SYS_PTRACE) still allows tracing.

This is also unlikely to come up in practice, since typical denylist configurations would only strip high-risk capabilities like CAP_NET_ADMIN and CAP_NET_RAW.

If we wanted to make an exception for ptrace() to still allow same-UID owner tracing when CAP_SYS_PTRACE is stripped, cap_ptrace_access_check() and cap_ptrace_traceme() already allow same-userns tracing without CAP_SYS_PTRACE when the target's capabilities (and userns ceiling) are a subset of the tracer's. Extending that check across owned namespaces (similar to cred_cap_issubset()) would be straightforward, though I'd prefer to keep the stricter, uniform behavior in v2 unless there are objections.

maintainer
#4 lore raw

Re: [PATCH v2 1/4] userns: introduce capability bounding set for user namespaces

In reply to Hallgrimur H. Gunnarsson
Quoted 1 line · Hallgrimur H. Gunnarsson

static void set_cred_user_ns(struct cred *cred, struct user_namespace *user_ns)

I read the diff through but this led me to dead end. Cannot find this function from anywhere. I look the changes again once this is sorted out becaus this is interesting.

I wanted to look at the call site to understand how cap_bset gets set, which is not now possible but I do get the gist and agree with it.

I'd figure getting this relates to my rootns patches (perhas). One key mechanism for me resolving the unprivileged in my use case is MOVE_MOUNT_T_MNTNS [1], which is orthogonal but just pointing out the problem space.

I read through https://lwn.net/Articles/978846/ to understand the topic overall. Just mentionining as a possible addition to the cover letter (not a priority/necessity).

Hope these help and can be kept in the loop :-)

[1] https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git/commit/?h=rootns&id=cb058646b3dd76b13f5044846c119fe1d28db4bf

Br, Jarkko

#5 lore raw

Re: [PATCH v2 1/4] userns: introduce capability bounding set for user namespaces

Quoted 9 lines · Jarkko Sakkinen
Quoted 1 line · Hallgrimur H. Gunnarsson

static void set_cred_user_ns(struct cred *cred, struct user_namespace *user_ns)

I read the diff through but this led me to dead end. Cannot find this function from anywhere. I look the changes again once this is sorted out becaus this is interesting.

I wanted to look at the call site to understand how cap_bset gets set, which is not now possible but I do get the gist and agree with it.

Thanks for taking a look. The series is based on v7.4-rc1 and set_cred_user_ns() lives in kernel/user_namespace.c, where it is called from create_user_ns() and userns_install(). ns->cap_bset itself is initialized in create_user_ns() right before calling set_cred_user_ns().

Quoted 4 lines

I'd figure getting this relates to my rootns patches (perhas). One key mechanism for me resolving the unprivileged in my use case is MOVE_MOUNT_T_MNTNS [1], which is orthogonal but just pointing out the problem space.

From a quick look, they appear complementary. Being able to do more setup operations from the outside generally aligns with bounding capabilities inside the user namespace.

Quoted 3 lines

I read through https://lwn.net/Articles/978846/ to understand the topic overall. Just mentionining as a possible addition to the cover letter (not a priority/necessity).

That LWN article is actually linked in the cover letter as [2].

Quoted 1 line

Hope these help and can be kept in the loop :-)

Will do, I'll keep you CC'd on future revisions.

maintainer
#6 lore raw

Re: [PATCH v2 1/4] userns: introduce capability bounding set for user namespaces

Quoted 29 lines · Hallgrimur H. Gunnarsson
Quoted 9 lines · Jarkko Sakkinen
Quoted 1 line · Hallgrimur H. Gunnarsson

static void set_cred_user_ns(struct cred *cred, struct user_namespace *user_ns)

I read the diff through but this led me to dead end. Cannot find this function from anywhere. I look the changes again once this is sorted out becaus this is interesting.

I wanted to look at the call site to understand how cap_bset gets set, which is not now possible but I do get the gist and agree with it.

Thanks for taking a look. The series is based on v7.4-rc1 and set_cred_user_ns() lives in kernel/user_namespace.c, where it is called from create_user_ns() and userns_install(). ns->cap_bset itself is initialized in create_user_ns() right before calling set_cred_user_ns().

Quoted 4 lines

I'd figure getting this relates to my rootns patches (perhas). One key mechanism for me resolving the unprivileged in my use case is MOVE_MOUNT_T_MNTNS [1], which is orthogonal but just pointing out the problem space.

From a quick look, they appear complementary. Being able to do more setup operations from the outside generally aligns with bounding capabilities inside the user namespace.

Quoted 3 lines

I read through https://lwn.net/Articles/978846/ to understand the topic overall. Just mentionining as a possible addition to the cover letter (not a priority/necessity).

Quoted 5 lines

That LWN article is actually linked in the cover letter as [2].

Quoted 1 line

Hope these help and can be kept in the loop :-)

Will do, I'll keep you CC'd on future revisions.

Thank you.

Br, Jarkko

#7 lore raw

Re: [PATCH v2 1/4] userns: introduce capability bounding set for user namespaces

In reply to Hallgrimur H. Gunnarsson
Quoted 8 lines · Hallgrimur H. Gunnarsson

When a process creates a new user namespace, it receives a full set of capabilities (CAP_FULL_SET) scoped to that namespace. While namespaced in scope, several of these capabilities (such as CAP_NET_ADMIN and CAP_NET_RAW) expose broad kernel attack surface that many sandboxes and containers never need. However, there is currently no configurable way to withhold such capabilities from user namespaces while still granting them to workloads that require them.

One thought (from the rootns thread): the other decent sized attack surface here is CAP_MOUNT_ADMIN. Which doesn't exist as a capability bit.

A sort of horrible solution (but maybe not so awful) would be to declare that the bits in cap_userns aren't actually capability bits, and that you need the bit in cap_userns *and* the bit in cap_effective to do sensitive things, and that mounting needs cap_userns to have NSCAP_MOUNT_ADMIN *and* cap_effective to have CAP_SYS_ADMIN.

I want to sleep on this. It might actually solve several problems, e.g. controlling creation of ipv4 and ipv6 loopback or tunnel devices or whatever.

--Andy

#8 lore raw

Re: [PATCH v2 1/4] userns: introduce capability bounding set for user namespaces

Quoted 23 lines · Andy Lutomirski

On Thu, Nov 19, 2026 at 2:43 AM Hallgrimur H. Gunnarsson

Quoted 8 lines · <[email protected]> wrote:

When a process creates a new user namespace, it receives a full set of capabilities (CAP_FULL_SET) scoped to that namespace. While namespaced in scope, several of these capabilities (such as CAP_NET_ADMIN and CAP_NET_RAW) expose broad kernel attack surface that many sandboxes and containers never need. However, there is currently no configurable way to withhold such capabilities from user namespaces while still granting them to workloads that require them.

One thought (from the rootns thread): the other decent sized attack surface here is CAP_MOUNT_ADMIN. Which doesn't exist as a capability bit.

A sort of horrible solution (but maybe not so awful) would be to declare that the bits in cap_userns aren't actually capability bits, and that you need the bit in cap_userns *and* the bit in cap_effective to do sensitive things, and that mounting needs cap_userns to have NSCAP_MOUNT_ADMIN *and* cap_effective to have CAP_SYS_ADMIN.

Quoted 3 lines

I want to sleep on this. It might actually solve several problems, e.g. controlling creation of ipv4 and ipv6 loopback or tunnel devices or whatever.

I slept on it. Here’s a counterproposal. I’m not saying I think this is better than this patch set, but I think it’s worth weighting the options.

Define a whole new set of privilege bits. As a poorly-painted-bikeshed option, I’ll call them eprivs (for exposure privileges - it’s a crappy name but at least it’s pronounceable).

An epriv is not permission to do something *to* an object; it’s permission to do something that exposes a meaningful attack surface within the kernel. So there’s no ns_has_epriv because there is no object. These are kind of the opposite of object capabilities. Additionally, an epriv never grants the ability to do something that one couldn’t do in an epriv-less world.

For now, all tasks have all eprivs, even not-yet-defined ones, unless user code or config explicitly changes this. (Maybe some day secure boot might remove certain eprivs.)

There should never be a check like ns_capable || has_epriv. It’s also &&, or perhaps caps are not checked at all.

Example eprivs include:

EPRIV_FSOPEN_VIRT: may fsconfig, fsopen, etc a virtual fs like fuse or tmpfs or overlayfs.

EPRIV_CLONE_TREE: may clone a mount tree

EPRIV_MOVE_MOUNT: may move mounts around (but only if you also have CAP_SYS_ADMIN on the correct namespace, of course)

EPRIV_FIREWALL_TC: may configure any firewalling configuration or tc configuration (this includes iptables, nftables, and ebtables)

EPRIV_NET_RAW: may use raw/packet sockets (like CAP_NET_RAW)

EPRIV_TUNTAP: may create and attach to tun/tap interfaces

EPRIV_IP_LOOPBACK: may set up IPv4 and IPv6 loopback using whatever new facility we add

EPRIV_NETLINK: may use netlink at all

EPRIV_NET_ADMIN: may use traditional CAP_NET_ADMIN abilities (all CAP_NET_ADMIN checks will also check EPRIV_NET_ADMIN)

EPRIV_OPEN_FILE_HANDLE: May use open_by_handle_at, etc.

EPRIV_UNSHARE_USERNS: may unshare userns

EPRIV_UNSHARE_NONUSERNS: may unshare any other namespace

EPRIV_MOUNT_CGROUPv1, EPRIV_MOUNT_CGROUPv2: may create a new mount of these subsystems

EPRIV_PTRACE: there are lots of different variations that might make sense.

EPRIV_MOUNT_PROC_PIDONLY: may mount proc-pidonly

EPRIV_MOUNT_PROC_NOTPIDONLY: may mount proc not-pidonly

EPRIV_MOUNT_SYSFS: may mount sysfs

Example eprivs that are questionable:

EPRIV_DMESG: the kernel log is a specific object, and I think it's better to control access using something kernel-log-specific.

There is no operation that increases eprivs -- even without no_new_privs set, a task will never gain an epriv, nor will a child ever have an epriv that its creator did not have at the time the child was created.

The evolution rules could be as simple as, on fork/clone, the child inheriting exactly the parent's eprivs.

Or we could bind eprivs to a userns instead of a task, but that could be more limiting and awkward than we want.

What do you all think?

FWIW, I had an LLM make an inventory (surely not exhaustive) of recent-ish CVEs and how they relate to this list. (The below is the only part of this email that is LLM-generated, although I added EPRIV_SYSFS because I didn't realize that nonroot userns could mount it until I asked an LLM, sigh.) To me, the list and its breakdown suggests that there is quite a lot of room for meaningful attack surface reductions while still leaving large parts of userns available, and that my epriv proposal captures much of this but the cap_userns proposal may be too coarse-grained.

(I also asked about eBPF, and my LLM came up with a lot of CVEs, but there's an existing BPF token mechanism and I therefore did not propose EPRIV_LOAD_EBPF.)

--- begin LLM output ---

**EPRIV_FSOPEN_VIRT:** CVE-2022-0185*, CVE-2023-0386*, CVE-2023-2640*, CVE-2023-32629*, CVE-2025-38499*

**EPRIV_CLONE_TREE:** CVE-2025-38499* (only if the check also covers the relevant internal mount-cloning path; explicit open_tree() restrictions alone are insufficient)

**EPRIV_MOVE_MOUNT:** CVE-2025-37988

**EPRIV_FIREWALL_TC:** CVE-2022-25636, CVE-2022-1015, CVE-2022-1016, CVE-2022-32250, CVE-2022-34918, CVE-2022-48911*, CVE-2022-2588, CVE-2023-32233, CVE-2023-35001, CVE-2023-4004, CVE-2023-4015, CVE-2023-4244, CVE-2023-5197, CVE-2023-6817, CVE-2023-3609, CVE-2023-4623, CVE-2023-4921, CVE-2024-1086, CVE-2024-0607, CVE-2024-27397, CVE-2024-26925, CVE-2025-38001, CVE-2026-23111

**EPRIV_NET_RAW:** None identified.

**EPRIV_TUNTAP:** None identified as requiring TUN/TAP. Some packet-triggered exploits may optionally use it, but that does not establish it as a necessary blocker.

**EPRIV_IP_LOOPBACK:** None identified.

**EPRIV_NETLINK:** Also those blocked by EPRIV_FIREWALL_TC, insofar as the documented attack paths use netlink. No additional CVEs identified.

**EPRIV_NET_ADMIN:** Also those blocked by EPRIV_FIREWALL_TC, insofar as the vulnerable operations require CAP_NET_ADMIN. No additional CVEs identified.

**EPRIV_OPEN_FILE_HANDLE:** CVE-2025-38306*

**EPRIV_UNSHARE_USERNS:** Also those blocked by EPRIV_FSOPEN_VIRT, EPRIV_MOVE_MOUNT, EPRIV_FIREWALL_TC, EPRIV_OPEN_FILE_HANDLE, EPRIV_MOUNT_CGROUPv1, and EPRIV_MOUNT_SYSFS, plus CVE-2025-38058*. More generally, blocks the documented unprivileged user-namespace setup for the entire inventory when no usable user namespace already exists.

**EPRIV_UNSHARE_NONUSERNS:** Also the namespace-dependent attack paths blocked by EPRIV_FIREWALL_TC, EPRIV_MOVE_MOUNT, EPRIV_MOUNT_CGROUPv1, EPRIV_MOUNT_SYSFS, and many of those blocked by EPRIV_FSOPEN_VIRT. Coverage depends on whether the necessary non-user namespaces already exist.

**EPRIV_MOUNT_CGROUPv1:** CVE-2022-0492*

**EPRIV_MOUNT_CGROUPv2:** None identified.

**EPRIV_PTRACE:** None identified.

**EPRIV_LOAD_EBPF:** None identified.

**EPRIV_MOUNT_PROC_PIDONLY:** None identified.

**EPRIV_MOUNT_PROC_NOTPIDONLY:** None identified.

**EPRIV_MOUNT_SYSFS:** CVE-2025-22089*

CVEs not cleanly blocked by an operation-specific bit Excluding the two EPRIV_UNSHARE_* gates:

- CVE-2025-38058: No explicit unmount privilege. The vulnerable race involves umount(2) and path lookup.

- CVE-2022-0492: The cgroup-v1 mount bit covers the documented new-mount attack path, but not necessarily configuration of release_agent on an existing writable hierarchy.

- CVE-2025-38499: The correct gate depends on which filesystem-context or internal cloning operation reaches clone_private_mnt(). I would not count EPRIV_CLONE_TREE as a definitive blocker without checking the exact call paths.

#9 lore raw

Re: [PATCH v2 1/4] userns: introduce capability bounding set for user namespaces

Quoted 24 lines · Andy Lutomirski
Quoted 21 lines · Andy Lutomirski

On Thu, Nov 19, 2026 at 2:43 AM Hallgrimur H. Gunnarsson

Quoted 7 lines · <[email protected]> wrote:

When a process creates a new user namespace, it receives a full set of capabilities (CAP_FULL_SET) scoped to that namespace. While namespaced in scope, several of these capabilities (such as CAP_NET_ADMIN and CAP_NET_RAW) expose broad kernel attack surface that many sandboxes and containers never need. However, there is currently no configurable way to withhold such capabilities from user namespaces while still granting them to workloads that require them.

One thought (from the rootns thread): the other decent sized attack surface here is CAP_MOUNT_ADMIN. Which doesn't exist as a capability bit.

A sort of horrible solution (but maybe not so awful) would be to declare that the bits in cap_userns aren't actually capability bits, and that you need the bit in cap_userns *and* the bit in cap_effective to do sensitive things, and that mounting needs cap_userns to have NSCAP_MOUNT_ADMIN *and* cap_effective to have CAP_SYS_ADMIN.

Quoted 3 lines

I want to sleep on this. It might actually solve several problems, e.g. controlling creation of ipv4 and ipv6 loopback or tunnel devices or whatever.

Quoted 7 lines

I slept on it. Here’s a counterproposal. I’m not saying I think this is better than this patch set, but I think it’s worth weighting the options.

Define a whole new set of privilege bits. As a poorly-painted-bikeshed option, I’ll call them eprivs (for exposure privileges - it’s a crappy name but at least it’s pronounceable).

I played with a mechanism I called "chits" (all the good terms for security bits have been consumed for a very long time) that looks a lot like what you're proposing. I did it to address the CAP_SYS_ADMIN problem, where any use of the capability opens up a whole barrel of worms. I cannot, unfortunately, find my patches. :( The basic approach is:

A process has an optional set of chits. A process without a chit set is unaffected by the mechanism. A process with a chit set is allowed only those operations for which it has a chit. The existing but empty chit set allows no operations. A process may drop a chit, but not the set, which, again, can be empty.

Because I was after CAP_SYS_ADMIN, I envisioned a call
cap_able_chit(capability, chit-list)
but there's no reason there couldn't be a
chit_able(chit-list)
as well.

I wrote this as an LSM, but the system-wide aspect of it made that a questionable choice.

If you have any interest, I could dig more deeply to try to find the patches. Otherwise, I'm happy to look at what you come up with.

Quoted 170 lines

An epriv is not permission to do something *to* an object; it’s permission to do something that exposes a meaningful attack surface within the kernel. So there’s no ns_has_epriv because there is no object. These are kind of the opposite of object capabilities. Additionally, an epriv never grants the ability to do something that one couldn’t do in an epriv-less world.

For now, all tasks have all eprivs, even not-yet-defined ones, unless user code or config explicitly changes this. (Maybe some day secure boot might remove certain eprivs.)

There should never be a check like ns_capable || has_epriv. It’s also &&, or perhaps caps are not checked at all.

Example eprivs include:

EPRIV_FSOPEN_VIRT: may fsconfig, fsopen, etc a virtual fs like fuse or tmpfs or overlayfs.

EPRIV_CLONE_TREE: may clone a mount tree

EPRIV_MOVE_MOUNT: may move mounts around (but only if you also have CAP_SYS_ADMIN on the correct namespace, of course)

EPRIV_FIREWALL_TC: may configure any firewalling configuration or tc configuration (this includes iptables, nftables, and ebtables)

EPRIV_NET_RAW: may use raw/packet sockets (like CAP_NET_RAW)

EPRIV_TUNTAP: may create and attach to tun/tap interfaces

EPRIV_IP_LOOPBACK: may set up IPv4 and IPv6 loopback using whatever new facility we add

EPRIV_NETLINK: may use netlink at all

EPRIV_NET_ADMIN: may use traditional CAP_NET_ADMIN abilities (all CAP_NET_ADMIN checks will also check EPRIV_NET_ADMIN)

EPRIV_OPEN_FILE_HANDLE: May use open_by_handle_at, etc.

EPRIV_UNSHARE_USERNS: may unshare userns

EPRIV_UNSHARE_NONUSERNS: may unshare any other namespace

EPRIV_MOUNT_CGROUPv1, EPRIV_MOUNT_CGROUPv2: may create a new mount of these subsystems

EPRIV_PTRACE: there are lots of different variations that might make sense.

EPRIV_MOUNT_PROC_PIDONLY: may mount proc-pidonly

EPRIV_MOUNT_PROC_NOTPIDONLY: may mount proc not-pidonly

EPRIV_MOUNT_SYSFS: may mount sysfs

Example eprivs that are questionable:

EPRIV_DMESG: the kernel log is a specific object, and I think it's better to control access using something kernel-log-specific.

There is no operation that increases eprivs -- even without no_new_privs set, a task will never gain an epriv, nor will a child ever have an epriv that its creator did not have at the time the child was created.

The evolution rules could be as simple as, on fork/clone, the child inheriting exactly the parent's eprivs.

Or we could bind eprivs to a userns instead of a task, but that could be more limiting and awkward than we want.

What do you all think?

FWIW, I had an LLM make an inventory (surely not exhaustive) of recent-ish CVEs and how they relate to this list. (The below is the only part of this email that is LLM-generated, although I added EPRIV_SYSFS because I didn't realize that nonroot userns could mount it until I asked an LLM, sigh.) To me, the list and its breakdown suggests that there is quite a lot of room for meaningful attack surface reductions while still leaving large parts of userns available, and that my epriv proposal captures much of this but the cap_userns proposal may be too coarse-grained.

(I also asked about eBPF, and my LLM came up with a lot of CVEs, but there's an existing BPF token mechanism and I therefore did not propose EPRIV_LOAD_EBPF.)

--- begin LLM output ---

**EPRIV_FSOPEN_VIRT:** CVE-2022-0185*, CVE-2023-0386*, CVE-2023-2640*, CVE-2023-32629*, CVE-2025-38499*

**EPRIV_CLONE_TREE:** CVE-2025-38499* (only if the check also covers the relevant internal mount-cloning path; explicit open_tree() restrictions alone are insufficient)

**EPRIV_MOVE_MOUNT:** CVE-2025-37988

**EPRIV_FIREWALL_TC:** CVE-2022-25636, CVE-2022-1015, CVE-2022-1016, CVE-2022-32250, CVE-2022-34918, CVE-2022-48911*, CVE-2022-2588, CVE-2023-32233, CVE-2023-35001, CVE-2023-4004, CVE-2023-4015, CVE-2023-4244, CVE-2023-5197, CVE-2023-6817, CVE-2023-3609, CVE-2023-4623, CVE-2023-4921, CVE-2024-1086, CVE-2024-0607, CVE-2024-27397, CVE-2024-26925, CVE-2025-38001, CVE-2026-23111

**EPRIV_NET_RAW:** None identified.

**EPRIV_TUNTAP:** None identified as requiring TUN/TAP. Some packet-triggered exploits may optionally use it, but that does not establish it as a necessary blocker.

**EPRIV_IP_LOOPBACK:** None identified.

**EPRIV_NETLINK:** Also those blocked by EPRIV_FIREWALL_TC, insofar as the documented attack paths use netlink. No additional CVEs identified.

**EPRIV_NET_ADMIN:** Also those blocked by EPRIV_FIREWALL_TC, insofar as the vulnerable operations require CAP_NET_ADMIN. No additional CVEs identified.

**EPRIV_OPEN_FILE_HANDLE:** CVE-2025-38306*

**EPRIV_UNSHARE_USERNS:** Also those blocked by EPRIV_FSOPEN_VIRT, EPRIV_MOVE_MOUNT, EPRIV_FIREWALL_TC, EPRIV_OPEN_FILE_HANDLE, EPRIV_MOUNT_CGROUPv1, and EPRIV_MOUNT_SYSFS, plus CVE-2025-38058*. More generally, blocks the documented unprivileged user-namespace setup for the entire inventory when no usable user namespace already exists.

**EPRIV_UNSHARE_NONUSERNS:** Also the namespace-dependent attack paths blocked by EPRIV_FIREWALL_TC, EPRIV_MOVE_MOUNT, EPRIV_MOUNT_CGROUPv1, EPRIV_MOUNT_SYSFS, and many of those blocked by EPRIV_FSOPEN_VIRT. Coverage depends on whether the necessary non-user namespaces already exist.

**EPRIV_MOUNT_CGROUPv1:** CVE-2022-0492*

**EPRIV_MOUNT_CGROUPv2:** None identified.

**EPRIV_PTRACE:** None identified.

**EPRIV_LOAD_EBPF:** None identified.

**EPRIV_MOUNT_PROC_PIDONLY:** None identified.

**EPRIV_MOUNT_PROC_NOTPIDONLY:** None identified.

**EPRIV_MOUNT_SYSFS:** CVE-2025-22089*

CVEs not cleanly blocked by an operation-specific bit Excluding the two EPRIV_UNSHARE_* gates:

- CVE-2025-38058: No explicit unmount privilege. The vulnerable race involves umount(2) and path lookup.

- CVE-2022-0492: The cgroup-v1 mount bit covers the documented new-mount attack path, but not necessarily configuration of release_agent on an existing writable hierarchy.

- CVE-2025-38499: The correct gate depends on which filesystem-context or internal cloning operation reaches clone_private_mnt(). I would not count EPRIV_CLONE_TREE as a definitive blocker without checking the exact call paths.

maintainer
#10 lore raw

Re: [PATCH v2 1/4] userns: introduce capability bounding set for user namespacesg

Quoted 51 lines · Casey Schaufler
Quoted 24 lines · Andy Lutomirski
Quoted 21 lines · Andy Lutomirski

On Thu, Nov 19, 2026 at 2:43 AM Hallgrimur H. Gunnarsson

Quoted 7 lines · <[email protected]> wrote:

When a process creates a new user namespace, it receives a full set of capabilities (CAP_FULL_SET) scoped to that namespace. While namespaced in scope, several of these capabilities (such as CAP_NET_ADMIN and CAP_NET_RAW) expose broad kernel attack surface that many sandboxes and containers never need. However, there is currently no configurable way to withhold such capabilities from user namespaces while still granting them to workloads that require them.

One thought (from the rootns thread): the other decent sized attack surface here is CAP_MOUNT_ADMIN. Which doesn't exist as a capability bit.

A sort of horrible solution (but maybe not so awful) would be to declare that the bits in cap_userns aren't actually capability bits, and that you need the bit in cap_userns *and* the bit in cap_effective to do sensitive things, and that mounting needs cap_userns to have NSCAP_MOUNT_ADMIN *and* cap_effective to have CAP_SYS_ADMIN.

Quoted 3 lines

I want to sleep on this. It might actually solve several problems, e.g. controlling creation of ipv4 and ipv6 loopback or tunnel devices or whatever.

Quoted 7 lines

I slept on it. Here’s a counterproposal. I’m not saying I think this is better than this patch set, but I think it’s worth weighting the options.

Define a whole new set of privilege bits. As a poorly-painted-bikeshed option, I’ll call them eprivs (for exposure privileges - it’s a crappy name but at least it’s pronounceable).

I played with a mechanism I called "chits" (all the good terms for security bits have been consumed for a very long time) that looks a lot like what you're proposing. I did it to address the CAP_SYS_ADMIN problem, where any use of the capability opens up a whole barrel of worms. I cannot, unfortunately, find my patches. :( The basic approach is:

A process has an optional set of chits. A process without a chit set is unaffected by the mechanism. A process with a chit set is allowed only those operations for which it has a chit. The existing but empty chit set allows no operations. A process may drop a chit, but not the set, which, again, can be empty.

Because I was after CAP_SYS_ADMIN, I envisioned a call
cap_able_chit(capability, chit-list)
but there's no reason there couldn't be a
chit_able(chit-list)
as well.

Quoted 5 lines

I wrote this as an LSM, but the system-wide aspect of it made that a questionable choice.

If you have any interest, I could dig more deeply to try to find the patches. Otherwise, I'm happy to look at what you come up with.

What if eprivs or chits would take each capability and subvidide them into pieces? CAP_MAC_ADMIN would be formally a set of chits (or eprivs).

And process having e.g., CAP_MAC_ADMIN, would actually have the set of chits that are included to CAP_MAC_ADMIN.

Without that type of relation there's just a space full of chit ;-)

Br, Jarkko

maintainer
#11 lore raw

Re: [PATCH v2 1/4] userns: introduce capability bounding set for user namespacesg

Quoted 62 lines · Jarkko Sakkinen
Quoted 51 lines · Casey Schaufler
Quoted 24 lines · Andy Lutomirski
Quoted 21 lines · Andy Lutomirski

On Thu, Nov 19, 2026 at 2:43 AM Hallgrimur H. Gunnarsson

Quoted 7 lines · <[email protected]> wrote:

When a process creates a new user namespace, it receives a full set of capabilities (CAP_FULL_SET) scoped to that namespace. While namespaced in scope, several of these capabilities (such as CAP_NET_ADMIN and CAP_NET_RAW) expose broad kernel attack surface that many sandboxes and containers never need. However, there is currently no configurable way to withhold such capabilities from user namespaces while still granting them to workloads that require them.

One thought (from the rootns thread): the other decent sized attack surface here is CAP_MOUNT_ADMIN. Which doesn't exist as a capability bit.

A sort of horrible solution (but maybe not so awful) would be to declare that the bits in cap_userns aren't actually capability bits, and that you need the bit in cap_userns *and* the bit in cap_effective to do sensitive things, and that mounting needs cap_userns to have NSCAP_MOUNT_ADMIN *and* cap_effective to have CAP_SYS_ADMIN.

Quoted 3 lines

I want to sleep on this. It might actually solve several problems, e.g. controlling creation of ipv4 and ipv6 loopback or tunnel devices or whatever.

Quoted 7 lines

I slept on it. Here’s a counterproposal. I’m not saying I think this is better than this patch set, but I think it’s worth weighting the options.

Define a whole new set of privilege bits. As a poorly-painted-bikeshed option, I’ll call them eprivs (for exposure privileges - it’s a crappy name but at least it’s pronounceable).

I played with a mechanism I called "chits" (all the good terms for security bits have been consumed for a very long time) that looks a lot like what you're proposing. I did it to address the CAP_SYS_ADMIN problem, where any use of the capability opens up a whole barrel of worms. I cannot, unfortunately, find my patches. :( The basic approach is:

A process has an optional set of chits. A process without a chit set is unaffected by the mechanism. A process with a chit set is allowed only those operations for which it has a chit. The existing but empty chit set allows no operations. A process may drop a chit, but not the set, which, again, can be empty.

Because I was after CAP_SYS_ADMIN, I envisioned a call
cap_able_chit(capability, chit-list)
but there's no reason there couldn't be a
chit_able(chit-list)
as well.

Quoted 5 lines

I wrote this as an LSM, but the system-wide aspect of it made that a questionable choice.

If you have any interest, I could dig more deeply to try to find the patches. Otherwise, I'm happy to look at what you come up with.

What if eprivs or chits would take each capability and subvidide them into pieces? CAP_MAC_ADMIN would be formally a set of chits (or eprivs).

Quoted 5 lines

And process having e.g., CAP_MAC_ADMIN, would actually have the set of chits that are included to CAP_MAC_ADMIN.

Without that type of relation there's just a space full of chit ;-)

This would not prevent from combining your own collections of chit that do not map to any specific cap, only that each cap should map to a specific set.

Br, Jarkko

maintainer
#12 lore raw

Re: [PATCH v2 1/4] userns: introduce capability bounding set for user namespacesg

Quoted 66 lines · Jarkko Sakkinen
Quoted 65 lines · Jarkko Sakkinen
Quoted 51 lines · Casey Schaufler
Quoted 24 lines · Andy Lutomirski
Quoted 21 lines · Andy Lutomirski

On Thu, Nov 19, 2026 at 2:43 AM Hallgrimur H. Gunnarsson

Quoted 7 lines · <[email protected]> wrote:

When a process creates a new user namespace, it receives a full set of capabilities (CAP_FULL_SET) scoped to that namespace. While namespaced in scope, several of these capabilities (such as CAP_NET_ADMIN and CAP_NET_RAW) expose broad kernel attack surface that many sandboxes and containers never need. However, there is currently no configurable way to withhold such capabilities from user namespaces while still granting them to workloads that require them.

One thought (from the rootns thread): the other decent sized attack surface here is CAP_MOUNT_ADMIN. Which doesn't exist as a capability bit.

A sort of horrible solution (but maybe not so awful) would be to declare that the bits in cap_userns aren't actually capability bits, and that you need the bit in cap_userns *and* the bit in cap_effective to do sensitive things, and that mounting needs cap_userns to have NSCAP_MOUNT_ADMIN *and* cap_effective to have CAP_SYS_ADMIN.

Quoted 3 lines

I want to sleep on this. It might actually solve several problems, e.g. controlling creation of ipv4 and ipv6 loopback or tunnel devices or whatever.

Quoted 7 lines

I slept on it. Here’s a counterproposal. I’m not saying I think this is better than this patch set, but I think it’s worth weighting the options.

Define a whole new set of privilege bits. As a poorly-painted-bikeshed option, I’ll call them eprivs (for exposure privileges - it’s a crappy name but at least it’s pronounceable).

I played with a mechanism I called "chits" (all the good terms for security bits have been consumed for a very long time) that looks a lot like what you're proposing. I did it to address the CAP_SYS_ADMIN problem, where any use of the capability opens up a whole barrel of worms. I cannot, unfortunately, find my patches. :( The basic approach is:

A process has an optional set of chits. A process without a chit set is unaffected by the mechanism. A process with a chit set is allowed only those operations for which it has a chit. The existing but empty chit set allows no operations. A process may drop a chit, but not the set, which, again, can be empty.

Because I was after CAP_SYS_ADMIN, I envisioned a call
cap_able_chit(capability, chit-list)
but there's no reason there couldn't be a
chit_able(chit-list)
as well.

Quoted 5 lines

I wrote this as an LSM, but the system-wide aspect of it made that a questionable choice.

If you have any interest, I could dig more deeply to try to find the patches. Otherwise, I'm happy to look at what you come up with.

What if eprivs or chits would take each capability and subvidide them into pieces? CAP_MAC_ADMIN would be formally a set of chits (or eprivs).

And process having e.g., CAP_MAC_ADMIN, would actually have the set of chits that are included to CAP_MAC_ADMIN.

Quoted 6 lines
Quoted 2 lines

Without that type of relation there's just a space full of chit ;-)

This would not prevent from combining your own collections of chit that do not map to any specific cap, only that each cap should map to a specific set.

With decompose/compose relation it would neither matter if caps would have for some reason the same chit. Internally task could have just this sets and caps can be dynamically refreshed if the process' set has all the chits that compose it.

I.e., that would make caps a cached result refresh, and chits the actually stored security tokens.

Br, Jarkko

#13 lore raw

Re: [PATCH v2 1/4] userns: introduce capability bounding set for user namespacesg

In reply to Jarkko Sakkinen
Quoted 53 lines · Jarkko Sakkinen
Quoted 52 lines · Casey Schaufler
Quoted 23 lines · Andy Lutomirski
Quoted 20 lines · Andy Lutomirski

On Thu, Nov 19, 2026 at 2:43 AM Hallgrimur H. Gunnarsson

Quoted 7 lines · <[email protected]> wrote:

When a process creates a new user namespace, it receives a full set of capabilities (CAP_FULL_SET) scoped to that namespace. While namespaced in scope, several of these capabilities (such as CAP_NET_ADMIN and CAP_NET_RAW) expose broad kernel attack surface that many sandboxes and containers never need. However, there is currently no configurable way to withhold such capabilities from user namespaces while still granting them to workloads that require them.

One thought (from the rootns thread): the other decent sized attack surface here is CAP_MOUNT_ADMIN. Which doesn't exist as a capability bit.

A sort of horrible solution (but maybe not so awful) would be to declare that the bits in cap_userns aren't actually capability bits, and that you need the bit in cap_userns *and* the bit in cap_effective to do sensitive things, and that mounting needs cap_userns to have NSCAP_MOUNT_ADMIN *and* cap_effective to have CAP_SYS_ADMIN.

Quoted 3 lines

I want to sleep on this. It might actually solve several problems, e.g. controlling creation of ipv4 and ipv6 loopback or tunnel devices or whatever.

Quoted 7 lines

I slept on it. Here’s a counterproposal. I’m not saying I think this is better than this patch set, but I think it’s worth weighting the options.

Define a whole new set of privilege bits. As a poorly-painted-bikeshed option, I’ll call them eprivs (for exposure privileges - it’s a crappy name but at least it’s pronounceable).

I played with a mechanism I called "chits" (all the good terms for security bits have been consumed for a very long time) that looks a lot like what you're proposing. I did it to address the CAP_SYS_ADMIN problem, where any use of the capability opens up a whole barrel of worms. I cannot, unfortunately, find my patches. :( The basic approach is:

A process has an optional set of chits. A process without a chit set is unaffected by the mechanism. A process with a chit set is allowed only those operations for which it has a chit. The existing but empty chit set allows no operations. A process may drop a chit, but not the set, which, again, can be empty.

Because I was after CAP_SYS_ADMIN, I envisioned a call
cap_able_chit(capability, chit-list)
but there's no reason there couldn't be a
chit_able(chit-list)
as well.

I wrote this as an LSM, but the system-wide aspect of it made that a questionable choice.

Quoted 8 lines
Quoted 2 lines

If you have any interest, I could dig more deeply to try to find the patches. Otherwise, I'm happy to look at what you come up with.

What if eprivs or chits would take each capability and subvidide them into pieces? CAP_MAC_ADMIN would be formally a set of chits (or eprivs).

And process having e.g., CAP_MAC_ADMIN, would actually have the set of chits that are included to CAP_MAC_ADMIN.

That would require that chits have the same inheritance rules as capabilities, and I think that's a really bad idea. I was an active member of the P1003.1e/2c committee that defined capabilities, and was a major advocate of their inclusion in Linux. I wish that I could say they've been successful, but root still rules the roost. I attribute that to the complexity that arose from trying to address privilege via setuid and privilege bracketing at the same time. Chits (or eprivs) as a finer granularity version of capabilities would make granular privilege even harder to sell than it is now.

Quoted 2 lines

Without that type of relation there's just a space full of chit ;-)

Which is one of the reasons I haven't published anything about them. Even with the scheme being (a lot) simpler than capabilities I don't see it as something I have the resources to complete. If Andy wants to drive the process I'm willing to contribute where I can.

Quoted 2 lines

Br, Jarkko

maintainer
#14 lore raw

Re: [PATCH v2 1/4] userns: introduce capability bounding set for user namespacesg

Quoted 63 lines · Casey Schaufler
Quoted 53 lines · Jarkko Sakkinen
Quoted 52 lines · Casey Schaufler
Quoted 23 lines · Andy Lutomirski
Quoted 20 lines · Andy Lutomirski

On Thu, Nov 19, 2026 at 2:43 AM Hallgrimur H. Gunnarsson

Quoted 7 lines · <[email protected]> wrote:

When a process creates a new user namespace, it receives a full set of capabilities (CAP_FULL_SET) scoped to that namespace. While namespaced in scope, several of these capabilities (such as CAP_NET_ADMIN and CAP_NET_RAW) expose broad kernel attack surface that many sandboxes and containers never need. However, there is currently no configurable way to withhold such capabilities from user namespaces while still granting them to workloads that require them.

One thought (from the rootns thread): the other decent sized attack surface here is CAP_MOUNT_ADMIN. Which doesn't exist as a capability bit.

A sort of horrible solution (but maybe not so awful) would be to declare that the bits in cap_userns aren't actually capability bits, and that you need the bit in cap_userns *and* the bit in cap_effective to do sensitive things, and that mounting needs cap_userns to have NSCAP_MOUNT_ADMIN *and* cap_effective to have CAP_SYS_ADMIN.

Quoted 3 lines

I want to sleep on this. It might actually solve several problems, e.g. controlling creation of ipv4 and ipv6 loopback or tunnel devices or whatever.

Quoted 7 lines

I slept on it. Here’s a counterproposal. I’m not saying I think this is better than this patch set, but I think it’s worth weighting the options.

Define a whole new set of privilege bits. As a poorly-painted-bikeshed option, I’ll call them eprivs (for exposure privileges - it’s a crappy name but at least it’s pronounceable).

I played with a mechanism I called "chits" (all the good terms for security bits have been consumed for a very long time) that looks a lot like what you're proposing. I did it to address the CAP_SYS_ADMIN problem, where any use of the capability opens up a whole barrel of worms. I cannot, unfortunately, find my patches. :( The basic approach is:

A process has an optional set of chits. A process without a chit set is unaffected by the mechanism. A process with a chit set is allowed only those operations for which it has a chit. The existing but empty chit set allows no operations. A process may drop a chit, but not the set, which, again, can be empty.

Because I was after CAP_SYS_ADMIN, I envisioned a call
cap_able_chit(capability, chit-list)
but there's no reason there couldn't be a
chit_able(chit-list)
as well.

I wrote this as an LSM, but the system-wide aspect of it made that a questionable choice.

Quoted 8 lines
Quoted 2 lines

If you have any interest, I could dig more deeply to try to find the patches. Otherwise, I'm happy to look at what you come up with.

What if eprivs or chits would take each capability and subvidide them into pieces? CAP_MAC_ADMIN would be formally a set of chits (or eprivs).

And process having e.g., CAP_MAC_ADMIN, would actually have the set of chits that are included to CAP_MAC_ADMIN.

Quoted 9 lines

That would require that chits have the same inheritance rules as capabilities, and I think that's a really bad idea. I was an active member of the P1003.1e/2c committee that defined capabilities, and was a major advocate of their inclusion in Linux. I wish that I could say they've been successful, but root still rules the roost. I attribute that to the complexity that arose from trying to address privilege via setuid and privilege bracketing at the same time. Chits (or eprivs) as a finer granularity version of capabilities would make granular privilege even harder to sell than it is now.

Perhaps (or likely'ish). I'm just unpurging what I meant (even if it ought to be wrong):

1. You can create F(C) -> S where C is set of caps and S is a set of chits.
2. G(S) -> C, which finds using some heuristics a set C for which F(C) = S.

Quoted 8 lines
Quoted 3 lines

Without that type of relation there's just a space full of chit ;-)

Which is one of the reasons I haven't published anything about them. Even with the scheme being (a lot) simpler than capabilities I don't see it as something I have the resources to complete. If Andy wants to drive the process I'm willing to contribute where I can.

You should e.g., RFC patch. We're exactly in the situation where the skill of not knowing what you're doing is the skill that should be applied with pride ;-)

Br, Jarkko

maintainer
#15 lore raw

Re: [PATCH v2 1/4] userns: introduce capability bounding set for user namespacesg

Quoted 74 lines · Jarkko Sakkinen
Quoted 63 lines · Casey Schaufler
Quoted 53 lines · Jarkko Sakkinen
Quoted 52 lines · Casey Schaufler
Quoted 23 lines · Andy Lutomirski
Quoted 20 lines · Andy Lutomirski

On Thu, Nov 19, 2026 at 2:43 AM Hallgrimur H. Gunnarsson

Quoted 7 lines · <[email protected]> wrote:

When a process creates a new user namespace, it receives a full set of capabilities (CAP_FULL_SET) scoped to that namespace. While namespaced in scope, several of these capabilities (such as CAP_NET_ADMIN and CAP_NET_RAW) expose broad kernel attack surface that many sandboxes and containers never need. However, there is currently no configurable way to withhold such capabilities from user namespaces while still granting them to workloads that require them.

One thought (from the rootns thread): the other decent sized attack surface here is CAP_MOUNT_ADMIN. Which doesn't exist as a capability bit.

A sort of horrible solution (but maybe not so awful) would be to declare that the bits in cap_userns aren't actually capability bits, and that you need the bit in cap_userns *and* the bit in cap_effective to do sensitive things, and that mounting needs cap_userns to have NSCAP_MOUNT_ADMIN *and* cap_effective to have CAP_SYS_ADMIN.

Quoted 3 lines

I want to sleep on this. It might actually solve several problems, e.g. controlling creation of ipv4 and ipv6 loopback or tunnel devices or whatever.

Quoted 7 lines

I slept on it. Here’s a counterproposal. I’m not saying I think this is better than this patch set, but I think it’s worth weighting the options.

Define a whole new set of privilege bits. As a poorly-painted-bikeshed option, I’ll call them eprivs (for exposure privileges - it’s a crappy name but at least it’s pronounceable).

I played with a mechanism I called "chits" (all the good terms for security bits have been consumed for a very long time) that looks a lot like what you're proposing. I did it to address the CAP_SYS_ADMIN problem, where any use of the capability opens up a whole barrel of worms. I cannot, unfortunately, find my patches. :( The basic approach is:

A process has an optional set of chits. A process without a chit set is unaffected by the mechanism. A process with a chit set is allowed only those operations for which it has a chit. The existing but empty chit set allows no operations. A process may drop a chit, but not the set, which, again, can be empty.

Because I was after CAP_SYS_ADMIN, I envisioned a call
cap_able_chit(capability, chit-list)
but there's no reason there couldn't be a
chit_able(chit-list)
as well.

I wrote this as an LSM, but the system-wide aspect of it made that a questionable choice.

Quoted 8 lines
Quoted 2 lines

If you have any interest, I could dig more deeply to try to find the patches. Otherwise, I'm happy to look at what you come up with.

What if eprivs or chits would take each capability and subvidide them into pieces? CAP_MAC_ADMIN would be formally a set of chits (or eprivs).

And process having e.g., CAP_MAC_ADMIN, would actually have the set of chits that are included to CAP_MAC_ADMIN.

Quoted 9 lines

That would require that chits have the same inheritance rules as capabilities, and I think that's a really bad idea. I was an active member of the P1003.1e/2c committee that defined capabilities, and was a major advocate of their inclusion in Linux. I wish that I could say they've been successful, but root still rules the roost. I attribute that to the complexity that arose from trying to address privilege via setuid and privilege bracketing at the same time. Chits (or eprivs) as a finer granularity version of capabilities would make granular privilege even harder to sell than it is now.

Quoted 5 lines

Perhaps (or likely'ish). I'm just unpurging what I meant (even if it ought to be wrong):

1. You can create F(C) -> S where C is set of caps and S is a set of chits.

s/You can create//

(left by accident)

Br, Jarkko

#16 lore raw

Re: [PATCH v2 1/4] userns: introduce capability bounding set for user namespaces

In reply to Casey Schaufler
Quoted 46 lines · Casey Schaufler
Quoted 24 lines · Andy Lutomirski
Quoted 21 lines · Andy Lutomirski

On Thu, Nov 19, 2026 at 2:43 AM Hallgrimur H. Gunnarsson

Quoted 7 lines · <[email protected]> wrote:

When a process creates a new user namespace, it receives a full set of capabilities (CAP_FULL_SET) scoped to that namespace. While namespaced in scope, several of these capabilities (such as CAP_NET_ADMIN and CAP_NET_RAW) expose broad kernel attack surface that many sandboxes and containers never need. However, there is currently no configurable way to withhold such capabilities from user namespaces while still granting them to workloads that require them.

One thought (from the rootns thread): the other decent sized attack surface here is CAP_MOUNT_ADMIN. Which doesn't exist as a capability bit.

A sort of horrible solution (but maybe not so awful) would be to declare that the bits in cap_userns aren't actually capability bits, and that you need the bit in cap_userns *and* the bit in cap_effective to do sensitive things, and that mounting needs cap_userns to have NSCAP_MOUNT_ADMIN *and* cap_effective to have CAP_SYS_ADMIN.

Quoted 3 lines

I want to sleep on this. It might actually solve several problems, e.g. controlling creation of ipv4 and ipv6 loopback or tunnel devices or whatever.

Quoted 7 lines

I slept on it. Here’s a counterproposal. I’m not saying I think this is better than this patch set, but I think it’s worth weighting the options.

Define a whole new set of privilege bits. As a poorly-painted-bikeshed option, I’ll call them eprivs (for exposure privileges - it’s a crappy name but at least it’s pronounceable).

I played with a mechanism I called "chits" (all the good terms for security bits have been consumed for a very long time) that looks a lot like what you're proposing. I did it to address the CAP_SYS_ADMIN problem, where any use of the capability opens up a whole barrel of worms. I cannot, unfortunately, find my patches. :( The basic approach is:

A process has an optional set of chits. A process without a chit set is unaffected by the mechanism. A process with a chit set is allowed only those operations for which it has a chit. The existing but empty chit set allows no operations. A process may drop a chit, but not the set, which, again, can be empty.

Quoted 5 lines

Because I was after CAP_SYS_ADMIN, I envisioned a call
cap_able_chit(capability, chit-list)
but there's no reason there couldn't be a
chit_able(chit-list)
as well.

This is quite pronounceable, but I'm not sure I could submit a patchset with a chitlist with a straight face :)

I feel like, in our brave new world, much of the work here is defining the interface and how it should work, and our little AI interns have gotten quite good at actually writing the code. So my grand plan is to let people contemplate it until next week (i.e. after the Thanksgiving holiday) before actually producing any code here.

I was imagining something like:

prctl(PR_EPRIVS_AND, mask1, mask2, mask3, mask4);

(i.e. define the things to be 64 * 4 bits max until we add a new prctl, which will hopefully be along time.) And to maybe make mask4 be specifically arch-dependent bits, because I think EPRIV_X86_LDT would be an excellent addition. (I say this with some chagrin because I fixed some gnarly vulns quite a while ago in modify_ldt, and I missed smp_mb(), and someone rooted it.)

Quoted 3 lines

I wrote this as an LSM, but the system-wide aspect of it made that a questionable choice.

I'm thinking not an LSM. The goal would be to make it available everywhere.

(If you missed the other thread, I'm also imagining adding CLONE_NO_NNP, only allowed with CLONE_NEWUSER, which would *clear* no_new_privs. LSM would have a chance to veto this, but the default behavior would be to allow it. This would allow running an entire system with no_new_privs set for all normal tasks including PID1 while still running conventional distros in containers.)

Quoted 174 lines

If you have any interest, I could dig more deeply to try to find the patches. Otherwise, I'm happy to look at what you come up with.

Quoted 170 lines

An epriv is not permission to do something *to* an object; it’s permission to do something that exposes a meaningful attack surface within the kernel. So there’s no ns_has_epriv because there is no object. These are kind of the opposite of object capabilities. Additionally, an epriv never grants the ability to do something that one couldn’t do in an epriv-less world.

For now, all tasks have all eprivs, even not-yet-defined ones, unless user code or config explicitly changes this. (Maybe some day secure boot might remove certain eprivs.)

There should never be a check like ns_capable || has_epriv. It’s also &&, or perhaps caps are not checked at all.

Example eprivs include:

EPRIV_FSOPEN_VIRT: may fsconfig, fsopen, etc a virtual fs like fuse or tmpfs or overlayfs.

EPRIV_CLONE_TREE: may clone a mount tree

EPRIV_MOVE_MOUNT: may move mounts around (but only if you also have CAP_SYS_ADMIN on the correct namespace, of course)

EPRIV_FIREWALL_TC: may configure any firewalling configuration or tc configuration (this includes iptables, nftables, and ebtables)

EPRIV_NET_RAW: may use raw/packet sockets (like CAP_NET_RAW)

EPRIV_TUNTAP: may create and attach to tun/tap interfaces

EPRIV_IP_LOOPBACK: may set up IPv4 and IPv6 loopback using whatever new facility we add

EPRIV_NETLINK: may use netlink at all

EPRIV_NET_ADMIN: may use traditional CAP_NET_ADMIN abilities (all CAP_NET_ADMIN checks will also check EPRIV_NET_ADMIN)

EPRIV_OPEN_FILE_HANDLE: May use open_by_handle_at, etc.

EPRIV_UNSHARE_USERNS: may unshare userns

EPRIV_UNSHARE_NONUSERNS: may unshare any other namespace

EPRIV_MOUNT_CGROUPv1, EPRIV_MOUNT_CGROUPv2: may create a new mount of these subsystems

EPRIV_PTRACE: there are lots of different variations that might make sense.

EPRIV_MOUNT_PROC_PIDONLY: may mount proc-pidonly

EPRIV_MOUNT_PROC_NOTPIDONLY: may mount proc not-pidonly

EPRIV_MOUNT_SYSFS: may mount sysfs

Example eprivs that are questionable:

EPRIV_DMESG: the kernel log is a specific object, and I think it's better to control access using something kernel-log-specific.

There is no operation that increases eprivs -- even without no_new_privs set, a task will never gain an epriv, nor will a child ever have an epriv that its creator did not have at the time the child was created.

The evolution rules could be as simple as, on fork/clone, the child inheriting exactly the parent's eprivs.

Or we could bind eprivs to a userns instead of a task, but that could be more limiting and awkward than we want.

What do you all think?

FWIW, I had an LLM make an inventory (surely not exhaustive) of recent-ish CVEs and how they relate to this list. (The below is the only part of this email that is LLM-generated, although I added EPRIV_SYSFS because I didn't realize that nonroot userns could mount it until I asked an LLM, sigh.) To me, the list and its breakdown suggests that there is quite a lot of room for meaningful attack surface reductions while still leaving large parts of userns available, and that my epriv proposal captures much of this but the cap_userns proposal may be too coarse-grained.

(I also asked about eBPF, and my LLM came up with a lot of CVEs, but there's an existing BPF token mechanism and I therefore did not propose EPRIV_LOAD_EBPF.)

--- begin LLM output ---

**EPRIV_FSOPEN_VIRT:** CVE-2022-0185*, CVE-2023-0386*, CVE-2023-2640*, CVE-2023-32629*, CVE-2025-38499*

**EPRIV_CLONE_TREE:** CVE-2025-38499* (only if the check also covers the relevant internal mount-cloning path; explicit open_tree() restrictions alone are insufficient)

**EPRIV_MOVE_MOUNT:** CVE-2025-37988

**EPRIV_FIREWALL_TC:** CVE-2022-25636, CVE-2022-1015, CVE-2022-1016, CVE-2022-32250, CVE-2022-34918, CVE-2022-48911*, CVE-2022-2588, CVE-2023-32233, CVE-2023-35001, CVE-2023-4004, CVE-2023-4015, CVE-2023-4244, CVE-2023-5197, CVE-2023-6817, CVE-2023-3609, CVE-2023-4623, CVE-2023-4921, CVE-2024-1086, CVE-2024-0607, CVE-2024-27397, CVE-2024-26925, CVE-2025-38001, CVE-2026-23111

**EPRIV_NET_RAW:** None identified.

**EPRIV_TUNTAP:** None identified as requiring TUN/TAP. Some packet-triggered exploits may optionally use it, but that does not establish it as a necessary blocker.

**EPRIV_IP_LOOPBACK:** None identified.

**EPRIV_NETLINK:** Also those blocked by EPRIV_FIREWALL_TC, insofar as the documented attack paths use netlink. No additional CVEs identified.

**EPRIV_NET_ADMIN:** Also those blocked by EPRIV_FIREWALL_TC, insofar as the vulnerable operations require CAP_NET_ADMIN. No additional CVEs identified.

**EPRIV_OPEN_FILE_HANDLE:** CVE-2025-38306*

**EPRIV_UNSHARE_USERNS:** Also those blocked by EPRIV_FSOPEN_VIRT, EPRIV_MOVE_MOUNT, EPRIV_FIREWALL_TC, EPRIV_OPEN_FILE_HANDLE, EPRIV_MOUNT_CGROUPv1, and EPRIV_MOUNT_SYSFS, plus CVE-2025-38058*. More generally, blocks the documented unprivileged user-namespace setup for the entire inventory when no usable user namespace already exists.

**EPRIV_UNSHARE_NONUSERNS:** Also the namespace-dependent attack paths blocked by EPRIV_FIREWALL_TC, EPRIV_MOVE_MOUNT, EPRIV_MOUNT_CGROUPv1, EPRIV_MOUNT_SYSFS, and many of those blocked by EPRIV_FSOPEN_VIRT. Coverage depends on whether the necessary non-user namespaces already exist.

**EPRIV_MOUNT_CGROUPv1:** CVE-2022-0492*

**EPRIV_MOUNT_CGROUPv2:** None identified.

**EPRIV_PTRACE:** None identified.

**EPRIV_LOAD_EBPF:** None identified.

**EPRIV_MOUNT_PROC_PIDONLY:** None identified.

**EPRIV_MOUNT_PROC_NOTPIDONLY:** None identified.

**EPRIV_MOUNT_SYSFS:** CVE-2025-22089*

CVEs not cleanly blocked by an operation-specific bit Excluding the two EPRIV_UNSHARE_* gates:

- CVE-2025-38058: No explicit unmount privilege. The vulnerable race involves umount(2) and path lookup.

- CVE-2022-0492: The cgroup-v1 mount bit covers the documented new-mount attack path, but not necessarily configuration of release_agent on an existing writable hierarchy.

- CVE-2025-38499: The correct gate depends on which filesystem-context or internal cloning operation reaches clone_private_mnt(). I would not count EPRIV_CLONE_TREE as a definitive blocker without checking the exact call paths.

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
#17 lore raw

PATCH v2 2/4 capability: bound ptrace and cred subset checks by userns ceilings

In reply to Hallgrimur H. Gunnarsson

Same-namespace ptrace checks only compare cap_permitted (or cap_effective), ignoring the userns capability ceiling. As a result, a task with a lowered ceiling could trace a less-restricted same-UID task in the same user namespace and use it to create a wider child user namespace.

Require the tracee's cred_userns_bset() to be a subset of the tracer's in the same-namespace check in cap_ptrace_access_check() and cap_ptrace_traceme(). Cross-namespace implicit CAP_SYS_PTRACE via user namespace ownership is already bounded by cap_capable_helper(), while tracers holding explicit CAP_SYS_PTRACE retain access.

Also update cred_cap_issubset() so commit_creds() resets mm->dumpable and pdeath_signal whenever a credential transition widens the effective userns capability ceiling.

---
 kernel/cred.c        | 13 +++++++++----
 security/commoncap.c | 12 ++++++++----
 2 files changed, 17 insertions(+), 8 deletions(-)
kernel/cred.c +9 -4
index d01df40a9a38..968122cdbf07 100644
@@ -335,17 +335,22 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
 	 * the capabilities of subset are a subset of set.
 	 */
 	if (set_ns == subset_ns)
-		return cap_issubset(subset->cap_permitted, set->cap_permitted);
+		return cap_issubset(subset->cap_permitted,
+				    set->cap_permitted) &&
+			cap_issubset(cred_userns_bset(subset),
+				     cred_userns_bset(set));
 
 	/* The credentials are in a different user namespaces
 	 * therefore one is a subset of the other only if a set is an
 	 * ancestor of subset and set->euid is owner of subset or one
-	 * of subsets ancestors.
+	 * of subsets ancestors, and set's userns capability ceiling
+	 * covers subset's capabilities.
 	 */
 	for (;subset_ns != &init_user_ns; subset_ns = subset_ns->parent) {
-		if ((set_ns == subset_ns->parent)  &&
+		if (set_ns == subset_ns->parent &&
 		    uid_eq(subset_ns->owner, set->euid))
-			return true;
+			return cap_issubset(subset_ns->cap_bset,
+					    cred_userns_bset(set));
 	}
 
 	return false;
security/commoncap.c +8 -4
index ddac8e917680..786f99eb6838 100644
@@ -157,7 +157,8 @@ int cap_settime(const struct timespec64 *ts, const struct timezone *tz)
  * @mode: The mode of attachment.
  *
  * If we are in the same or an ancestor user_ns and have all the target
- * task's capabilities, then ptrace access is allowed.
+ * task's capabilities (including its userns capability ceiling), then
+ * ptrace access is allowed.
  * If we have the ptrace capability to the target user_ns, then ptrace
  * access is allowed.
  * Else denied.
@@ -179,7 +180,8 @@ int cap_ptrace_access_check(struct task_struct *child, unsigned int mode)
 	else
 		caller_caps = &cred->cap_permitted;
 	if (cred->user_ns == child_cred->user_ns &&
-	    cap_issubset(child_cred->cap_permitted, *caller_caps))
+	    cap_issubset(child_cred->cap_permitted, *caller_caps) &&
+	    cap_issubset(cred_userns_bset(child_cred), cred_userns_bset(cred)))
 		goto out;
 	if (ns_capable(child_cred->user_ns, CAP_SYS_PTRACE))
 		goto out;
@@ -194,7 +196,8 @@ int cap_ptrace_access_check(struct task_struct *child, unsigned int mode)
  * @parent: The task proposed to be the tracer
  *
  * If parent is in the same or an ancestor user_ns and has all current's
- * capabilities, then ptrace access is allowed.
+ * capabilities (including its userns capability ceiling), then ptrace
+ * access is allowed.
  * If parent has the ptrace capability to current's user_ns, then ptrace
  * access is allowed.
  * Else denied.
@@ -211,7 +214,8 @@ int cap_ptrace_traceme(struct task_struct *parent)
 	cred = __task_cred(parent);
 	child_cred = current_cred();
 	if (cred->user_ns == child_cred->user_ns &&
-	    cap_issubset(child_cred->cap_permitted, cred->cap_permitted))
+	    cap_issubset(child_cred->cap_permitted, cred->cap_permitted) &&
+	    cap_issubset(cred_userns_bset(child_cred), cred_userns_bset(cred)))
 		goto out;
 	if (has_ns_capability(parent, child_cred->user_ns, CAP_SYS_PTRACE))
 		goto out;
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
#18 lore raw

Re: [PATCH v2 2/4] capability: bound ptrace and cred subset checks by userns ceilings

Sashiko has reviewed this patch and found no issues.
Quoted 12 lines

Same-namespace ptrace checks only compare cap_permitted (or cap_effective), ignoring the userns capability ceiling. As a result, a task with a lowered ceiling could trace a less-restricted same-UID task in the same user namespace and use it to create a wider child user namespace.

Require the tracee's cred_userns_bset() to be a subset of the tracer's in the same-namespace check in cap_ptrace_access_check() and cap_ptrace_traceme(). Cross-namespace implicit CAP_SYS_PTRACE via user namespace ownership is already bounded by cap_capable_helper(), while tracers holding explicit CAP_SYS_PTRACE retain access.

Quoted 7 lines

Also update cred_cap_issubset() so commit_creds() resets mm->dumpable and pdeath_signal whenever a credential transition widens the effective userns capability ceiling.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#19 lore raw

PATCH v2 3/4 proc: expose userns capability mask as CapUns in /proc/<pid>/status

In reply to Hallgrimur H. Gunnarsson

Render cred->cap_userns as CapUns in /proc/<pid>/status alongside other capability masks, allowing userspace tools to inspect a task's userns capability mask directly.

Document the new field in Documentation/filesystems/proc.rst.

---
 Documentation/filesystems/proc.rst | 2 ++
 fs/proc/array.c                    | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)
Documentation/filesystems/proc.rst +2 -0
index fa7a468e8edf..9cf45810e41c 100644
@@ -200,6 +200,7 @@ read the file /proc/PID/status::
   CapEff: 0000000000000000
   CapBnd: ffffffffffffffff
   CapAmb: 0000000000000000
+  CapUns: ffffffffffffffff
   NoNewPrivs:     0
   Seccomp:        0
   Speculation_Store_Bypass:       thread vulnerable
@@ -286,6 +287,7 @@ It's slow but very precise.
  CapEff                      bitmap of effective capabilities
  CapBnd                      bitmap of capabilities bounding set
  CapAmb                      bitmap of ambient capabilities
+ CapUns                      bitmap of userns capabilities
  NoNewPrivs                  no_new_privs, like prctl(PR_GET_NO_NEW_PRIV, ...)
  Seccomp                     seccomp mode, like prctl(PR_GET_SECCOMP, ...)
  Speculation_Store_Bypass    speculative store bypass mitigation status
fs/proc/array.c +3 -1
index f6f75d206762..2b86673aae00 100644
@@ -311,7 +311,7 @@ static inline void task_cap(struct seq_file *m, struct task_struct *p)
 {
 	const struct cred *cred;
 	kernel_cap_t cap_inheritable, cap_permitted, cap_effective,
-			cap_bset, cap_ambient;
+			cap_bset, cap_ambient, cap_userns;
 
 	rcu_read_lock();
 	cred = __task_cred(p);
@@ -320,6 +320,7 @@ static inline void task_cap(struct seq_file *m, struct task_struct *p)
 	cap_effective	= cred->cap_effective;
 	cap_bset	= cred->cap_bset;
 	cap_ambient	= cred->cap_ambient;
+	cap_userns	= cred->cap_userns;
 	rcu_read_unlock();
 
 	render_cap_t(m, "CapInh:\t", &cap_inheritable);
@@ -327,6 +328,7 @@ static inline void task_cap(struct seq_file *m, struct task_struct *p)
 	render_cap_t(m, "CapEff:\t", &cap_effective);
 	render_cap_t(m, "CapBnd:\t", &cap_bset);
 	render_cap_t(m, "CapAmb:\t", &cap_ambient);
+	render_cap_t(m, "CapUns:\t", &cap_userns);
 }
 
 static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
#20 lore raw

Re: [PATCH v2 3/4] proc: expose userns capability mask as CapUns in /proc/<pid>/status

Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

Render cred->cap_userns as CapUns in /proc/<pid>/status alongside other capability masks, allowing userspace tools to inspect a task's userns capability mask directly.

Document the new field in Documentation/filesystems/proc.rst.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#21 lore raw

PATCH v2 4/4 selftests/capabilities: add userns capability bounding set tests

In reply to Hallgrimur H. Gunnarsson

Add selftests in tools/testing/selftests/capabilities covering:

- prctl(PR_CAP_USERNS) argument validation and authorization rules for lowering, clearing, and raising capabilities.
- Default full capability grants, cap_userns restrictions (including clearing all capabilities), and monotonic inheritance across nested user namespaces.
- Default retention of capabilities in cap_permitted, and strict enforcement and persistence of SECBIT_CAP_USERNS_STRICT and its lock across user namespace transitions.
- Credential and cap_userns clamping upon entering a user namespace via setns().
- Implicit parent-owner capability bounding by the owned namespace's cap_bset (including over descendants) and the caller's userns ceiling, while preserving explicit ancestor capabilities.
- Ptrace restrictions across PTRACE_ATTACH, PTRACE_TRACEME, and PTRACE_MODE_READ for same-userns peers and owned descendant namespaces, while preserving explicit CAP_SYS_PTRACE.
- Preservation of dumpable and pdeath_signal when narrowing the userns ceiling and resets when widening it.
- CapUns reporting in /proc/self/status.

---
 .../testing/selftests/capabilities/.gitignore |    1 +
 tools/testing/selftests/capabilities/Makefile |    2 +-
 .../capabilities/userns_bounding_set_test.c   | 1064 +++++++++++++++++
 3 files changed, 1066 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/capabilities/userns_bounding_set_test.c
tools/testing/selftests/capabilities/.gitignore +1 -0
index 426d9adca67c..28767c08dea8 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 test_execve
+userns_bounding_set_test
 validate_cap
tools/testing/selftests/capabilities/Makefile +1 -1
index 411ac098308f..b29f7b117c11 100644
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 TEST_GEN_FILES := validate_cap
-TEST_GEN_PROGS := test_execve
+TEST_GEN_PROGS := test_execve userns_bounding_set_test
 
 CFLAGS += -O2 -g -std=gnu99 -Wall $(KHDR_INCLUDES)
 LDLIBS += -lcap-ng -lrt -ldl
tools/testing/selftests/capabilities/userns_bounding_set_test.c new file +1064 -0

1,064 lines not on this page · raw message

Signature · 1 line
2.56.1.708.g77570a6a1d-goog
#22 lore raw

Re: [PATCH v2 4/4] selftests/capabilities: add userns capability bounding set tests

Sashiko has reviewed this patch and found no issues.
Quoted 22 lines

Add selftests in tools/testing/selftests/capabilities covering:

- prctl(PR_CAP_USERNS) argument validation and authorization rules for lowering, clearing, and raising capabilities.
- Default full capability grants, cap_userns restrictions (including clearing all capabilities), and monotonic inheritance across nested user namespaces.
- Default retention of capabilities in cap_permitted, and strict enforcement and persistence of SECBIT_CAP_USERNS_STRICT and its lock across user namespace transitions.
- Credential and cap_userns clamping upon entering a user namespace via setns().
- Implicit parent-owner capability bounding by the owned namespace's cap_bset (including over descendants) and the caller's userns ceiling, while preserving explicit ancestor capabilities.
- Ptrace restrictions across PTRACE_ATTACH, PTRACE_TRACEME, and PTRACE_MODE_READ for same-userns peers and owned descendant namespaces, while preserving explicit CAP_SYS_PTRACE.
- Preservation of dumpable and pdeath_signal when narrowing the userns ceiling and resets when widening it.
- CapUns reporting in /proc/self/status.

Quoted 1 line

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4