Linux Security Modules development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hallgrimur H. Gunnarsson" <halg@google.com>,
	"Christian Brauner" <brauner@kernel.org>,
	"Serge Hallyn" <sergeh@kernel.org>,
	"Andy Lutomirski" <luto@kernel.org>
Cc: "Paul Moore" <paul@paul-moore.com>,
	"James Morris" <jmorris@namei.org>,
	"David Howells" <dhowells@redhat.com>,
	"Jarkko Sakkinen" <jarkko@kernel.org>,
	"Kees Cook" <kees@kernel.org>, "Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Mickaël Salaün" <mic@digikod.net>,
	"Jonathan Calmels" <jcalmels@3xx0.net>,
	"Jann Horn" <jannh@google.com>,
	"Günther Noack" <gnoack@google.com>,
	"KP Singh" <kpsingh@kernel.org>,
	"Casey Schaufler" <casey@schaufler-ca.com>,
	linux-security-module@vger.kernel.org, keyrings@vger.kernel.org
Subject: Re: [PATCH v2 1/4] userns: introduce capability bounding set for user namespaces
Date: Thu, 19 Nov 2026 11:11:50 +0000	[thread overview]
Message-ID: <sashiko-outbox-223014@kernel.org> (raw)
In-Reply-To: <20261119104208.782900-2-halg@google.com>

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@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

  reply	other threads:[~2026-11-19 11:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 10:42 [PATCH v2 0/4] userns: per-namespace capability bounding set Hallgrimur H. Gunnarsson
2026-11-19 10:42 ` [PATCH v2 1/4] userns: introduce capability bounding set for user namespaces Hallgrimur H. Gunnarsson
2026-11-19 11:11   ` sashiko-bot [this message]
2026-11-19 10:42 ` [PATCH v2 2/4] capability: bound ptrace and cred subset checks by userns ceilings Hallgrimur H. Gunnarsson
2026-11-19 10:51   ` sashiko-bot
2026-11-19 10:42 ` [PATCH v2 3/4] proc: expose userns capability mask as CapUns in /proc/<pid>/status Hallgrimur H. Gunnarsson
2026-11-19 10:46   ` sashiko-bot
2026-11-19 10:42 ` [PATCH v2 4/4] selftests/capabilities: add userns capability bounding set tests Hallgrimur H. Gunnarsson
2026-11-19 10:47   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-223014@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=brauner@kernel.org \
    --cc=casey@schaufler-ca.com \
    --cc=corbet@lwn.net \
    --cc=dhowells@redhat.com \
    --cc=gnoack@google.com \
    --cc=halg@google.com \
    --cc=jannh@google.com \
    --cc=jarkko@kernel.org \
    --cc=jcalmels@3xx0.net \
    --cc=jmorris@namei.org \
    --cc=kees@kernel.org \
    --cc=keyrings@vger.kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mic@digikod.net \
    --cc=paul@paul-moore.com \
    --cc=rdunlap@infradead.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sergeh@kernel.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox