🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
16 messages
16 total messages Started by Andy Lutomirski Wed, 28 Oct 2026 22:56
Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
#8387
Author: Andy Lutomirski
Date: Wed, 28 Oct 2026 22:56
83 lines
16821 bytes
On Wed, Oct 28, 2026 at 3:18 PM Hallgrimur H. Gunnarsson
<halg@google.com> wrote:
>
> When an unprivileged process creates a new user namespace, it is granted
> a full set of capabilities (CAP_FULL_SET) scoped to that namespace.
> While these capabilities are isolated to the namespace, they allow
> unprivileged local users to reach deep kernel subsystems (most notably
> networking configuration and raw sockets via CAP_NET_ADMIN and
> CAP_NET_RAW) that historically assumed a trusted caller and have
> accounted for a large share of local privilege escalation
> vulnerabilities.
>
> Many workloads and sandboxes use unprivileged user namespaces strictly
> for basic UID/GID, mount, PID, or network isolation and never need
> high-risk capabilities like CAP_NET_ADMIN or CAP_NET_RAW. Likewise,
> system administrators often want a host-wide policy ceiling restricting
> which capabilities unprivileged user namespaces may acquire, without
> disabling unprivileged user namespaces altogether.
>
> Prior work by Jonathan Calmels [1] proposed addressing this via a sixth
> per-thread capability set (cap_userns) alongside a global sysctl mask.
> During that discussion [1, 2], feedback (e.g. from Casey Schaufler)
> suggested that rather than adding another per-thread capability set and
> prctl() interface, capability restrictions could be integrated directly
> into struct user_namespace and configured via clone3(). At the same
> time, as noted in [1], a clone3() flag alone is not sufficient for
> administrators who need to enforce a host-wide ceiling on unprivileged
> user namespaces without modifying every userspace callsite.
>
> This series combines both pieces of feedback: it embeds a capability
> bounding set (cap_bset) directly into struct user_namespace, reusing
> the existing task cap_bset, cap_permitted, and cap_effective sets on
> namespace entry, and provides both a system-wide sysctl ceiling for
> unprivileged user namespaces and a CLONE_NEWUSER_BSET flag for
> voluntary per-namespace restriction via clone3().

Why should the task's cap masks affect this?  *Maybe* cap_bset makes
sense, but I'm struggling a bit to see why cap_permitted and
cap_effective should matter.

Also, I think that Docker in non-userns mode restricts cap_bset, and
the purpose of that restriction is rather at odds with interpreting it
as a restriction on newly created user namespaces for purposes of
vulnerability mitigation.

>
> In addition, because restricting CAP_NET_ADMIN at user namespace
> creation time prevents userspace from bringing up the loopback
> interface in new network namespaces, the series first introduces
> an opt-in flag to automatically enable loopback on network namespace
> creation:
>
> 1. Opt-in loopback activation on netns creation (Patch 1)
>
>   New network namespaces start with the loopback interface (lo) DOWN by
>   default, requiring CAP_NET_ADMIN over the owning user namespace to
>   bring it up. To block external network access while preserving
>   localhost networking, sandboxes commonly create an isolated network
>   namespace with only the loopback interface enabled.
>

The whole unshare/clone flag situation is getting out of hand, IMO.
And this new thing makes logical sense but is really about reducing
exposure.

Perhaps we should instead have a small list associated with a userns
(extensible in the future) of things that the ns's admin (i.e. whoever
has CAP_SYS_ADMIN relative to the ns) may do.  That list could
include:

- Create loopback with sensible defaults for ipv4 and/or ipv6 (i see
no obvious reason to separate them)
- Create tun/tap interfaces in that ns (and attach them, etc)

And add a very simple new API to do these things.  Actually, the
tun/tap could just use the normal mechanism.

Thoughts?

