mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Andy Lutomirski <luto@amacapital.net>
Cc: "Hallgrimur H. Gunnarsson" <halg@google.com>,
	"Alexander Viro" <viro@zeniv.linux.org.uk>,
	"Paul Moore" <paul@paul-moore.com>,
	"Serge Hallyn" <sergeh@kernel.org>, "Kees Cook" <kees@kernel.org>,
	"David S . Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>, "Jan Kara" <jack@suse.cz>,
	"James Morris" <jmorris@namei.org>,
	"Simon Horman" <horms@kernel.org>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Jann Horn" <jannh@google.com>,
	"Günther Noack" <gnoack@google.com>,
	"KP Singh" <kpsingh@kernel.org>,
	"Jonathan Calmels" <jcalmels@3xx0.net>,
	"Casey Schaufler" <casey@schaufler-ca.com>,
	linux-fsdevel@vger.kernel.org,
	linux-security-module@vger.kernel.org, linux-api@vger.kernel.org,
	containers@lists.linux.dev, netdev@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
Date: Wed, 18 Nov 2026 11:21:57 +0100	[thread overview]
Message-ID: <20261118-stapeln-eckpunkte-lesbar-ee73537f474d@brauner> (raw)
In-Reply-To: <CALCETrWhuOnBy0N0KznmczD4S2XEK0fbr0C=1KFQqTnoTJbQbg@mail.gmail.com>

On Tue, Nov 17, 2026 at 09:37:19AM -0800, Andy Lutomirski wrote:
> On Tue, Nov 17, 2026 at 9:10 AM Christian Brauner <brauner@kernel.org> wrote:
> >
> > On Mon, Nov 16, 2026 at 09:15:18AM -0800, Andy Lutomirski wrote:
> > > On Wed, Nov 11, 2026 at 7:20 AM Christian Brauner <brauner@kernel.org> wrote:
> > > > * a task that setns()es in later gets
> > > >   ns->cap_bset & (cred->cap_userns | cred->cap_permitted)
> > >
> > > I'm not sure this is ideal.  If a task has cap_userns & CAP_NET_ADMIN,
> > > then there is no attack surface issue with allowing it to enter a
> > > namespace and be NET_ADMIN there even if the namespace itself has
> > > CAP_NET_ADMIN cleared from cap_bset.  But any exemption here would
> > > need to be a new API so that it isn't used by accident.
> > >
> > > I'm mostly saying this because container managers might want to
> > > restrict cap_userns within their containers but still have it
> > > themselves for management.  But maybe there isn't any need to enter
> > > the userns for this purpose.
> >
> > I don't think there is. A manager that holds the capabilities itself can
> > just do most things from the outside. I think it's nice that once you're
> > inside a namespace you're bound by its capabiltiy set. Otherwise the set
> > isn't a property of the namespace anymore. If someone comes up with a
> > real need to enter we can add an explicit opt-in later?
> 
> Fair enough.  Also you've written infinitely more nontrivial container
> managers than I have (I've written container managers, too, but
> they're all special-purpose things that don't do much in the way of
> actual managing).

So I think this is another instance where we're bitten by the complexity
of the whole namespace api. In a perfect world our answer would be "Yes,
the owner of the userns is definitely capable of performing all relevant
actions from outside the userns.". But we're actually not able to say
that because there's so many different ways how some <object> is set up
or configured for a container and nobody ever sat down and defined the
model how a container and it's various resoures are set up.

So once again, here we are guessing our way to a decent decision...
Thanks for helping with thinking this through.

