From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796164727; b=SmUOQl/1rd/32uGevvnDGn03qMxgRO2VWjYLXVGqouyHbYD7fRx7EAL9cURapka5xxuz 5WtJFogdiSTsiPIDwq95O3iRm2OFKErHqkBBv6zcWH2XZeTEkGYUVCG4wlewsWy/tUdEq OZ6UB1NsiCdvn7uDmEDjLsgZCepBuLSzWQJr5wJJjhW7dYug5tXIgYWAiyHqbKh7moOpW HO1/gRXfPGoOLMJ9JCsSol/P3WwV/G3cJDsxRYP75BhVhuxA4RkzU45/J2YEUEzcJeiDp ajW4zbtGEAq5qWQzoOb1h5Ui3N/hI/AamYWYvzkCMTSb++QADa/MqsxQ+wyLWKGrW5g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796164727; h=Received:DKIM-Signature:Received:X-Forwarded-Encrypted: X-Gm-Message-State:X-Received:MIME-Version:References:In-Reply-To: From:Date:X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID: Subject:To:Cc:Content-Type:Content-Transfer-Encoding; bh=XmvmCn29jZ6ZlufnTzFCjEK0kWph4oINBxdLdl0eijs=; b=vHWKOOIctFolLpUnUCA0fHi5DGRE4Y+X9cCq5Z4iCBB6J2Eu2hskxLGVe0LJKabDOgUv Xz+eTV5yQ7ECZw3/5gH2RNOa9gC7HVucloBiORxY1p0NfWi3INHEX4zRTcaL9BWwocbrd 47F/ONeLyW0ENHuOKJrDTe6LmoUWn2f46HD+P6G+jZPPK/NQHxYpZ5AdCBot5O8gXOnbL d9Pyt1plWByuKFfMAD7lFtoYJlqNaaVloU1V++e6752Z5eXpLP0LuZHUVReF2w1oOZ3CO FQHM18kXR0vXaXutmH/QGEpyrh9pp+Jnn4Sa/+vmKUiWwRQaf2eLJ5JUlsA24eEOdyQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gYgv6crv; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56830606A320 for ; Tue, 1 Dec 2026 22:38:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gYgv6crv Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE7511F00893 for ; Tue, 1 Dec 2026 22:38:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796164727; bh=XmvmCn29jZ6ZlufnTzFCjEK0kWph4oINBxdLdl0eijs=; h=References:In-Reply-To:From:Date:Subject:To:Cc; b=gYgv6crvY8K2zNzbnRk6e9g11Bk45vdRG0Q5UtvVfe9XO8PCpIAR+GdGytRwc/k7a BpeFnZYa7Cn1MZVuQ5UO9T93nW7EcOPiDG7k9FQnwCN1KD+tmZb/Uz/ljwFmcHluq5 SFDAL6ABR7Q91MuLbm/gyodWfKRJj6px4dMPSdyrJpRC7MkfW3snY/yOomW1m+85Sl XGPSjeJ8B7ULatltypff9ky3zUDgb8bOs4rdKBNCUNlO81X7zik7FrtSwcxIKAh1cI 2e095vbUFKBvQJbnV0p99RS0O0qhpaQF3E+Y/G5c8zVbm3IlcgjB0qgITqz6Rj4xZb 5P+a6K3UxFNHA== Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-3ab3b29a298so103398691fa.3 for ; Tue, 01 Dec 2026 14:38:46 -0800 (PST) X-Forwarded-Encrypted: i=1; AL+hErGEULoAUZqRs1O/nYYXYb1QL47XAOeDbz0bFWzeNxjAEB5Qxy5VnkV7uGFKkVbKTakYpgGN8Y59vZCXWcI=@vger.kernel.org X-Gm-Message-State: APuU4Z9W2h8hIOdznuBKcvgV6D6u1fP/QOGc3ZclCbC7AsmeWJabE8CU BmMbmqwoVkg6e3w3q1N7tFUiBDJqjDejw8DXbJdBi9oateS3TkJ7hl6PMmwxfmb4UvZ0+sJu1c9 lKqvuGN3TNpfGNG+ZAO3Oqv8O321RSA5Q47ppfISp X-Received: by 2002:a05:6512:1382:b0:5c3:2517:e864 with SMTP id 2adb3069b0e04-5c32517e8acmr6861984e87.53.1796164725412; Tue, 01 Dec 2026 14:38:45 -0800 (PST) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 References: <20261201-raufen-belieben-seegurke-8f2da01d79b0@brauner> In-Reply-To: From: Andy Lutomirski Date: Tue, 1 Dec 2026 14:38:33 -0800 X-Gmail-Original-Message-ID: X-Gm-Features: Aa3M54rh0EyDI5rRcLo3Do1DkoveEXMNPnvQK9Tvg03bT0M2-IkVqmUpjvfHD9w Message-ID: Subject: Re: CLONE_CLEAR_NNP (Re: [PATCH v2 1/4] userns: introduce capability bounding set for user namespaces) To: Christian Brauner Cc: selinux@vger.kernel.org, apparmor@lists.ubuntu.com, Andy Lutomirski , "Hallgrimur H. Gunnarsson" , Serge Hallyn , Paul Moore , James Morris , David Howells , Jarkko Sakkinen , Kees Cook , Jonathan Corbet , Shuah Khan , Randy Dunlap , =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= , Jonathan Calmels , Jann Horn , =?UTF-8?Q?G=C3=BCnther_Noack?= , Singh KP , Casey Schaufler , Linux FS Devel , LSM List , Linux API , containers@lists.linux.dev, keyrings@vger.kernel.org, "open list:DOCUMENTATION" , "open list:KERNEL SELFTEST FRAMEWORK" , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Dec 1, 2026 at 2:17=E2=80=AFPM Andy Lutomirski wrote: > > On Tue, Dec 1, 2026 at 3:52=E2=80=AFAM Christian Brauner 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 i= f > > > 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 !=3D 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?