-- 
Andy Lutomirski
AMA Capital Management, LLC
Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
#8531
Author: Alexey Gladkov
Date: Thu, 29 Oct 2026 10:44
89 lines
12917 bytes
On Wed, Oct 28, 2026 at 03:56:11PM -0700, Andy Lutomirski wrote:
> On Wed, Oct 28, 2026 at 3:18 PM Hallgrimur H. Gunnarsson
> <halg@google.com> wrote:
> >
> > When an unprivileged process creates a new user namespace, it is granted
> > a full set of capabilities (CAP_FULL_SET) scoped to that namespace.
> > While these capabilities are isolated to the namespace, they allow
> > unprivileged local users to reach deep kernel subsystems (most notably
> > networking configuration and raw sockets via CAP_NET_ADMIN and
> > CAP_NET_RAW) that historically assumed a trusted caller and have
> > accounted for a large share of local privilege escalation
> > vulnerabilities.
> >
> > Many workloads and sandboxes use unprivileged user namespaces strictly
> > for basic UID/GID, mount, PID, or network isolation and never need
> > high-risk capabilities like CAP_NET_ADMIN or CAP_NET_RAW. Likewise,
> > system administrators often want a host-wide policy ceiling restricting
> > which capabilities unprivileged user namespaces may acquire, without
> > disabling unprivileged user namespaces altogether.
> >
> > Prior work by Jonathan Calmels [1] proposed addressing this via a sixth
> > per-thread capability set (cap_userns) alongside a global sysctl mask.
> > During that discussion [1, 2], feedback (e.g. from Casey Schaufler)
> > suggested that rather than adding another per-thread capability set and
> > prctl() interface, capability restrictions could be integrated directly
> > into struct user_namespace and configured via clone3(). At the same
> > time, as noted in [1], a clone3() flag alone is not sufficient for
> > administrators who need to enforce a host-wide ceiling on unprivileged
> > user namespaces without modifying every userspace callsite.
> >
> > This series combines both pieces of feedback: it embeds a capability
> > bounding set (cap_bset) directly into struct user_namespace, reusing
> > the existing task cap_bset, cap_permitted, and cap_effective sets on
> > namespace entry, and provides both a system-wide sysctl ceiling for
> > unprivileged user namespaces and a CLONE_NEWUSER_BSET flag for
> > voluntary per-namespace restriction via clone3().
> 
> Why should the task's cap masks affect this?  *Maybe* cap_bset makes
> sense, but I'm struggling a bit to see why cap_permitted and
> cap_effective should matter.
> 
> Also, I think that Docker in non-userns mode restricts cap_bset, and
> the purpose of that restriction is rather at odds with interpreting it
> as a restriction on newly created user namespaces for purposes of
> vulnerability mitigation.
> 
> >
> > In addition, because restricting CAP_NET_ADMIN at user namespace
> > creation time prevents userspace from bringing up the loopback
> > interface in new network namespaces, the series first introduces
> > an opt-in flag to automatically enable loopback on network namespace
> > creation:
> >
> > 1. Opt-in loopback activation on netns creation (Patch 1)
> >
> >   New network namespaces start with the loopback interface (lo) DOWN by
> >   default, requiring CAP_NET_ADMIN over the owning user namespace to
> >   bring it up. To block external network access while preserving
> >   localhost networking, sandboxes commonly create an isolated network
> >   namespace with only the loopback interface enabled.
> >
> 
> The whole unshare/clone flag situation is getting out of hand, IMO.
> And this new thing makes logical sense but is really about reducing
> exposure.
> 
> Perhaps we should instead have a small list associated with a userns
> (extensible in the future) of things that the ns's admin (i.e. whoever
> has CAP_SYS_ADMIN relative to the ns) may do.  That list could
> include:
> 
> - Create loopback with sensible defaults for ipv4 and/or ipv6 (i see
> no obvious reason to separate them)
> - Create tun/tap interfaces in that ns (and attach them, etc)
> 
> And add a very simple new API to do these things.  Actually, the
> tun/tap could just use the normal mechanism.
> 
> Thoughts?

I think that's an interesting idea. I also think the whole flag issue is
moving in the wrong direction.

Are you thinking of something like `struct open_how` in openat2,
or something else?

-- 
Rgrds, legion
Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
#10579
Author: Andy Lutomirski
Date: Tue, 03 Nov 2026 18:37
46 lines
14930 bytes
On Thu, Oct 29, 2026 at 5:11 AM Hallgrimur H. Gunnarsson
<halg@google.com> wrote:
>
> On Wed, Oct 28, 2026 at 03:56:11PM -0700, Andy Lutomirski wrote:

> >
> > Why should the task's cap masks affect this?  *Maybe* cap_bset makes
> > sense, but I'm struggling a bit to see why cap_permitted and
> > cap_effective should matter.
>
> Sorry, the phrasing here may have been misleading. Just to clarify:
> none of the creating task's capability sets (cap_bset, cap_permitted
> or cap_effective) are used to restrict the new user namespace.
>
> When I wrote "reusing the existing task cap_bset, cap_permitted and
> cap_effective sets on namespace entry", I was contrasting this with
> the prior series from 2024 [1], which proposed adding a 6th per-thread
> capability set to struct cred.
>
> In this series, when a task creates or enters a user namespace, we
> simply initialize its new cred->cap_{bset,permitted,effective} in
> that namespace to user_ns->cap_bset instead of CAP_FULL_SET.
>

Okay, this makes *more* sense, but I think it's too weak.

I have a sort-of goal of having the creation of unprivileged
namespaces be allowed in most contexts by default, *even in Docker*
(which would involve the Docker team changing their default seccomp
rules, but that bridge can be crossed later).  (In furtherance of this
goal, I fixed an ancient bug in newuidmap that gets us quite a bit
closer a couple weeks ago.)

But tying this mitigation to a parent userns means that it's
completely unusable in the single-deep case.

I do have a question about this whole scheme, though: are we talking
*just* about CAP_NET_ADMIN?  That is, is there any other bit that has
anywhere near enough security relevance to make this kind of thing
worthwhile?  Because if it's really just a single bit control, maybe
we can come up with a nicer scheme.

-- 
Andy Lutomirski
AMA Capital Management, LLC
Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
#11806
Author: Andy Lutomirski
Date: Thu, 05 Nov 2026 16:48
126 lines
17126 bytes
On Wed, Nov 4, 2026 at 3:30 AM Hallgrimur H. Gunnarsson <halg@google.com> wrote:
>
> On Tue, Nov 03, 2026 at 10:37:48AM -0800, Andy Lutomirski wrote:
> > On Thu, Oct 29, 2026 at 5:11 AM Hallgrimur H. Gunnarsson
> > <halg@google.com> wrote:
> > >
> > > On Wed, Oct 28, 2026 at 03:56:11PM -0700, Andy Lutomirski wrote:
> >
> > > >
> > > > Why should the task's cap masks affect this?  *Maybe* cap_bset makes
> > > > sense, but I'm struggling a bit to see why cap_permitted and
> > > > cap_effective should matter.
> > >
> > > Sorry, the phrasing here may have been misleading. Just to clarify:
> > > none of the creating task's capability sets (cap_bset, cap_permitted
> > > or cap_effective) are used to restrict the new user namespace.
> > >
> > > When I wrote "reusing the existing task cap_bset, cap_permitted and
> > > cap_effective sets on namespace entry", I was contrasting this with
> > > the prior series from 2024 [1], which proposed adding a 6th per-thread
> > > capability set to struct cred.
> > >
> > > In this series, when a task creates or enters a user namespace, we
> > > simply initialize its new cred->cap_{bset,permitted,effective} in
> > > that namespace to user_ns->cap_bset instead of CAP_FULL_SET.
> > >
> >
> > Okay, this makes *more* sense, but I think it's too weak.
> >
> > I have a sort-of goal of having the creation of unprivileged
> > namespaces be allowed in most contexts by default, *even in Docker*
> > (which would involve the Docker team changing their default seccomp
> > rules, but that bridge can be crossed later).  (In furtherance of this
> > goal, I fixed an ancient bug in newuidmap that gets us quite a bit
> > closer a couple weeks ago.)
> >
> > But tying this mitigation to a parent userns means that it's
> > completely unusable in the single-deep case.
>
> To clarify, this mitigation isn't exclusively tied to the parent userns.
> If a system administrator wants a host-wide policy, like trimming
> CAP_NET_ADMIN for all unprivileged user namespaces, including
> single-deep Docker containers, then the host-wide sysctl handles this
> seamlessly. Any unprivileged process in init_user_ns calling CLONE_NEWUSER
> is subjected to the sysctl ceiling, effectively stripping CAP_NET_ADMIN
> upon creation.