> > > > * Root in a container has caps as well so for containers the exemption
> > > >   would be wrong.
> > > >
> > > >   So here we need a a lockable SECURE_NO_USERNS_CAP_RAISE bit thingy.
> > > >   This turns off the exemption and prevents raising the mask.
> > > >
> > > >   Docker lowers the mask, sets and locks the bit, and
> > > >   unshare(CLONE_NEWUSER) in the container doesn't hand out CAP_NET_ADMIN
> > > >   anymore.
> > >
> > > Can you clarify this part a bit?  I'm not seeing why Docker should be
> > > special.  Shouldn't the inside of a Docker container work as much like
> > > a normal non-container system as possible?  What's the use case?
> >
> > I picked Docker because you brought it up, and your goal of allowing
> > user namespaces even in Docker is kinda the use case. Docker can only
> > drop the CLONE_NEWUSER block from its seccomp profile if nested user
> > namespaces can't get more caps than root/Docker wants to give them.
> >
> > But the bit isn't at all Docker specific. Any privileged task that wants the
> > mask to apply to itself would benefit. With just the exemption this wouldn't be
> > possible:
> >
> > (1) A runtime that holds full capabilities gives a
> >     user namespace it creates all bits.
> >     It can just set the bit before creating it.
> >
> > (2) In a container without a user namespace container root has host-level
> >     capabilities. Any user namespace it creates gets them through this
> >     exemption thing. So it can also add them back to its mask. And the mask is
> >     inherited. So every process it starts can then create user namespaces with
> >     them.
> >
> >     by raising the bit we stop both. The locked bit keeps container root which
> >     also has CAP_SETPCAP from clearing it.
> >
> 
> I'm still not 100% sure I'm following this.  By "exemption" are you
> talking about the cred->cap_premitted term here?

Yes.

> ns->cap_bset = parent->cap_bset &
>                        (cred->cap_userns | cred->cap_permitted);
> 
> (As as aside, as formulated, the parent->cap_bset term should be
> irrelevant, no?  cred always refers to a task in parent, and this

(
I don't think it i.s
cap_userns is full by default. Entering a namespace doesn't change it.
A task inside a namespace with a reduced cap_bset still has the full
mask. Without the term a child namespace gets more caps than its parent
had.

cap_permitted can grow through a setuid-root exec in the parent
namespace. And that exec is bounded by the tasks bounding set and not
by the namespace bounding set.

So that term ensures that the namespace bounding set shrinks
monotonically by construction.

I think it would only be redundant if exec would be clamped by cap_bset.
I'm not sure if the patchset does this.

/me looks...

Ah, ok... this patch series already clamps exec to the namespace
bounding set. So yes, you're right.
)

> whole thing is defined so that cap_userns and cap_permitted are always
> subsets of parent's cap_bset, right?)
> 
> I think I agree that there needs to be a way to turn the cap_permitted
> thing on and off (and I'm also not sure whether cap_permitted is
> better than cap_effective), but I'm not convinced that an inheritable

The effective set can be raised from the permitted set at will. So I
think permitted is just more correct.

> and lockable bit is necessary or wise.
> 
> How about changing the rule to:
> 
> child->cap_bset = parent->cap_bset & soft_cap_userns &
> (cred->cap_userns | cred->cap_permitted)
> 
> a) (ugly but easier) A non-inheritable prctl-controlled mask
> soft_cap_userns, changing the rule to parent->cap_bset &
> soft_cap_userns & (cred->cap_userns | cred->cap_permitted).
> soft_cap_userns would be reset to all ones on on fork and exec to
> avoid creating new inheritable security-relevant state.

So both let the creator pick. But the bit is for the creator when it
wants to self-restrict: container-root without a user namespace.

It's the same reason that securebits and no_new_privs are inheritable
and lockable. Afaict, a) is reset on exec so it doesn't control the next
exec. b) covers namespace creation but not unsharing a user namespace.

> b) A whole new create-a-namespace API where the caller chooses
> soft_cap_userns at the time they create the namespace.
> 
> > On the host none of that matters as the mask is root's own policy there.
> 
> I'm still not seeing how there's a difference between host vs
> init-userns-container vs separate-userns-container.  After all, in

I think the difference is simply whether the restricting task holds the
capabilities itself. Unprivileged users on the host don't and so they're
not subject to the exemption. The bit is for that case where the task
holds the caps.

But ok, if we really don't want to bother with container without user
namespaces the bit vs a) thing can also go into a follow-up series.

> Unfortunately we don't live in this world, and I'm not convinced that
> can credibly even approximate it, because people really like their
> setuid programs working inside a userns.  It still bugs me that we're
> designing permission systems designed to work in the POSIX model that
> I think we all kind of agree is fundamentally rather messed up.

I don't think all hope is lost. We have slowly been pushing in this
direction. systemd allows to set NoNewPrivileges= in it's global config
so it's possible to enable it for the whole system easily.

There's been a ton of work to get rid of classic setuid-exec stuff:

