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=1796442749; b=RrnsirvaqYxeF75FWe0RQfQoJyvEH7egQ/sfmX453f4z2C6tODcyU/bk5ZoKEX8vSIxS q95Emjt0A9xjEzfkIIeU7EQnd1X65krpSyXFaJjHRD1CUGcxmxpxQwaTr8VCnYWkmC6Nq kyhOeREIulNucWissXZN5/dSjAeWOx/FzTHGMOav+iS20K3dFxvvALjcEpYz8Po2MCJTV rc3LubXMraHs+5k7jS6OIWyhwZyIO8qudC2ppyjpUCGYuVqJ9UwpVEgpTh8CQ7w4rzaY5 wv7eMc6VJuhLLIDkoy1O0Pnul7sHb+S5DtT1S6HkpTeUn0hn1DuEX4Pky8Vv0bk6HVQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796442749; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=sKT6DZwYyecyZG3bdGk+6uYMGbDimirvx2fcgi5pTes=; b=Fr9JtvlQtokJL0GNJYx4tkz61EhRCPVoeUl/zfi+K6Awyr0Ynwy4ZTIePwbrq583GLbK 2K6PQGKqOqDaBCNzg+CX9/8evyUC0uaF7HBzV5HiNDxv6BbyXsFnhi8IsaP8ayKwp1Zv8 XFxEp/62fY9el0phwH3s8rlgcw/mAvczW4F0KF2qsmPK3yTAbMTCa+dgKExpzfRECma9H 3xkggoPErqdqtJ27qOz/PPg2coldltVr3PnLNNArTIblZKR8YfbKYmFZ4EEHdz2zHMBL1 vpcUIRFEgWYiEKboyvobGAz3SJyfTAystWAzBWrBymRBys5pXOimvU0I/O021wBg1YQ== 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=oZKrVPUH; 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 DE5B4606A322; Sat, 5 Dec 2026 03:52:29 +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=oZKrVPUH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3452C1F0092B; Sat, 5 Dec 2026 03:52:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796442749; bh=sKT6DZwYyecyZG3bdGk+6uYMGbDimirvx2fcgi5pTes=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=oZKrVPUH6jjqoRb28wIs8iBMAy62PAhpaLhZynvt800QuRVh5c3q8CgwE/ObVrUye jDCSUIcgnynZdeR5RvzRc65wSJF38qfZl5L3eFJQQ2I0zH9pZTVVhOng6hj06wFyKN 6WO6ve+U8FiMpi2DATN4/Ho1RAaeb9inhj/XdFw/brn5Nx5EhQFVCMBuGFsdleQtQh J+if8tzOIxf/luhdba0r1wCp2U47YFrIjlWbisNpb1+DfrmZjyoxdffFYP8PjlC6Db xHSZTFjdf1rcJBAr8uKL1MU2grlIX4CyiSB3Q9u1UdjR7DOMi5nJU4XGp9ZxJM+VPQ iFnkKzN51L5rg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH v10 02/28] userns: Add NS_SET_IDMAP ioctl Reply-To: sashiko-reviews@lists.linux.dev To: "Jarkko Sakkinen" Cc: bpf@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, "Aleksa Sarai" , "Alexander Mikhalitsyn" , "Alexander Viro" , "Alexei Starovoitov" , "Andrew Morton" , "Andrii Nakryiko" , "Andy Lutomirski" , "Arnd Bergmann" , "Baolin Wang" , "Ben Segall" , "Christian Brauner" , "Daniel Borkmann" , "David Hildenbrand" , "David Howells" , "David Woodhouse" , "Davidlohr Bueso" , "Dietmar Eggemann" , "Eduard Zingerman" , "Emil Tsalapatis" , "Eric Biggers" , "Georgia Garcia" , "Giuseppe Scrivano" , =?utf-8?b?R8O8bnRoZXIgTm9hY2s=?= , "Hugh Dickins" , "Ihor Solodrai" , "Ingo Molnar" , "James Morris" , "Jan Kara" , "Jason Gunthorpe" , "Jeff Layton" , "Jiri Olsa" , "John Johansen" , "Jonathan Corbet" , "Josef Bacik" , "Juri Lelli" , "Kees Cook" , "K Prateek Nayak" , "KP Singh" , "Kumar Kartikeya Dwivedi" , "Lennart Poettering" , "Liam R. Howlett" , "Manfred Spraul" , "Martin KaFai Lau" , "Matt Bobrowski" , "Mel Gorman" , "Michal Hocko" , =?utf-8?b?TWlja2HDq2wgU2FsYcO8bg==?= , "Mike Rapoport" , "Neal Gompa" , "Oleg Nesterov" , "Paul Moore" , "Pavel Tikhomirov" , "Peter Zijlstra" , "Randy Dunlap" , "Serge E. Hallyn" , "Serge Hallyn" , "Shuah Khan" , "Song Liu" , "Stephen Smalley" , "Steven Rostedt" , "Valentin Schneider" , "Vincent Guittot" , "Yonghong Song" , "Zygmunt Krynicki" In-Reply-To: <20261205032633.1702772-3-jarkko@kernel.org> References: <20261205032633.1702772-1-jarkko@kernel.org> <20261205032633.1702772-3-jarkko@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 03:52:26 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] userns: O_RDONLY nsfs fd delegates CAP_SYS_ADMIN in userns_set_idmap() - [Medium] userns: unconditional audited capability checks in userns_set_idmap() - [Low] userns: UAPI enum userns_flags coupled to internal user_namespace flags -- commit f30565016f3fce79f0b5b5361521af58b064c599 Author: Jarkko Sakkinen userns: Add NS_SET_IDMAP ioctl This commit adds the NS_SET_IDMAP ioctl on user namespace nsfs file descriptors to atomically install UID, GID, and project ID mappings and configure the USERNS_SETGROUPS_ALLOWED policy. [ ... ] > diff --git a/include/uapi/linux/nsfs.h b/include/uapi/linux/nsfs.h > index e5909266ec3fb..5fc59e2f23bda 100644 > --- a/include/uapi/linux/nsfs.h > +++ b/include/uapi/linux/nsfs.h [ ... ] > +/** > + * enum userns_flags - User namespace flags > + * @USERNS_SETGROUPS_ALLOWED: Allow setgroups(2) inside the user namespa= ce > + * once its GID mapping is established. > + */ > +enum userns_flags { > + USERNS_SETGROUPS_ALLOWED =3D (1 << 0), > +}; [Severity: Low] Should NS_SET_IDMAP define its own ioctl-scoped flag instead of exporting USERNS_SETGROUPS_ALLOWED directly into UAPI? Reusing this enumerator for USERNS_INIT_FLAGS and ns->flags couples the permanent ABI to kernel-internal state bits, risking bit collisions when either side adds flags. A dedicated UAPI flag such as USERNS_IDMAP_SETGROUPS_ALLOWED translated in userns_set_idmap() avoids this. [ ... ] > diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c > index caba2ac33077e..73daac18e6347 100644 > --- a/kernel/user_namespace.c > +++ b/kernel/user_namespace.c [ ... ] > + file_ok =3D (filp->f_cred->user_ns =3D=3D ns || > + filp->f_cred->user_ns =3D=3D ns->parent) && > + file_ns_capable(filp, ns, CAP_SYS_ADMIN); > + if (!ns_capable(ns, CAP_SYS_ADMIN) && !file_ok) > + return -EPERM; [Severity: High] Does authorizing NS_SET_IDMAP via file_ns_capable() turn O_RDONLY nsfs file descriptors into CAP_SYS_ADMIN bearer tokens? Every nsfs inode is read-only (S_IRUGO in nsfs_init_inode()) and opened O_RDONLY, so unlike /proc//projid_map (S_IRUGO|S_IWUSR) there is no write-open check separating inspection handles from write-authorized ones. An unprivileged process in ns->parent that obtains an O_RDONLY nsfs fd opened by root or ns->owner passes file_ok, and caller_idmap_permitted() returns true unconditionally when !cap_valid(cap_setid), allowing it to permanently install an arbitrary write-once projid_map on ns. Likewise, a task inside ns that dropped CAP_SYS_ADMIN while holding an inherited O_RDONLY fd can still set uid_map, gid_map (permanently disabling setgroups(2)), and projid_map via unpriv_idmap_permitted(). [Severity: Medium] Can these unconditional capability checks emit spurious LSM audit denials on succeeding NS_SET_IDMAP calls? Both file_ns_capable() and ns_capable() pass CAP_OPT_NONE to security_capable(). Here file_ok is computed eagerly and ns_capable() runs even when file_ok is true, so a succeeding call where one side is denied by SELinux emits a spurious AVC denial and can mark PF_SUPERPRIV unnecessarily. Checking with ns_capable_noaudit() and short-circuiting so an audited check runs only on final denial would avoid these spurious audit records. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205032633.1702= 772-1-jarkko@kernel.org?part=3D2