Seems reasonable, but see below.

>
> Where the single-deep case falls short in this series is per-container
> granularity. For flexible configuration on a per-container basis, this
> patch series assumes that containers run in their own user namespace,
> allowing the runtime to bound capabilities at creation time via clone3()
> and have that bound persist down the namespace hierarchy across any nested
> userns creation.

There are plenty of cases of *privileged* user namespaces (i.e.
created by privileged users) that would nonetheless want this.  Or
unprivileged user namespaces on systems that will not have this
restriction set that still want to apply it in their own container.



>
> If a container runs in init_user_ns (as in standard Docker) and we want
> to restrict userns capabilities for that specific container without
> relying on a host-wide sysctl, then you are exactly right. We would need
> some kind of cred-based mechanism to pre-configure a restriction for any
> future CLONE_NEWUSER calls within that container.
>
> > I do have a question about this whole scheme, though: are we talking
> > *just* about CAP_NET_ADMIN?  That is, is there any other bit that has
> > anywhere near enough security relevance to make this kind of thing
> > worthwhile?  Because if it's really just a single bit control, maybe
> > we can come up with a nicer scheme.
>
> Yes, primarily CAP_NET_ADMIN, and to a lesser extent CAP_NET_RAW.
>
> If we look at submissions to Google's kernelCTF VRP [1], 90% of the
> exploit submissions in 2026 require CAP_NET_ADMIN (and about 70%
> across all submissions since the program started in 2023).
>
> Restricting these network capabilities when they are not strictly needed
> (e.g. for sandboxing) is the primary motivation behind the series.
> However, I wrote the userns capability bounding as a generic mask so it
> could restrict arbitrary capabilities down the hierarchy, but if the
> preference is to narrow the scope more specifically to trimming
> CAP_NET_ADMIN and CAP_NET_RAW, that's completely fine by me.
>
> If we go that route and want to support the single-deep Docker case, a
> per-task inheritable securebit might be one way to do it, e.g.
> SECBIT_NO_USERNS_NET and SECBIT_NO_USERNS_NET_LOCKED. Docker could then
> set and lock that bit on a container in init_user_ns without needing a
> parent userns.

This seems perhaps better.  But maybe a bit that applies the
restriction to a userns created by someone who doesn't have
CAP_NET_ADMIN in their own userns?

IMO what we really want is a generic mechanism for sysctl-like
settings that are scoped to a userns.  And we would want the API not
to be filesystem-based (or at least not require *mounting* a
filesystem) because then we would just make everything messier.  This
would solve many problems.

>
> On userns creation, create_user_ns() could record this restriction on
> struct user_namespace. That could either feed into the userns capability
> bounding set proposed in this series (clearing CAP_NET_ADMIN and
> CAP_NET_RAW from user_ns->cap_bset when the bit is set on the creator),
> or be stored as a single boolean in struct user_namespace if we want to
> keep the mechanism minimal and drop the generic capability mask UAPI.
> In the latter case, we would still need to replicate some of the
> userns capability bounding functionality, e.g. strip CAP_NET_ADMIN and
> CAP_NET_RAW in set_cred_user_ns() on namespace entry, and bound the
> parent-owner check in cap_capable_helper().
>
> [1] https://github.com/google/security-research/tree/master/pocs/linux/kernelctf
Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
#12186
Author: Christian Brauner
Date: Fri, 06 Nov 2026 13:13
41 lines
10462 bytes
On Wed, Oct 28, 2026 at 03:56:11PM -0700, Andy Lutomirski wrote:
> The whole unshare/clone flag situation is getting out of hand, IMO.
> And this new thing makes logical sense but is really about reducing
> exposure.
> 
> Perhaps we should instead have a small list associated with a userns
> (extensible in the future) of things that the ns's admin (i.e. whoever
> has CAP_SYS_ADMIN relative to the ns) may do.  That list could
> include:
> 
> - Create loopback with sensible defaults for ipv4 and/or ipv6 (i see
> no obvious reason to separate them)
> - Create tun/tap interfaces in that ns (and attach them, etc)
> 
> And add a very simple new API to do these things.  Actually, the

