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

sashiko-bot at kernel.org sashiko-bot at kernel.org
Thu Nov 19 11:11:50 UTC 2026


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 <halg at google.com>

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.

> diff --git a/security/commoncap.c b/security/commoncap.c
> index d47ab30223435..ddac8e9176808 100644
> --- a/security/commoncap.c
> +++ b/security/commoncap.c
> @@ -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
> +		 * 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().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119104208.782900-1-halg@google.com?part=1



More information about the Linux-security-module-archive mailing list