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=1795910386; b=BKh9C8ZwkEKBjajEi6+MG3ekG7oZqbDcgpEqaKWSPK0XbYCEQSP4bswHxZAAeQdxq2br oMNF12y4g4Q8XRBxyCvxLRSxeg39OHLqLZuYkLtWgoSIEccol1uZFnkyaKWiOs2E23Ypd a4aSS+82AWnvaFLGzEueCwnC9NXwaxeqeUAAh3sjcWK7w6YzXVDW2HZROylYO9GihgF1q xpSAs3lrLZ6KjUiAN010tp3uXQJUiHQauA8Lo4eDnrkgsf5Cq+tf+MB5YOetVNByJUT4+ AxlBDOzmuztW0Ac7KVy+yOQuiS3J8Y1DNKCooZAWYtP+ny06L78o4sAQrJ3uCkDUEMA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795910386; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=Jfv3MMg/O7UN8A+W1NHYimNXqqAkPIDpKwh6yDT3Yps=; b=MnMzALV0bqgGQLg72Ru2bzTBMQoFd/pBkdpY3/ZU+HxrdaRRMuvh2H9gn22LRbNbM6p8 oR1UBVXHMi2m/UFkika8llAzyFG5enoQlNRCa4QY4XqbJsZIZeuOWcspcCe7svsZesxRs FdSLuLByjJ4OE2zDsKX2B2vuAvW2RM7D83W+XBFtLOne8MUY08GdhBCUWpMmqaA2RiDbc 7vNZk3nlZQ2TO1SNDngtcUHY1LyoiwKdVHvQblZKLmIHTvqWb/e34JtbQd0A8sLvVg8Pb wtw72yUUS3iqv/p21NY7F3d1dqbEK9MAMW1nmqrzqJ0z3RV4sU24PHZR18GImoArIKw== 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=UmKlIVDj; 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 UTF8SMTPS id B6778606A6B0; Sat, 28 Nov 2026 23:59:45 +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=UmKlIVDj Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 5D9F41F00A17; Sat, 28 Nov 2026 23:59:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795910385; bh=Jfv3MMg/O7UN8A+W1NHYimNXqqAkPIDpKwh6yDT3Yps=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UmKlIVDjf5e3TnRuLyOjEkbtY07KXJAuvSGy3cdmxifiLbqUfI0SElxmg7R42ZwuM vfZhzfyRHWQQeZhqqnJskYFo+rbhkyOfjods1+yk5N9PSfgtOPSy61xO2Oc/0UY0cn 96RIifKUptrVGNgmlJKr72D9UwIltT2DTudEPkV1frSK+y3ABWogn8GF/WwnlJrz03 Jk0bnn0b0kbg7wBtIqZ9xUAUk9C7d8SGE2JW8CUEnwfIK4SPNlxfTa4Jju6mPIb9Za oUS1OSithn/uf2a6FRBHOdQTRhwXDAcpcSng76FfTZl+82C4OwKlYwzEqVcJ36R5GN B6L6h3dFuWZhA== 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-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 , Andy Lutomirski , Arnd Bergmann , Christian Brauner , David Howells , Eric Biggers , Georgia Garcia , Giuseppe Scrivano , Hugh Dickins , James Morris , Jan Kara , Jeff Layton , John Johansen , Jonathan Corbet , Josef Bacik , Kees Cook , KP Singh , Lennart Poettering , Matt Bobrowski , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Neal Gompa , Oleg Nesterov , Paul Moore , Pavel Tikhomirov , Serge Hallyn , Shuah Khan , Stephen Smalley , Zygmunt Krynicki Subject: [RFC PATCH v8 21/29] proc: Implement ->set_userland() fs_context operation Date: Sun, 29 Nov 2026 01:58:00 +0200 Message-ID: <20261128235808.2369970-22-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261128235808.2369970-1-jarkko@kernel.org> References: <20261128235808.2369970-1-jarkko@kernel.org> X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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_USERLAND and leaving the context attached to the caller's PID namespace. Wire up proc_set_userland() to verify that the target userland'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_USERLAND_MOUNT. Co-developed-by: David Howells Signed-off-by: David Howells Signed-off-by: Jarkko Sakkinen --- fs/proc/root.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/fs/proc/root.c b/fs/proc/root.c index 7fbbe92bf73a..e61b1a559172 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include #include @@ -206,6 +208,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->userland_bound) { + errorfc(fc, "cannot override pidns on userland-bound procfs"); + return -EBUSY; + } err = proc_parse_pidns_param(fc, param, &result); if (err) return err; @@ -323,6 +329,21 @@ static int proc_get_tree(struct fs_context *fc) return get_tree_nodev(fc, proc_fill_super); } +static int proc_set_userland(struct fs_context *fc, struct userland *userland) +{ + struct proc_fs_context *ctx = fc->fs_private; + struct pid_namespace *target = userland->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 +355,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_userland = proc_set_userland, .get_tree = proc_get_tree, .reconfigure = proc_reconfigure, }; @@ -371,7 +393,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_USERLAND_MOUNT | + FS_USERNS_MOUNT_RESTRICTED | + FS_DISALLOW_NOTIFY_PERM, }; void __init proc_root_init(void) -- 2.47.3