We've had this idea in the past and I think it is reasonable. I had
always thought that we should expose a system call to create empty
namespaces ot any type. Usually I'd be excited about that but I think
that point is a bit moot and I'd really like see whether we can turn
cells (or whatever other name) into a first class api.

The problem I have with the patchset as written is that adds a lot of
moving parts. And yes, I find the CLONE_* and UNSHARE_* flags plus
sysctl to be suboptimal as well.

So the TL;DR is that CAP_NET_ADMIN + userns =
CAP_NET_PRIVILEGE_ESCALATION 10+ years later. And this patchset wants to
put it back on a leash.

So why isn't an aggressively stupid solution to this problem to split a
new capability out of CAP_NET_ADMIN so it covers the absolute minimal
set of things that should be allowed instead of doing effectively the
same thing but split over multiple apis?

Anything that is reasonably advanced should not be the kernel's
responsibility to delegate. I really think the old privilege model where
the kernel grants control over a whole subsystem is inherently flawed
and is much better replaced if you have the means to let userspace
services grant and delegate resources.
Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
#12547
Author: Andy Lutomirski
Date: Sat, 07 Nov 2026 18:47
60 lines
13719 bytes
On Fri, Nov 6, 2026 at 5:13 AM Christian Brauner <brauner@kernel.org> wrote:
>
> On Wed, Oct 28, 2026 at 03:56:11PM -0700, Andy Lutomirski wrote:
> > The whole unshare/clone flag situation is getting out of hand, IMO.
> > And this new thing makes logical sense but is really about reducing
> > exposure.
> >
> > Perhaps we should instead have a small list associated with a userns
> > (extensible in the future) of things that the ns's admin (i.e. whoever
> > has CAP_SYS_ADMIN relative to the ns) may do.  That list could
> > include:
> >
> > - Create loopback with sensible defaults for ipv4 and/or ipv6 (i see
> > no obvious reason to separate them)
> > - Create tun/tap interfaces in that ns (and attach them, etc)
> >
> > And add a very simple new API to do these things.  Actually, the
>
> We've had this idea in the past and I think it is reasonable. I had
> always thought that we should expose a system call to create empty
> namespaces ot any type. Usually I'd be excited about that but I think
> that point is a bit moot and I'd really like see whether we can turn
> cells (or whatever other name) into a first class api.
>
> The problem I have with the patchset as written is that adds a lot of
> moving parts. And yes, I find the CLONE_* and UNSHARE_* flags plus
> sysctl to be suboptimal as well.
>
> So the TL;DR is that CAP_NET_ADMIN + userns =
> CAP_NET_PRIVILEGE_ESCALATION 10+ years later. And this patchset wants to
> put it back on a leash.
>
> So why isn't an aggressively stupid solution to this problem to split a
> new capability out of CAP_NET_ADMIN so it covers the absolute minimal
> set of things that should be allowed instead of doing effectively the
> same thing but split over multiple apis?

Because we don't actually have a clean way to make a list of
privileges that are, in theory, harmless but are hazardous from an
attack surface perspective and assign them only to tasks that ought to
have them.

But maybe we should invent such a thing.  It would be very, very nice.

Other than that, I agree with you.

>
> Anything that is reasonably advanced should not be the kernel's
> responsibility to delegate. I really think the old privilege model where
> the kernel grants control over a whole subsystem is inherently flawed
> and is much better replaced if you have the means to let userspace
> services grant and delegate resources.



-- 
Andy Lutomirski
AMA Capital Management, LLC
Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
#14594
Author: Christian Brauner
Date: Wed, 11 Nov 2026 15:20
124 lines
13919 bytes
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@3xx0.net
Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
#17362
Author: Andy Lutomirski
Date: Mon, 16 Nov 2026 17:15
106 lines
18066 bytes
On Wed, Nov 11, 2026 at 7:20 AM Christian Brauner <brauner@kernel.org> 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.
Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
#17997
Author: Christian Brauner
Date: Tue, 17 Nov 2026 16:49
16 lines
9406 bytes
On Mon, Nov 16, 2026 at 04:43:05PM +0000, Hallgrimur H. Gunnarsson wrote:
> Quick question on AUDIT_CAPSET: today it's only emitted on capset() and
> only logs capability sets that capset() can modify (explicitly or
> implicitly like cap_ambient). It does not include cap_bset which is
> modified via prctl(). Since capset() never modifies cap_userns either,
> does it make sense to treat it like cap_bset and leave it out of
> AUDIT_CAPSET, relying on prctl auditing instead?

