From: Andy Lutomirski <luto@kernel.org>
To: Christian Brauner <brauner@kernel.org>
Cc: selinux@vger.kernel.org, apparmor@lists.ubuntu.com,
"Andy Lutomirski" <luto@kernel.org>,
"Hallgrimur H. Gunnarsson" <halg@google.com>,
"Serge Hallyn" <sergeh@kernel.org>,
"Paul Moore" <paul@paul-moore.com>,
"James Morris" <jmorris@namei.org>,
"David Howells" <dhowells@redhat.com>,
"Jarkko Sakkinen" <jarkko@kernel.org>,
"Kees Cook" <kees@kernel.org>, "Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Mickaël Salaün" <mic@digikod.net>,
"Jonathan Calmels" <jcalmels@3xx0.net>,
"Jann Horn" <jannh@google.com>,
"Günther Noack" <gnoack@google.com>,
"Singh KP" <kpsingh@kernel.org>,
"Casey Schaufler" <casey@schaufler-ca.com>,
"Linux FS Devel" <linux-fsdevel@vger.kernel.org>,
"LSM List" <linux-security-module@vger.kernel.org>,
"Linux API" <linux-api@vger.kernel.org>,
containers@lists.linux.dev, keyrings@vger.kernel.org,
"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
"open list:KERNEL SELFTEST FRAMEWORK"
<linux-kselftest@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: CLONE_CLEAR_NNP (Re: [PATCH v2 1/4] userns: introduce capability bounding set for user namespaces)
Date: Tue, 1 Dec 2026 14:38:33 -0800 [thread overview]
Message-ID: <CALCETrWV++G_o_NaThrMM7e4AQ4cduBC3bRuiCHpm3MgReW1Wg@mail.gmail.com> (raw)
In-Reply-To: <CALCETrUM=gdZBmVkx0T0Vf+hLmqkgPDbUTnLW17dEaiK5DhMdA@mail.gmail.com>
On Tue, Dec 1, 2026 at 2:17 PM Andy Lutomirski <luto@amacapital.net> wrote:
>
> On Tue, Dec 1, 2026 at 3:52 AM Christian Brauner <brauner@kernel.org> 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?
prev parent reply other threads:[~2026-12-01 22:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 19:31 Andy Lutomirski
2026-12-01 11:52 ` Christian Brauner
2026-12-01 22:17 ` Andy Lutomirski
2026-12-01 22:38 ` Andy Lutomirski [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CALCETrWV++G_o_NaThrMM7e4AQ4cduBC3bRuiCHpm3MgReW1Wg@mail.gmail.com \
--to=luto@kernel.org \
--cc=apparmor@lists.ubuntu.com \
--cc=brauner@kernel.org \
--cc=casey@schaufler-ca.com \
--cc=containers@lists.linux.dev \
--cc=corbet@lwn.net \
--cc=dhowells@redhat.com \
--cc=gnoack@google.com \
--cc=halg@google.com \
--cc=jannh@google.com \
--cc=jarkko@kernel.org \
--cc=jcalmels@3xx0.net \
--cc=jmorris@namei.org \
--cc=kees@kernel.org \
--cc=keyrings@vger.kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mic@digikod.net \
--cc=paul@paul-moore.com \
--cc=rdunlap@infradead.org \
--cc=selinux@vger.kernel.org \
--cc=sergeh@kernel.org \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®