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

From: Andy Lutomirski

Date: Mon Nov 16 2026 - 12:15:35 EST


On Wed, Nov 11, 2026 at 7:20 AM Christian Brauner <brauner@xxxxxxxxxx> wrote:
>
> On Tue, Nov 10, 2026 at 03:31:33PM +0000, Hallgrimur H. Gunnarsson wrote:
> > If we drop CLONE_NEWNET_LOOPBACK / UNSHARE_NEWNET_LOOPBACK from this
> > series and handle loopback separately, do you think the per-userns
> > bounding set is a reasonable approach for withholding capabilities
> > (e.g. CAP_NET_ADMIN and CAP_NET_RAW) from unprivileged userns, or
> > would you prefer a different mechanism?
>
> Seems ok to me.
>
> > To address the concern about the number of moving parts, I am also
> > happy to simplify the control interfaces. If we decide a per-task
> > securebit is the cleanest way to drive this configuration for both
> > single-deep and nested cases, we could focus on that and drop the
> > clone3() and sysctl from this series entirely, or only expose whatever
> > subset you prefer.
>
> Just a note on the essay I cut off. I really object to any arguments
> that amount to "it's too much work" propped up by a few thin arguments
> sprinkled in such as rtnetlink.
>
> I also reject any arguments that amount to underscoping and overscoping
> of the new capability. The scope is clear: empty netns with brought up
> loop device.
>
> I'm 180 patches deep into fixing procfs and 41 patches deep into
> preventing loop devices from abuse. Either we do the work and get
> something better or we do the same thing we've always done and hope we
> end up happily ever after.
>
> But again, I'm more focussed on cells so here's what I find acceptable:
>
> I'd rather go back to what Jonathan proposed in 2024 (cf. [1]). A
> per-task userns capability mask. Serge acked the core of it back
> then. It's at least generic and not just the single securebit capability
> thing. And we'd burn a new bit for every capability that turns out to be
> a problem later.
>
> Jonathan's version had holes though. The restriction only lived in the
> task's creds so the owner rule and setns() blew this up. So it needs to
> be combined with your per-namespace set. Roughly:
>
> * every task carries a mask, cred->cap_userns, full by default
> fork, exec, setuid and entering a namespace never change it
> * a new user namespace records
>
> ns->cap_bset = parent->cap_bset &
> (cred->cap_userns | cred->cap_permitted);
>
> once at creation and never changes it again => it's monotonic downwards
> * the creator gets ns->cap_bset instead of CAP_FULL_SET
> * 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.

> * the owner rule in cap_capable_helper() grants exactly what entering
> would and otherwise falls through to what the owner has
>
> So caps a task actually has always count as allowed
> => should check Andy's "only restrict creators that don't have
> CAP_NET_ADMIN themselves" per capability.
>
> This amounts to a host-wide default without a sysctl.
> PID 1 drops CAP_NET_ADMIN and CAP_NET_RAW from its own mask at boot
> and everything inherits that.
>
> Root, sudo and setuid-root binaries have those capabilities so
> nothing changes for them. A regular user doesn't and so their user
> namespaces come without CAP_NET_ADMIN and CAP_NET_RAW.
>
> This also covers newgrp, su and sudo -u shells which is where
> resetting the mask on setuid exec (Which was raised by Serge in the
> other thread.).
>
> * 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?


In any event, the ptrace access checks also need to be updated. If
we're adding cap_userns, then one should not be able to
PTRACE_MODE_ATTACH a task with higher cap_userns.