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 84223606A32F for ; Sat, 5 Dec 2026 13:47:57 +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=X3hq1Ob2 Received: by kanga.kvack.org (Postfix) id 477786B00EF; Sat, 5 Dec 2026 08:47:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 44F5D6B05B1; Sat, 5 Dec 2026 08:47:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33DD76B05B2; Sat, 5 Dec 2026 08:47:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 117456B00EF for ; Sat, 5 Dec 2026 08:47:56 -0500 (EST) Received: from smtpin21.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E416AC02ED for ; Sat, 5 Dec 2026 13:47:54 +0000 (UTC) X-FDA: 85510057668.21.06AED92 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf13.hostedemail.com (Postfix) with ESMTP id 4FBCF20004 for ; Sat, 5 Dec 2026 13:47:53 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=X3hq1Ob2; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of jarkko@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=jarkko@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796478473; b=Y1P9Vjrm79fCEHnEDTJFi2IaL1eU/subt18UIYDTNtwiT4QeqTJFEzfF0c3JvmCcSdVf7Z fR1vHOFqBp6b1FK9IGABynigF2jb7da05aRbUh1En5OnMzWDbJyTr9WcLQv+WE1u1quXeL rfirnWAbF9Q3JDZdZsFMoeoMLPFpnEM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796478473; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4A7sKf0/Dz1VYTrJ84aF3VifVp6nUPV7DEGrZqdIjYM=; b=yHGeNyZYBhB19HN3f7v4S8O8QoxZJ7zXHT7mdB/KA9DEqpbLABlvJCW0mmY8VCSMwEoUsJ o1W8B7U9pvRu6rArJaCA3L14Ae0IK46b3COWgUIF65jOXmqC0BLU62IoxnGB7XnjQVGfUY s5i05v+1tiNOUjfMiOCzRa+yI1K6v6k= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=X3hq1Ob2; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of jarkko@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=jarkko@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with UTF8SMTP id C1435601AC; Sat, 5 Dec 2026 13:47:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id BEA9E1F0092B; Sat, 5 Dec 2026 13:47:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796478472; bh=4A7sKf0/Dz1VYTrJ84aF3VifVp6nUPV7DEGrZqdIjYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=X3hq1Ob29GlBFmCq9LKSIgOZhWpLsnvpgJA8IU1nooMe9ml4/C/hXPeLRwokbhy8C 1gtfIGAvothBEFnnKiZYfjKoM3k+tq8e1xdB37U3K7gwRQnZsSRVYWJ+bTjqFNxIph Q59P7ckHqcwZXODJWGcOxTUnMURMbWbBKSO6LV2AlD1fDnneKklBwurffDqgA94R14 qNpFQT4blBmf9Oed9V7h27Bxoo9MxPp6/IKy1ySsqKqWbJr5+MLH/w7OcjTF7WHtCo 8b2XV6E3YCyCkphXwRTp2EhGy1PFVMJE69ugCT2nb0BBomH4GWXd5Y/nYQQuk4okLq VrGg7VOHjyQTA== From: Jarkko Sakkinen To: linux-fsdevel@vger.kernel.org Cc: bpf@vger.kernel.org, containers@lists.linux.dev, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, aleksa@amutable.com, alex@amutable.com, viro@zeniv.linux.org.uk, ast@kernel.org, akpm@linux-foundation.org, andrii@kernel.org, luto@amacapital.net, arnd@arndb.de, baolin.wang@linux.alibaba.com, bsegall@google.com, brauner@kernel.org, daniel@iogearbox.net, david@kernel.org, dhowells@redhat.com, dwmw2@infradead.org, dave@stgolabs.net, dietmar.eggemann@arm.com, eddyz87@gmail.com, emil@etsalapatis.com, ebiggers@kernel.org, georgia.garcia@canonical.com, giuseppe@scrivano.org, gnoack@google.com, hughd@google.com, ihor.solodrai@linux.dev, mingo@redhat.com, jmorris@namei.org, jack@suse.cz, jgg@nvidia.com, jlayton@kernel.org, jolsa@kernel.org, john.johansen@canonical.com, corbet@lwn.net, josef@toxicpanda.com, juri.lelli@redhat.com, kees@kernel.org, kprateek.nayak@amd.com, kpsingh@kernel.org, memxor@gmail.com, lennart@poettering.net, liam@infradead.org, manfred@colorfullife.com, martin.lau@linux.dev, matt@bobrowski.net, mgorman@suse.de, mhocko@suse.com, mic@digikod.net, rppt@kernel.org, neal@gompa.dev, oleg@redhat.com, paul@paul-moore.com, ptikhomirov@virtuozzo.com, peterz@infradead.org, rdunlap@infradead.org, serge@hallyn.com, sergeh@kernel.org, skhan@linuxfoundation.org, song@kernel.org, stephen.smalley.work@gmail.com, rostedt@goodmis.org, vschneid@redhat.com, vincent.guittot@linaro.org, yonghong.song@linux.dev, zygmunt.krynicki@canonical.com Subject: Re: [RFC PATCH v10 02/28] userns: Add NS_SET_IDMAP ioctl Date: Sat, 5 Dec 2026 15:47:43 +0200 Message-ID: <20261205134743.1870007-1-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261205032633.1702772-3-jarkko@kernel.org> References: <20261205032633.1702772-1-jarkko@kernel.org> <20261205032633.1702772-3-jarkko@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam04 X-Rspam-User: X-Rspamd-Queue-Id: 4FBCF20004 X-Stat-Signature: f7jceeob3noc6ep1imiaafbfziurrint X-Spam-Status: No, score=-14.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, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796478473-959162 X-HE-Meta: U2FsdGVkX1+GeSxUYl+nUrGD0fKfUqmyN+dG3a6Eh8TXnqGAZourD7vS2of/UgA9QfwfVRMVX7skDlcU7oy09bNIWTUm492Q+vTbyawbcx5xyGiq+oGEuvB6ngLeZ6F/PhaCXUo+guIPHEcXoYYmj5t8v12e3qWipoz+joyWOTwPiI7KuHsn5m6SYs+YQIRFpUTAcMEQiMRv3OpIDkbg0RvE0j7s7JNEvVNTc2pgx5hAfKrIvEmSrWPgNZFkDeYBkZUF3d7lblHZF2DDMzmzcWK4tq1849qXpEhDFlB8OHkrGJzMuM2JMmVV93R0u50U7+7UvTPcLjOr8rEsJ4k9+Ja95ogrJ4X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D4L+48jlnyjdVr/QZAccviA5uNBAEPniTOr8++sgf5FB0qLR7mk88WyhTmza6WtZnctdb9cEdGVdIkMbiTlDAb84Huu8zUeEs= 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 diff --git a/fs/nsfs.c b/fs/nsfs.c index c3c511133d80..f246930c9fa3 100644 --- a/fs/nsfs.c +++ b/fs/nsfs.c @@ -366,7 +366,7 @@ static long ns_ioctl(struct file *filp, unsigned int io= ctl, if (ns->ns_type !=3D CLONE_NEWUSER) return -EINVAL; =20 - return userns_set_idmap(filp, to_user_ns(ns), + return userns_set_idmap(to_user_ns(ns), (const struct userns_idmap __user *)arg, _IOC_SIZE(ioctl)); default: diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h index 7181c6011b44..079c66cbfa1c 100644 --- a/include/linux/user_namespace.h +++ b/include/linux/user_namespace.h @@ -35,7 +35,8 @@ struct uid_gid_map { /* 64 bytes -- 1 cache line */ }; }; =20 -#define USERNS_INIT_FLAGS USERNS_SETGROUPS_ALLOWED +#define USERNS_STATE_SETGROUPS_ALLOWED 1UL +#define USERNS_INIT_FLAGS USERNS_STATE_SETGROUPS_ALLOWED =20 struct ucounts; struct userns_idmap; @@ -207,7 +208,7 @@ extern bool in_userns(const struct user_namespace *ance= stor, const struct user_namespace *child); extern bool current_in_userns(const struct user_namespace *target_ns); struct ns_common *ns_get_owner(struct ns_common *ns); -long userns_set_idmap(struct file *file, struct user_namespace *ns, +long userns_set_idmap(struct user_namespace *ns, const struct userns_idmap __user *map, size_t size); =20 #if IS_ENABLED(CONFIG_KUNIT) @@ -267,8 +268,7 @@ static inline struct ns_common *ns_get_owner(struct ns_= common *ns) return ERR_PTR(-EPERM); } =20 -static inline long userns_set_idmap(struct file *file, - struct user_namespace *ns, +static inline long userns_set_idmap(struct user_namespace *ns, const struct userns_idmap __user *map, size_t size) { diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index 0a6d77b57798..1ab18f621980 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c @@ -150,7 +150,7 @@ int create_user_ns(struct cred *new) set_userns_rlimit_max(ns, UCOUNT_RLIMIT_MEMLOCK, rlimit(RLIMIT_MEMLOCK)); ns->ucounts =3D ucounts; =20 - /* Inherit USERNS_SETGROUPS_ALLOWED from our parent */ + /* Inherit the setgroups policy from our parent. */ mutex_lock(&userns_state_mutex); ns->flags =3D parent_ns->flags; mutex_unlock(&userns_state_mutex); @@ -1034,7 +1034,7 @@ static bool unpriv_idmap_permitted(const struct user_= namespace *ns, if (cap_setid =3D=3D CAP_SETUID) return uid_eq(make_kuid(ns->parent, id), cred->euid); if (cap_setid =3D=3D CAP_SETGID) - return !(ns_flags & USERNS_SETGROUPS_ALLOWED) && + return !(ns_flags & USERNS_STATE_SETGROUPS_ALLOWED) && gid_eq(make_kgid(ns->parent, id), cred->egid); return false; } @@ -1246,27 +1246,24 @@ static int parse_user_idmap_extents(__u64 uptr, __u= 32 nr_extents, =20 /** * userns_set_idmap - Handle %NS_SET_IDMAP on a user namespace nsfs file - * @filp: ``nsfs`` file referencing @ns * @ns: Target user namespace * @map: User pointer to &struct userns_idmap configuration * @size: Size of @map in bytes, encoded in the ioctl number * * Atomically configure UID, GID, and project ID mappings (and, when - * @map->nr_gid_extents is non-zero, the %USERNS_SETGROUPS_ALLOWED policy)= of - * @ns. Requires ``CAP_SYS_ADMIN`` over @ns in the caller's or @filp opene= r's - * credentials, with parent ID ranges authorized against the caller's - * credentials. + * @map->nr_gid_extents is non-zero, the setgroups policy) of @ns. The + * caller must have ``CAP_SYS_ADMIN`` over @ns; the descriptor does not + * confer authority. Parent ID ranges are authorized against the caller. * * Return: 0 on success, negative error code on failure. */ -long userns_set_idmap(struct file *filp, struct user_namespace *ns, +long userns_set_idmap(struct user_namespace *ns, const struct userns_idmap __user *map, size_t size) { struct uid_gid_map new_uid =3D {}, new_gid =3D {}, new_projid =3D {}; struct userns_idmap req =3D {}; unsigned long new_flags; unsigned int flags; - bool file_ok; int ret; =20 BUILD_BUG_ON(sizeof(struct userns_idmap) !=3D USERNS_IDMAP_SIZE_VER0); @@ -1292,10 +1289,7 @@ long userns_set_idmap(struct file *filp, struct user= _namespace *ns, if (current_user_ns() !=3D ns && current_user_ns() !=3D ns->parent) return -EPERM; =20 - 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) + if (!ns_capable(ns, CAP_SYS_ADMIN)) return -EPERM; =20 if (req.nr_uid_extents) { @@ -1331,10 +1325,10 @@ long userns_set_idmap(struct file *filp, struct use= r_namespace *ns, =20 if (req.nr_gid_extents) { if ((flags & USERNS_SETGROUPS_ALLOWED) && - !(new_flags & USERNS_SETGROUPS_ALLOWED)) + !(new_flags & USERNS_STATE_SETGROUPS_ALLOWED)) goto out_unlock; if (!(flags & USERNS_SETGROUPS_ALLOWED)) - new_flags &=3D ~USERNS_SETGROUPS_ALLOWED; + new_flags &=3D ~USERNS_STATE_SETGROUPS_ALLOWED; } =20 if (req.nr_uid_extents) { @@ -1465,7 +1459,7 @@ int proc_setgroups_show(struct seq_file *seq, void *v) unsigned long userns_flags =3D READ_ONCE(ns->flags); =20 seq_printf(seq, "%s\n", - (userns_flags & USERNS_SETGROUPS_ALLOWED) ? + (userns_flags & USERNS_STATE_SETGROUPS_ALLOWED) ? "allow" : "deny"); return 0; } @@ -1515,7 +1509,7 @@ ssize_t proc_setgroups_write(struct file *file, const= char __user *buf, /* Enabling setgroups after setgroups has been disabled * is not allowed. */ - if (!(ns->flags & USERNS_SETGROUPS_ALLOWED)) + if (!(ns->flags & USERNS_STATE_SETGROUPS_ALLOWED)) goto out_unlock; } else { /* Permanently disabling setgroups after setgroups has @@ -1523,7 +1517,7 @@ ssize_t proc_setgroups_write(struct file *file, const= char __user *buf, */ if (ns->gid_map.nr_extents !=3D 0) goto out_unlock; - ns->flags &=3D ~USERNS_SETGROUPS_ALLOWED; + ns->flags &=3D ~USERNS_STATE_SETGROUPS_ALLOWED; } mutex_unlock(&userns_state_mutex); =20 @@ -1547,7 +1541,7 @@ bool userns_may_setgroups(const struct user_namespace= *ns) */ allowed =3D ns->gid_map.nr_extents !=3D 0; /* Is setgroups allowed? */ - allowed =3D allowed && (ns->flags & USERNS_SETGROUPS_ALLOWED); + allowed =3D allowed && (ns->flags & USERNS_STATE_SETGROUPS_ALLOWED); mutex_unlock(&userns_state_mutex); =20 return allowed;