From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61F90606A322 for ; Sat, 5 Dec 2026 03:52:39 +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 kanga.kvack.org (Postfix) id 32BC56B05BB; Fri, 4 Dec 2026 22:52:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DCD26B05BE; Fri, 4 Dec 2026 22:52:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A4266B05BF; Fri, 4 Dec 2026 22:52:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id CF45E6B05BB for ; Fri, 4 Dec 2026 22:52:37 -0500 (EST) Received: from smtpin03.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0D9CBA016B for ; Sat, 5 Dec 2026 03:52:32 +0000 (UTC) X-FDA: 85508557344.03.3AE023E Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf13.hostedemail.com (Postfix) with ESMTP id 648072000A for ; Sat, 5 Dec 2026 03:52:30 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=oZKrVPUH; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796442750; b=ds4z/bV4HX+zIym9hLPGOJBcc02KqEk9jETzfmmSypoIQQjtjOsdJlofoJu6712sn9vCQ1 QNsAGR57rp7epWtkZAaKu9s6BZ4XNmNdCl09kp5Lm/QkTs5F9CwiUcdUToOdtbrP6y4tgL xeOroZNfse0gbEOfGUE6B7pPygYwpd0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796442750; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sKT6DZwYyecyZG3bdGk+6uYMGbDimirvx2fcgi5pTes=; b=qAizglMVHeOdU2N9NsYBft+Z57Q08A9RFxR7khtcNT0722KgC5eldJqtUTxUY8NDnUBGB1 IycYiv8oqliL9k9bt8RrjjhV4exHQznD/Db+wMHOynLgM2ehbjL6oYbuhESNftQ2Y0jgTD qt4ymP4aOPrvJIsRLZcUd+mQEFaNI/8= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=oZKrVPUH; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 8C7784455E; Sat, 5 Dec 2026 03:52:29 +0000 (UTC) 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-Rspamd-Server: rspam11 X-Rspam-User: X-Stat-Signature: 4hcrkrp3bcoo37x6ffzoopykwetnqwst X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Rspamd-Queue-Id: 648072000A X-HE-Tag: 1796442750-650305 X-HE-Meta: U2FsdGVkX1868cHKQ7SpgfXA1t/xEu23cXqX+p0WkV/kU7NBrb7/V/jhKsRMfFIAFX25Z7HRAVdpwYNrxUXGFTWS0qCqpNxJeUz0c6wS5+QYtqLfEu1S/rEjhA4hVun+YFL9RUSi8M1E35hCyc/fU/VAyQjSefikIGlbJfo+/SEhWSZahWxm2WsmHGl1o4DVBIGuBBKambyllNjdVLKVeNLQ73LLtPWrwlc16YXQjOwEBcShhGrdtBZ+AbCQKGvAbWQRrT7oH2IzsFSiUNmsVLcLG9LGJ1zYXkFFF3j3VWCuhO3gM4GtBB6nRdOlRVXAUyyjDXNdDp9/Um4rcNI46QsGg6MqIGQD84hAmoCaCtmlD/+uikumJvHMmDXhsPDq2pgjJ0ErZOG/KZX4TTxTb12TMWrhrDH8IxOnGk3pY/PHlrrc5okYdTmy9AWuFO/1QL6FZL8CUiiSvJdBO9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nIZGZUedMA85FOx8Myo/r/gcfWUc6zQ4+ILVcZytel4n5HNjTGy2Q17N2cGLmoiLi+2ozyWq/ttP96jdm5IF/DygmRvozv9lWua0leavFMSplCXKWJyvkX+dockWJX2NSHTmFB9b9NUUOfFDoAP8EGoDE4xE71pvF5RGLsfUW1hfyKK5OV+6RNJDLmOneM8fv4zj1g9ahC/apKO+GCJMAtiIy7RpTF9NbF4/O3isyzjQFRNpOgl0mO8judqzYM1cgvV9odHaHUNO+8hGGmOHqu9bCZ7Qfdfe9sxgz9MtDFvnBBobUXzlbGDXon8xzR1TkpnD011Bl8z/Z6DFBSqkCQGftMhvYLqnXSP1oSZsxLQuG6HA/IpS0MfWi5iaFqamG3h6p8Y8syHKFsDzDEHYw== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: 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