Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
From: Christian Brauner
Date: Wed Nov 11 2026 - 10:20:47 EST
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)
* 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.
=> no parent user namespace needed for the single-nesting case.
So a container with CAP_NET_ADMIN lowers its mask before it spawns the
nested container => should cover your (3) case.
uAPI is a prctl modeled on the ambient capset:
* PR_CAP_USERNS with IS_SET, RAISE, LOWER and CLEAR_ALL
* lowering needs no_new_privs or CAP_SETPCAP
=> handles sendmail-style problem Serge raised on Jonathan's series.
* a new CapUns: line in /proc/<pid>/status
* new audit mask in AUDIT_CAPSET record
Raising needs the capability in the permitted set.
Fwiw, neither series handles ptrace. A task with a restricted mask can
attach a less restricted task of the same uid and then make it create
the namespace.
cap_ptrace_access_check() only compares permitted sets so far. So for
PTRACE_MODE_ATTACH the tracer must be able to get whatever the tracee
could get through user namespaces. A tracer that has CAP_SYS_PTRACE
in its own creds can still attach to anything. But the CAP_SYS_PTRACE
the caller gets over a user namespace just because it owns it must not
count. Otherwise a restricted task could attach to a less restricted
task inside a namespace it owns.
That gets rid of the sysctl, the clone3() field and the clone flags,
doesn't need a new capability bit, and nothing changes for anyone who
doesn't opt in, I think.
And that loopback thing should be its own series. Not as an nsfs ioctl
though. All nsfs ioctls only report namespace state and I'd like to keep
it that way.
Pipe this through an LLM and make sure it makes sense and covers all
holes.
Thoughts?
[1]: https://lore.kernel.org/all/20240609104355.442002-1-jcalmels@xxxxxxxx