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 59BD0606A332 for ; Sat, 5 Dec 2026 03:29:43 +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=PSQfOutN Received: by kanga.kvack.org (Postfix) id 2A8536B05D7; Fri, 4 Dec 2026 22:28:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2809A6B05D8; Fri, 4 Dec 2026 22:28:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 16E9E6B05D9; Fri, 4 Dec 2026 22:28:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CA89F6B05D7 for ; Fri, 4 Dec 2026 22:28:10 -0500 (EST) Received: from smtpin01.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 361C61401B7 for ; Sat, 5 Dec 2026 03:28:10 +0000 (UTC) X-FDA: 85508495940.01.14B1A22 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf15.hostedemail.com (Postfix) with ESMTP id 95082A000C for ; Sat, 5 Dec 2026 03:28:08 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=PSQfOutN; spf=pass (imf15.hostedemail.com: domain of jarkko@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=jarkko@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796441288; b=1ARbkBSAIYcn6+ZoJe07xucFAp4gdEbwvxIBmUZ5AtrLNuHKE7uca3Q4srlepTh3aFiBDN u7dbmBV6QslnhncPPLJMyRqxpQcWXaVT+N8Gx0yG1eubFmCZ7h5KpNM1HH+wRr8UcHxR/j ps1mKpmpTxN3fxMahXj47NfMHxztAuE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796441288; 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=7jiMvZAA58AqIxDwzO1QdJZpkwXsP7IdTfZOd7CLBoE=; b=WorSN6KqpI48gDkyQPq+5DVZVTDZYlG96rpip8caf9YHTQOwMgZzTfvVJzuR7zi3kSGvrO kja0zktzKCFnV4ZyqWVOzouIhnWrkz5PXIm7JJoYThbgNTLWRh9I7oAZOUcLnNtNOWzmJV acxnDJz8qkGw1xa+iMCJnCf5Y4QjA50= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=PSQfOutN; spf=pass (imf15.hostedemail.com: domain of jarkko@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=jarkko@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with UTF8SMTP id 1ADDF61B26; Sat, 5 Dec 2026 03:28:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 146A51F00A07; Sat, 5 Dec 2026 03:28:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796441287; bh=7jiMvZAA58AqIxDwzO1QdJZpkwXsP7IdTfZOd7CLBoE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PSQfOutNpaqJCHWHVCC1U2STGZdXL9gOLcfC2SifbAdtBGSC5JsbKNsRv9AE+1Hn0 EHb0djYp0uaRQHonwqbK4PdND9LaPjseqTblygHM2q7OLPVauG0Kye6xbLfoi2s0Mu ge3UVyfkrmx0yRPjwK5EEz706kErE1V7269v8fJBCadb4qdtLG2co5WPhpdHfsJKMR QME+UkENkY8qLmjYVE6JYzWtMhNK/TutJn5uYNAAuBbZhAznhwdvFjc8ARitv7ZGiy h7TRVgEV+Yext+shSk226Dv5oP8Esy9BTBTHr6nnQBiEE/A0h5rPpdmZXeRzR0ttPP +gFCgOLzAsIbw== From: Jarkko Sakkinen To: fsdevel@vger.kernel.org Cc: Jarkko Sakkinen , bpf@vger.kernel.org, containers@lists.linux.dev, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@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 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?q?G=C3=BCnther=20Noack?= , 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?q?Micka=C3=ABl=20Sala=C3=BCn?= , 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 Subject: [RFC PATCH v10 20/28] proc: Implement ->set_run() fs_context operation Date: Sat, 5 Dec 2026 05:26:25 +0200 Message-ID: <20261205032633.1702772-21-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261205032633.1702772-1-jarkko@kernel.org> References: <20261205032633.1702772-1-jarkko@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: 4dipa4tmpijduk85epy4wmjckp13i1ag X-Rspam-User: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Rspamd-Queue-Id: 95082A000C X-Rspamd-Server: rspam01 X-HE-Tag: 1796441288-965683 X-HE-Meta: U2FsdGVkX1/ee1CjlnoA1902j3NkIKqgKps98uw9VUlCPTICUQEu49hssxWtQScmTqzud91a1OEPKABaK0+jwdIR9TG1JAP8Df0Rp0JOH7f3WcN5V8i3D0clCW/Q1rOPmCIYZ3luJYulURH9Xsxc9mzeB6fl/JoOFA67MF85itnHTjutqLiGdPsg97W5+y7xlRfJ1yCsgaD0M49dJypU2y507RUr1wMm49OdZZFqItq60/kld4mC+eAYeLjXoy9HGCfKaCj4/YBlVsbd4NgVpq1MxzgP2FBAjSLxMgHQz8VAFTRWA/t4ABPAXyDbwEimfteg7YCPW1aGEl9wyqq7bp/+skJKlZJq0ceVZXf9DM/gHBR+XECe3tA7Y/fhVcXTyxemj6YbxmH/7dJJ+5pTzxDaGxmPUACgCdtDsWdKCd0GCg4XYfiZBSwMCsNbSifNEGFJWAX90XZ5K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wVpt/YU88dUYeQw== 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 proc_init_fs_context() binds ctx->pid_ns to task_active_pid_ns(current) and resets fc->user_ns to ctx->pid_ns->user_ns, overriding the user namespace delegated by FSCONFIG_SET_RUN and leaving the context attached to the caller's PID namespace. Wire up proc_set_run() to verify that the target run's PID namespace is a descendant of the caller's active PID namespace and rebind ctx->pid_ns and fc->user_ns accordingly, and mark proc with FS_RUN_MOUNT. Co-developed-by: David Howells Signed-off-by: David Howells Signed-off-by: Jarkko Sakkinen --- fs/proc/root.c | 61 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 15 deletions(-) diff --git a/fs/proc/root.c b/fs/proc/root.c index 7fbbe92bf73a..de14a7933ee5 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include #include @@ -30,7 +32,7 @@ struct proc_fs_context { struct pid_namespace *pid_ns; unsigned int mask; enum proc_hidepid hidepid; - int gid; + kgid_t gid; enum proc_pidonly pidonly; }; @@ -42,7 +44,7 @@ enum proc_param { }; static const struct fs_parameter_spec proc_fs_parameters[] = { - fsparam_u32("gid", Opt_gid), + fsparam_gid("gid", Opt_gid), fsparam_string("hidepid", Opt_hidepid), fsparam_string("subset", Opt_subset), fsparam_file_or_string("pidns", Opt_pidns), @@ -178,7 +180,9 @@ static int proc_parse_param(struct fs_context *fc, struct fs_parameter *param) switch (opt) { case Opt_gid: - ctx->gid = result.uint_32; + if (!kgid_has_mapping(fc->user_ns, result.gid)) + return invalfc(fc, "Invalid gid"); + ctx->gid = result.gid; break; case Opt_hidepid: @@ -206,6 +210,10 @@ static int proc_parse_param(struct fs_context *fc, struct fs_parameter *param) errorfc(fc, "cannot reconfigure pidns for existing procfs"); return -EBUSY; } + if (fc->run_bound) { + errorfc(fc, "cannot override pidns on run-bound procfs"); + return -EBUSY; + } err = proc_parse_pidns_param(fc, param, &result); if (err) return err; @@ -224,8 +232,7 @@ static int proc_parse_param(struct fs_context *fc, struct fs_parameter *param) } static int proc_apply_options(struct proc_fs_info *fs_info, - struct fs_context *fc, - struct user_namespace *user_ns) + struct fs_context *fc) { struct proc_fs_context *ctx = fc->fs_private; @@ -234,8 +241,11 @@ static int proc_apply_options(struct proc_fs_info *fs_info, ctx->pidonly != fs_info->pidonly) return invalf(fc, "proc: subset=pid cannot be changed\n"); - if (ctx->mask & (1 << Opt_gid)) - fs_info->pid_gid = make_kgid(user_ns, ctx->gid); + if (ctx->mask & (1 << Opt_gid)) { + if (!kgid_has_mapping(fc->user_ns, ctx->gid)) + return invalfc(fc, "Invalid gid"); + fs_info->pid_gid = ctx->gid; + } if (ctx->mask & (1 << Opt_hidepid)) fs_info->hide_pid = ctx->hidepid; if (ctx->mask & (1 << Opt_subset)) @@ -261,7 +271,8 @@ static int proc_fill_super(struct super_block *s, struct fs_context *fc) fs_info->pid_ns = get_pid_ns(ctx->pid_ns); fs_info->mounter_cred = get_cred(fc->cred); - ret = proc_apply_options(fs_info, fc, current_user_ns()); + s->s_fs_info = fs_info; + ret = proc_apply_options(fs_info, fc); if (ret) return ret; @@ -273,8 +284,6 @@ static int proc_fill_super(struct super_block *s, struct fs_context *fc) s->s_magic = PROC_SUPER_MAGIC; s->s_op = &proc_sops; s->s_time_gran = 1; - s->s_fs_info = fs_info; - if (fs_info->pidonly == PROC_PIDONLY_ON) s->s_iflags |= SB_I_RESTRICTED_VARIANT; @@ -315,7 +324,7 @@ static int proc_reconfigure(struct fs_context *fc) sync_filesystem(sb); - return proc_apply_options(fs_info, fc, current_user_ns()); + return proc_apply_options(fs_info, fc); } static int proc_get_tree(struct fs_context *fc) @@ -323,6 +332,21 @@ static int proc_get_tree(struct fs_context *fc) return get_tree_nodev(fc, proc_fill_super); } +static int proc_set_run(struct fs_context *fc, struct run *run) +{ + struct proc_fs_context *ctx = fc->fs_private; + struct pid_namespace *target = run->ns->pid_ns_for_children; + + if (!pidns_is_ancestor(target, task_active_pid_ns(current))) + return invalfc(fc, "cannot set pidns to non-descendant pidns"); + + put_pid_ns(ctx->pid_ns); + ctx->pid_ns = get_pid_ns(target); + put_user_ns(fc->user_ns); + fc->user_ns = get_user_ns(ctx->pid_ns->user_ns); + return 0; +} + static void proc_fs_context_free(struct fs_context *fc) { struct proc_fs_context *ctx = fc->fs_private; @@ -334,6 +358,7 @@ static void proc_fs_context_free(struct fs_context *fc) static const struct fs_context_operations proc_fs_context_ops = { .free = proc_fs_context_free, .parse_param = proc_parse_param, + .set_run = proc_set_run, .get_tree = proc_get_tree, .reconfigure = proc_reconfigure, }; @@ -346,9 +371,13 @@ static int proc_init_fs_context(struct fs_context *fc) if (!ctx) return -ENOMEM; - ctx->pid_ns = get_pid_ns(task_active_pid_ns(current)); - put_user_ns(fc->user_ns); - fc->user_ns = get_user_ns(ctx->pid_ns->user_ns); + if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) { + ctx->pid_ns = get_pid_ns(proc_sb_info(fc->root->d_sb)->pid_ns); + } else { + ctx->pid_ns = get_pid_ns(task_active_pid_ns(current)); + put_user_ns(fc->user_ns); + fc->user_ns = get_user_ns(ctx->pid_ns->user_ns); + } fc->fs_private = ctx; fc->ops = &proc_fs_context_ops; return 0; @@ -371,7 +400,9 @@ static struct file_system_type proc_fs_type = { .init_fs_context = proc_init_fs_context, .parameters = proc_fs_parameters, .kill_sb = proc_kill_sb, - .fs_flags = FS_USERNS_MOUNT | FS_USERNS_MOUNT_RESTRICTED | FS_DISALLOW_NOTIFY_PERM, + .fs_flags = FS_USERNS_MOUNT | FS_RUN_MOUNT | + FS_USERNS_MOUNT_RESTRICTED | + FS_DISALLOW_NOTIFY_PERM, }; void __init proc_root_init(void) -- 2.47.3