On Tue, Dec 1, 2026 at 2:17 PM Andy Lutomirski <[email protected]> wrote:
>
> On Tue, Dec 1, 2026 at 3:52 AM Christian Brauner <[email protected]> wrote:
> >
> > On Mon, Nov 30, 2026 at 11:31:23AM -0800, Andy Lutomirski wrote:
> > > We add a new LSM hook clear_nnp.  The logic that one may only use it
> > > when unsharing userns goes outside LSM (because there is nothing in
> > > the hook that indicates that userns is being unshared, so it can't go
> > > in commoncap).  Apparmor implements it by only allowing unconfined
> > > tasks to do it (and apparmor devs are welcome to change this policy if
> > > it becomes useful).  selinux adds an actual new policy
> > > PROCESS2__CLEAR_NNP.
> >
> > Sounds decent. It's fine to add the hooks later.
> > Send that soon if you can. That doesn't need to hold up the other stuff.
>
> It's sitting here, with apparmor and selinux hooks and a test case
> (AI-written) that passes:
>
> https://github.com/amluto/linux/tree/clone_nnp
>
> (The code is drafted partially by AI and substantially cleaned up by me.)
>
> I'll send it out later today or tomorrow, but you're welcome to
> comment even before I manage to send it.

Reviewing my own code, there's an interesting interaction with
autokill and pidns killing.

Today, a non-nnp task can create a userns and pidns, then execute a
setuid program inside them (as pid != 1), then kill pid1, thus
SIGKILLing the setuid problem.

And we have this:

        if (clone_flags & CLONE_PIDFD_AUTOKILL) {
                if (!(clone_flags & CLONE_PIDFD))
                        return ERR_PTR(-EINVAL);
                if (!(clone_flags & CLONE_AUTOREAP))
                        return ERR_PTR(-EINVAL);
                if (clone_flags & CLONE_THREAD)
                        return ERR_PTR(-EINVAL);
                /*
                 * Without CLONE_NNP the child could escalate privileges
                 * after being spawned, so require CAP_SYS_ADMIN.
                 * With CLONE_NNP the child can't gain new privileges,
                 * so allow unprivileged usage.
                 */
                if (!(clone_flags & CLONE_NNP) &&
                    !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
                        return ERR_PTR(-EPERM);
        }

My patch allows CLONE_CLEAR_NNP in both clone3 and unshare, which
means it allows the check at the end to be bypassed: one can
clone3(..., CLONE_NNP | CLONE_PIDFD_AUTOKILL) and then
unshare(CLONE_NEWUSER | CLONE_CLEAR_NNP).  And then one can (in the
new namespace) elevate privileges and send SIGKILL the elevated task.

I'm thinking that this isn't a problem (except with LSMs, and I have
that covered).  So I actually suggest relaxing the rule so that
CLONE_PIDFD_AUTOKILL | CLONE_NEWUSER | CLONE_CLEAR_NNP is also
allowed, mostly for consistency.  (I'm less comfortable with it
without the CLONE_CLEAR_NNP part because that would bypass LSMs, at
least the way I've structured it.)

What do you think?

Reply via email to