* run0 instead of sudo (with sudo compat), and systemd-ptybrokerd for
  interactive shells
* nsresourced for user namespaces with delegated ranges, mountfsd for
  unprivileged image mounts
* outside of systemd: pwaccessd/pwupdd/newidmapd replacing unix_chkpwd,
  passwd and newuidmap/newgidmap, polkit without a setuid helper, and
  su/sudo/pkexec wrappers on top of ptybrokerd

But yes, containers are the sore spot. no_new_privs inherited from PID
1 breaks setuid inside of containers.

My idea has been to make this dynamic:

* deny privilege gain on exec in the initial user namespace and allow it
  in nested ones. I mused about this in
  https://github.com/uapi-group/kernel-features/pull/38

Also, since v7.1 there's CLONE_NNP to spawn a child without no_new_privs
set.

  reply	other threads:[~2026-11-18 10:22 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 22:16 Hallgrimur H. Gunnarsson
2026-10-28 22:16 ` [PATCH 1/8] net: introduce CLONE_NEWNET_LOOPBACK to auto-enable loopback Hallgrimur H. Gunnarsson
2026-10-28 22:16 ` [PATCH 2/8] userns: introduce capability bounding set for user namespaces Hallgrimur H. Gunnarsson
2026-10-28 22:17 ` [PATCH 3/8] userns: allow restricting capability bounding set via clone3() Hallgrimur H. Gunnarsson
2026-10-28 22:17 ` [PATCH 4/8] nsfs: add NS_USER_GET_INFO ioctl to inspect user namespace capabilities Hallgrimur H. Gunnarsson
2026-10-28 22:17 ` [PATCH 5/8] selftests/net: add test suite for CLONE_NEWNET_LOOPBACK Hallgrimur H. Gunnarsson
2026-10-28 22:17 ` [PATCH 6/8] selftests/capabilities: tests for user namespace capability bounding set Hallgrimur H. Gunnarsson
2026-10-28 22:17 ` [PATCH 7/8] selftests/capabilities: add clone3() tests for CLONE_NEWUSER_BSET Hallgrimur H. Gunnarsson
2026-10-28 22:17 ` [PATCH 8/8] selftests/nsfs: add tests for NS_USER_GET_INFO ioctl Hallgrimur H. Gunnarsson
2026-10-28 22:56 ` [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback Andy Lutomirski
2026-10-29 10:44   ` Alexey Gladkov
2026-10-29 12:11   ` Hallgrimur H. Gunnarsson
2026-11-03 18:37     ` Andy Lutomirski
2026-11-04 11:30       ` Hallgrimur H. Gunnarsson
2026-11-05 16:48         ` Andy Lutomirski
2026-11-06 13:13   ` Christian Brauner
2026-11-07 18:47     ` Andy Lutomirski
2026-11-10 15:31       ` Hallgrimur H. Gunnarsson
2026-11-11 15:20         ` Christian Brauner
2026-11-16 16:43           ` Hallgrimur H. Gunnarsson
2026-11-17 16:49             ` Christian Brauner
2026-11-16 17:15           ` Andy Lutomirski
2026-11-17 17:10             ` Christian Brauner
2026-11-17 17:37               ` Andy Lutomirski
2026-11-18 10:21                 ` Christian Brauner [this message]
2026-11-03 12:37 ` Serge E. Hallyn
2026-11-05 15:37   ` Hallgrimur H. Gunnarsson
2026-11-05 16:59     ` Andy Lutomirski
2026-11-06 10:12   ` Christian Brauner
2026-11-04 14:09 ` Josef Bacik
2026-11-07 12:43 ` Mickaël Salaün

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=20261118-stapeln-eckpunkte-lesbar-ee73537f474d@brauner \
    --to=brauner@kernel.org \
    --cc=casey@schaufler-ca.com \
    --cc=containers@lists.linux.dev \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gnoack@google.com \
    --cc=halg@google.com \
    --cc=horms@kernel.org \
    --cc=jack@suse.cz \
    --cc=jannh@google.com \
    --cc=jcalmels@3xx0.net \
    --cc=jmorris@namei.org \
    --cc=kees@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-doc@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=luto@amacapital.net \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=rdunlap@infradead.org \
    --cc=sergeh@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®