Fine by me as well.

> Thanks for the feedback and the detailed proposal. It looks good to me
> and nicely ties everything together. I'll prepare a V2 for review based
> on this hybrid design.

Sounds good.
Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
#18002
Author: Christian Brauner
Date: Tue, 17 Nov 2026 17:10
66 lines
11981 bytes
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?

> > * 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.

On the host none of that matters as the mask is root's own policy there.

> 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.

Yeah, I mentioned that in my reply earlier.
Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
#18021
Author: Andy Lutomirski
Date: Tue, 17 Nov 2026 17:37
151 lines
20034 bytes
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).

>
> > > * 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?

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
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
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.

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
*any* of these contexts, the configuration *of the host or inside the
container* might want to restrict cap_userns for unprivileged users or
for everyone, which it can do with whatever API we add to do this.
And some container manager might run with CAP_NET_ADMIN in such a
context, and it might want to create its own container that has
CAP_NET_ADMIN removed from cap_bset.   But I might just be being dense
here or I might be misunderstanding you.



There is one thing that continues to bother me about all of this.  In
a sane world where privilege elevation on exec was simply not a thing
(no_new_privs = true always, nosuid always, no file caps, etc), then
cap_bset is kind of irrelevant, right?  A task either does or does not
have NET_ADMIN, and it either does or does not have the ability to
create *a task in a new userns, including itself, with NET_ADMIN*.
Since our API is based on creating/entering a userns as opposed to
spawning tasks into a userns, the rule should be, upon entering a
userns:

    cap_permitted = cap_userns

or something to that effect.  Or maybe:

    cap_permitted = ns_enter_requested_caps & cap_userns

and cap_effective and ambient get clamped to cap_permitted.

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.

>
> > 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.
>
> Yeah, I mentioned that in my reply earlier.
Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
#18443
Author: Christian Brauner
Date: Wed, 18 Nov 2026 10:21
190 lines
17712 bytes
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.
Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
#18763
Author: Christian Brauner
Date: Wed, 18 Nov 2026 21:06
205 lines
18515 bytes
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@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.

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
Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
#18764
Author: Andy Lutomirski
Date: Wed, 18 Nov 2026 21:12
272 lines
24797 bytes
On Wed, Nov 18, 2026 at 1:06 PM Christian Brauner <brauner@kernel.org> wrote:
>
> 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@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.
>
> Forgot:
>
> https://www.thkukuk.de/blog/no_new_privs/
>
> has an overview of where we're currently at.

Nice!

I commented in the uapi-group issue:

I think there may be a rather more direct solution to this problem. I
seem to recall advocating for clearing no_new_privs when entering a
userns way back when, and IIRC I dropped this as part of the extensive
negotiation to get NNP into the kernel in the first place. (I think
dropping it was probably the right decision to keep the final patch
simple.)

But I think I would still advocate for an option to let clone, unshare
and setns callers turn no_new_privs off. The logic is that, if you own
a userns, you already have all capabilities in it. If you enter it,
you get to keep those by having them raised in cap_permitted. Being
able to clear NNP and thus drop and subsequently regain them does not
let you do anything you couldn’t already do.

An LSM hook for this would be needed because this argument does not
apply to non-namespace-scoped LSM-based privileges. But the LSM hook
would just be a "may this caller enter this userns and clear
no_new_privs while doing so" query. In the absence of LSMs, the
operation would be allowed.

This would allow a fully no_new_privs host to run an ordinary
container that runs, in the ordinary way, without no_new_privs, and
without hitting any new LSM calls after it's started.

The API could be as simple as a CLONE_CLEAR_NNP bit.


