Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback

From: Christian Brauner

Date: Wed Nov 18 2026 - 16:06:24 EST


On Wed, Nov 18, 2026 at 11:21:57AM +0100, Christian Brauner wrote:
> 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@xxxxxxxxxx> 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@xxxxxxxxxx> 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.

Forgot:

https://www.thkukuk.de/blog/no_new_privs/

has an overview of where we're currently at.

Some tools are in:

https://github.com/thkukuk/account-utils

and Thorsten also gave a talk at All Systems Go in September:

https://www.youtube.com/watch?v=MKG_WMAypDY