Linux Security Modules development
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serge@hallyn.com>
To: Josef Bacik <josef@toxicpanda.com>
Cc: Paul Moore <paul@paul-moore.com>,
	Christian Brauner <brauner@kernel.org>,
	James Morris <jmorris@namei.org>,
	David Howells <dhowells@redhat.com>,
	Jarkko Sakkinen <jarkko@kernel.org>,
	"Andrew G. Morgan" <morgan@kernel.org>,
	Serge Hallyn <sergeh@kernel.org>,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org, keyrings@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, Shuah Khan <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org,
	Bradley Morgan <brads@mainlining.org>
Subject: Re: [PATCH v11 1/3] userns: don't let setns() lend CAP_SETFCAP
Date: Sun, 22 Nov 2026 10:14:59 -0600	[thread overview]
Message-ID: <awMVA+9Q+7mF7naH@hallyn.com> (raw)
In-Reply-To: <awCEjJ8syhv+f4vd@hallyn.com>

On Fri, Nov 20, 2026 at 11:34:04AM -0600, Serge E. Hallyn wrote:
> On Fri, Nov 20, 2026 at 11:22:37AM -0600, Serge E. Hallyn wrote:
> > On Tue, Nov 17, 2026 at 07:54:24PM +0000, Josef Bacik wrote:
> > > A uid 0 task that gave up CAP_SETFCAP can get it back by joining a user
> > > namespace that another root task created.  Commit db2e718a4798
> > > ("capabilities: require CAP_SETFCAP to map uid 0") keeps such a task
> > > from mapping uid 0 into a namespace it creates itself, because tasks in
> > > that namespace could then write file capabilities for its root user.
> > > setns() gives a joiner a full capability set in the namespace too, so
> > > it can do the same there:
> > > 
> > >   task A: uid 0, full caps          task B: uid 0, no CAP_SETFCAP
> > >   unshare(CLONE_NEWUSER)
> > >                                     setns(A's user ns)
> > >                                       allowed, euid == ns->owner
> > >                                     write "0 0 1" to /proc/self/uid_map
> > >                                       A had CAP_SETFCAP -> allowed
> > > 
> > > If A's namespace already maps host uid 0, at any uid, B can set
> > > security.capability on a file right away.  Either way uid 1000 can then
> > 
> > "Either way" here means whether it already maps host uid 0, or whether
> > it has no mappings yet?  I'd just drop 'Either way'.
> > 
> > > run that file with CAP_SYS_ADMIN, which the selftest at the end of this
> > > series shows on an unmodified kernel.
> > > 
> > > The check doesn't look at the joiner's uids, which it can change while
> > 
> > >From here until the 'Fix by', it is confusing whether any given statement
> > refers to the pre-patch or post-patch state.
> > 
> > > keeping its other capabilities, and CAP_SYS_PTRACE doesn't stand in for
> > 
> > Is this a reference to the next patch?  But that's a completely different
> > commit.
> > 
> > > CAP_SETFCAP.  What gets refused is a task without CAP_SETFCAP that has
> > > CAP_SYS_ADMIN over a namespace that maps the joiner's root user, or that
> > > has no uid_map yet while its parent maps that root user, so that it can
> > > still be mapped.  If that is uid 0 of the parent and the creator of the
> > > namespace didn't have CAP_SETFCAP, the join is let through: only a
> > > writer with CAP_SETFCAP in the parent could map it then.  Containers
> > > that don't map the joiner's root user, tasks with CAP_SETFCAP and
> > > unprivileged users are not affected.
> > > 
> > > Like verify_root_map(), the check is about uid 0 of the joiner's own
> > > namespace.  The root user of an ancestor that it maps at another uid,
> > > and a root user stored through an idmapped mount, are left to whoever
> > > set up that map or mount.
> > > 
> > > Fix by refusing setns() when the joiner doesn't have CAP_SETFCAP and
> > > tasks in the namespace can write file capabilities for the root user of
> > > the joiner's namespace.
> > > 
> > > Suggested-by: Serge Hallyn <serge@hallyn.com>
> > > Link: https://lore.kernel.org/all/fd159e68-c613-4c7d-bfba-8af0a3f3a96e@hallyn.com/
> > > Fixes: db2e718a4798 ("capabilities: require CAP_SETFCAP to map uid 0")
> > > Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> > 
> > The code looks good to me,
> > 
> > Reviewed-by: Serge Hallyn <serge@hallyn.com>

I've tested that unprivileged lxc still works with these two patches, so feel
free to add

Tested-by: Serge Hallyn <serge@hallyn.com>

to the first two as well.

-serge

  reply	other threads:[~2026-11-22 16:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 19:54 [PATCH v11 0/3] capabilities: close the ways around the CAP_SETFCAP rule for uid 0 Josef Bacik
2026-11-17 19:54 ` [PATCH v11 1/3] userns: don't let setns() lend CAP_SETFCAP Josef Bacik
2026-11-17 20:06   ` sashiko-bot
2026-11-20 17:22   ` Serge E. Hallyn
2026-11-20 17:34     ` Serge E. Hallyn
2026-11-22 16:14       ` Serge E. Hallyn [this message]
2026-11-17 19:54 ` [PATCH v11 2/3] capabilities: don't let ptrace borrow CAP_SETFCAP Josef Bacik
2026-11-17 20:13   ` sashiko-bot
2026-11-20 17:31   ` Serge E. Hallyn
2026-11-17 19:54 ` [PATCH v11 3/3] selftests/namespaces: test the CAP_SETFCAP rule for user namespaces Josef Bacik
2026-11-17 20:01   ` sashiko-bot
2026-11-20 10:11 ` [PATCH v11 0/3] capabilities: close the ways around the CAP_SETFCAP rule for uid 0 Christian Brauner
2026-11-20 16:51   ` Bradley Morgan

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=awMVA+9Q+7mF7naH@hallyn.com \
    --to=serge@hallyn.com \
    --cc=brads@mainlining.org \
    --cc=brauner@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=jarkko@kernel.org \
    --cc=jmorris@namei.org \
    --cc=josef@toxicpanda.com \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=morgan@kernel.org \
    --cc=paul@paul-moore.com \
    --cc=sergeh@kernel.org \
    --cc=shuah@kernel.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