-- 
Andy Lutomirski
AMA Capital Management, LLC
Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
#18767
Author: Christian Brauner
Date: Wed, 18 Nov 2026 21:37
236 lines
21034 bytes
On Wed, Nov 18, 2026 at 01:12:45PM -0800, Andy Lutomirski wrote:
> On Wed, Nov 18, 2026 at 1:06 PM Christian Brauner <brauner@kernel.org> wrote:
> >
> > 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@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.
> >
> > Forgot:
> >
> > https://www.thkukuk.de/blog/no_new_privs/
> >
> > has an overview of where we're currently at.
> 
> Nice!
> 
> I commented in the uapi-group issue:
> 
> I think there may be a rather more direct solution to this problem. I
> seem to recall advocating for clearing no_new_privs when entering a
> userns way back when, and IIRC I dropped this as part of the extensive
> negotiation to get NNP into the kernel in the first place. (I think
> dropping it was probably the right decision to keep the final patch
> simple.)
> 
> But I think I would still advocate for an option to let clone, unshare
> and setns callers turn no_new_privs off. The logic is that, if you own
> a userns, you already have all capabilities in it. If you enter it,
> you get to keep those by having them raised in cap_permitted. Being
> able to clear NNP and thus drop and subsequently regain them does not
> let you do anything you couldn’t already do.
> 
> An LSM hook for this would be needed because this argument does not
> apply to non-namespace-scoped LSM-based privileges. But the LSM hook
> would just be a "may this caller enter this userns and clear
> no_new_privs while doing so" query. In the absence of LSMs, the
> operation would be allowed.
> 
> This would allow a fully no_new_privs host to run an ordinary
> container that runs, in the ordinary way, without no_new_privs, and
> without hitting any new LSM calls after it's started.
> 
> The API could be as simple as a CLONE_CLEAR_NNP bit.

I think that sounds ok. I worry a little it since it would somewhat
alter the promise that NNP gives. What model do you envision?
It seems that CLONE_CLEAR_NNP would only be allowed with CLONE_NEWUSER.
I _think_ this safe even for privileged users that create a user
namespace and map uid 0 to uid 0. So I think this could work.
Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
#18769
Author: Andy Lutomirski
Date: Wed, 18 Nov 2026 21:49
63 lines
16322 bytes
On Wed, Nov 18, 2026 at 1:37 PM Christian Brauner <brauner@kernel.org> wrote:
>
> On Wed, Nov 18, 2026 at 01:12:45PM -0800, Andy Lutomirski wrote:

> > > > * 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.
> >
> > Nice!
> >
> > I commented in the uapi-group issue:
> >
> > I think there may be a rather more direct solution to this problem. I
> > seem to recall advocating for clearing no_new_privs when entering a
> > userns way back when, and IIRC I dropped this as part of the extensive
> > negotiation to get NNP into the kernel in the first place. (I think
> > dropping it was probably the right decision to keep the final patch
> > simple.)
> >
> > But I think I would still advocate for an option to let clone, unshare
> > and setns callers turn no_new_privs off. The logic is that, if you own
> > a userns, you already have all capabilities in it. If you enter it,
> > you get to keep those by having them raised in cap_permitted. Being
> > able to clear NNP and thus drop and subsequently regain them does not
> > let you do anything you couldn’t already do.
> >
> > An LSM hook for this would be needed because this argument does not
> > apply to non-namespace-scoped LSM-based privileges. But the LSM hook
> > would just be a "may this caller enter this userns and clear
> > no_new_privs while doing so" query. In the absence of LSMs, the
> > operation would be allowed.
> >
> > This would allow a fully no_new_privs host to run an ordinary
> > container that runs, in the ordinary way, without no_new_privs, and
> > without hitting any new LSM calls after it's started.
> >
> > The API could be as simple as a CLONE_CLEAR_NNP bit.
>
> I think that sounds ok. I worry a little it since it would somewhat
> alter the promise that NNP gives. What model do you envision?
> It seems that CLONE_CLEAR_NNP would only be allowed with CLONE_NEWUSER.
> I _think_ this safe even for privileged users that create a user
> namespace and map uid 0 to uid 0. So I think this could work.

Whoops.  I thought that and didn't type that.  Yes, I think you should
only be able to clear NNP with CLONE_NEWUSER.

(And if something like cells ever lands, presumably a task with NNP
set should be allowed to create a cell without NNP in the init task as
long as the same LSM hook says it's okay.)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads