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=1794892133; b=QtUg8hB63eeYAsm2RYhxvi23INEMIMvv7XkvKPiM9BNDWKnA2VW65cN1kmtyLidd9cpk 2hGZ6Z8S7rY1jPRXORWVTootdEfdO306PdFW2a1wciGjEm/qE3wd39hlyZdvBj4E2gI+v 8K6gLoi3TTXD7PWz3zWRZi6R1RoQ4duUg2UoxHxEKESlzqup0ozS3c8maDbya4cJrSdHI QGvyWKeGdmdnijuRKmo/BYDqp+6zJCLMX32W0XDBFQXloVuW20AvrFfZOGBpeFOfALElS R7DzMpFAzYZ6oudk80rZiJPmyS4Bhvje8bkoJTyQMcMgx7PqTik9Te2N8dRbTWKj2jA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794892133; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=glmqSz2x+APivEM/vonQfanbbokAEU7WMuncz0VaekQ=; b=1ZdczRE8EndBwNvu8dnnefluNQgzd81IKreuqjHscw/ZYmLnErhrjBzbYdSaz/k3NIKh Gf4WJRFX2wO2SlH+WtEJKoaXzmde3ruxIgshW/aE/0rM6WXARd5vUZtZLGKvcZDCvmqH9 9a6RCctxvkNrlYO02ibk6kF1aEd0VLs6co71U0AKSZm30ixWCLz867/UNQt2OzbsQuU3J VCaxcIKdLKVCZmTWUljyS3BHDRyVvZcQ+0q6eEKQt12+npabJIhxm05hMMqn2CyfLJSTK QvI0wGRtW7CFUGbSp30CdmVueO67DJH/KRqRcsKHcMgBJ+dcytARR3hJHE3rRJQACSQ== 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="He/O1Yy/"; 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 80ABD606A31C; Tue, 17 Nov 2026 05:08:53 +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=He/O1Yy/ Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 805E41F000D0; Tue, 17 Nov 2026 05:08:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794892133; bh=glmqSz2x+APivEM/vonQfanbbokAEU7WMuncz0VaekQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=He/O1Yy/L1j4ZozAOzPbkeszipcs7RRuCmyVSYaTq1BV8Vc4qKurtvkhGG1pB/OlG mLeqBxCxgNnmeuDokGWvChBtutsb91igoC8oLr9iLqqT/dJd04LRFqoLY8w+cyu8UA eAmMHro8YjtWx+oxikakHiHu5BTsPyM4LEE5/rhTqB8ZWmorfH1b1NDRdwkhc6ErHM zB0SW7daDGcT4TAv4MrjBiu+fV5epwkyhapDN/tIkFi4FLBSgnxlmHWkE9sSzIdHb2 ASadzctJObrLmyKpZo7ANrbXur2n+ApSLe5h9eMVHrMcXamrWisU+qB4q40/TcjWqn iw2iC7INnWbVg== From: Jarkko Sakkinen To: linux-fsdevel@vger.kernel.org Cc: Jarkko Sakkinen , linux-api@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, Alexander Viro , Andrew Morton , Ben Segall , Christian Brauner , David Hildenbrand , David Howells , Davidlohr Bueso , Dietmar Eggemann , Ingo Molnar , Jan Kara , Jonathan Corbet , Juri Lelli , Kees Cook , K Prateek Nayak , "Liam R. Howlett" , Lorenzo Stoakes , Manfred Spraul , Mel Gorman , Michal Hocko , Mike Rapoport , Neal Gompa , Paul Moore , Pavel Tikhomirov , Peter Zijlstra , Randy Dunlap , Serge Hallyn , Shuah Khan , Steven Rostedt , Suren Baghdasaryan , Valentin Schneider , Vincent Guittot , Vlastimil Babka Subject: [RFC PATCH 01/13] nsproxy: Pass nsproxy to create_new_namespaces() Date: Tue, 17 Nov 2026 07:08:29 +0200 Message-ID: <20261117050841.3289652-2-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261117050841.3289652-1-jarkko@kernel.org> References: <20261117050841.3289652-1-jarkko@kernel.org> X-Mailing-List: linux-kernel@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 create_new_namespaces() takes a struct task_struct pointer even though it only reads tsk->nsproxy, preventing callers outside kernel/nsproxy.c from constructing a child nsproxy without mutating a task. Expose create_new_namespaces() and pass the source struct nsproxy pointer directly so root namespace creation can allocate a detached namespace set from current->nsproxy. Co-developed-by: David Howells Signed-off-by: David Howells Signed-off-by: Jarkko Sakkinen --- include/linux/nsproxy.h | 5 +++++ kernel/nsproxy.c | 32 ++++++++++++++++---------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/include/linux/nsproxy.h b/include/linux/nsproxy.h index dc2447f5f092..cacbbbe3f1ce 100644 --- a/include/linux/nsproxy.h +++ b/include/linux/nsproxy.h @@ -12,6 +12,7 @@ struct ipc_namespace; struct pid_namespace; struct cgroup_namespace; struct fs_struct; +struct user_namespace; /* * A structure to contain pointers to all per-process @@ -92,6 +93,10 @@ static inline struct cred *nsset_cred(struct nsset *set) * */ +struct nsproxy *create_new_namespaces(u64 flags, + struct nsproxy *ns, + struct user_namespace *user_ns, + struct fs_struct *new_fs); int copy_namespaces(u64 flags, struct task_struct *tsk); void switch_cred_namespaces(const struct cred *old, const struct cred *new); void exit_nsproxy_namespaces(struct task_struct *tsk); diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c index 2dcf105e8ee2..8a3c6d4e94e2 100644 --- a/kernel/nsproxy.c +++ b/kernel/nsproxy.c @@ -85,9 +85,10 @@ void deactivate_nsproxy(struct nsproxy *ns) * Return the newly created nsproxy. Do not attach this to the task, * leave it to the caller to do proper locking and attach it to task. */ -static struct nsproxy *create_new_namespaces(u64 flags, - struct task_struct *tsk, struct user_namespace *user_ns, - struct fs_struct *new_fs) +struct nsproxy *create_new_namespaces(u64 flags, + struct nsproxy *ns, + struct user_namespace *user_ns, + struct fs_struct *new_fs) { struct nsproxy *new_nsp; int err; @@ -96,52 +97,51 @@ static struct nsproxy *create_new_namespaces(u64 flags, if (!new_nsp) return ERR_PTR(-ENOMEM); - new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, - user_ns, new_fs); + new_nsp->mnt_ns = copy_mnt_ns(flags, ns->mnt_ns, user_ns, new_fs); if (IS_ERR(new_nsp->mnt_ns)) { err = PTR_ERR(new_nsp->mnt_ns); goto out_ns; } - new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns); + new_nsp->uts_ns = copy_utsname(flags, user_ns, ns->uts_ns); if (IS_ERR(new_nsp->uts_ns)) { err = PTR_ERR(new_nsp->uts_ns); goto out_uts; } - new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns); + new_nsp->ipc_ns = copy_ipcs(flags, user_ns, ns->ipc_ns); if (IS_ERR(new_nsp->ipc_ns)) { err = PTR_ERR(new_nsp->ipc_ns); goto out_ipc; } new_nsp->pid_ns_for_children = - copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns_for_children); + copy_pid_ns(flags, user_ns, ns->pid_ns_for_children); if (IS_ERR(new_nsp->pid_ns_for_children)) { err = PTR_ERR(new_nsp->pid_ns_for_children); goto out_pid; } new_nsp->cgroup_ns = copy_cgroup_ns(flags, user_ns, - tsk->nsproxy->cgroup_ns); + ns->cgroup_ns); if (IS_ERR(new_nsp->cgroup_ns)) { err = PTR_ERR(new_nsp->cgroup_ns); goto out_cgroup; } - new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns); + new_nsp->net_ns = copy_net_ns(flags, user_ns, ns->net_ns); if (IS_ERR(new_nsp->net_ns)) { err = PTR_ERR(new_nsp->net_ns); goto out_net; } new_nsp->time_ns_for_children = copy_time_ns(flags, user_ns, - tsk->nsproxy->time_ns_for_children); + ns->time_ns_for_children); if (IS_ERR(new_nsp->time_ns_for_children)) { err = PTR_ERR(new_nsp->time_ns_for_children); goto out_time; } - new_nsp->time_ns = get_time_ns(tsk->nsproxy->time_ns); + new_nsp->time_ns = get_time_ns(ns->time_ns); return new_nsp; @@ -192,7 +192,7 @@ int copy_namespaces(u64 flags, struct task_struct *tsk) (CLONE_NEWIPC | CLONE_SYSVSEM)) return -EINVAL; - new_ns = create_new_namespaces(flags, tsk, user_ns, tsk->fs); + new_ns = create_new_namespaces(flags, tsk->nsproxy, user_ns, tsk->fs); if (IS_ERR(new_ns)) return PTR_ERR(new_ns); @@ -231,7 +231,7 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags, flags |= CLONE_EMPTY_MNTNS; } - *new_nsp = create_new_namespaces(flags, current, user_ns, + *new_nsp = create_new_namespaces(flags, current->nsproxy, user_ns, new_fs ? new_fs : current->fs); if (IS_ERR(*new_nsp)) { err = PTR_ERR(*new_nsp); @@ -289,7 +289,7 @@ int exec_task_namespaces(void) if (tsk->nsproxy->time_ns_for_children == tsk->nsproxy->time_ns) return 0; - new = create_new_namespaces(0, tsk, current_user_ns(), tsk->fs); + new = create_new_namespaces(0, tsk->nsproxy, current_user_ns(), tsk->fs); if (IS_ERR(new)) return PTR_ERR(new); @@ -356,7 +356,7 @@ static int prepare_nsset(unsigned flags, struct nsset *nsset) struct task_struct *me = current; nsset->flags = flags; - nsset->nsproxy = create_new_namespaces(0, me, current_user_ns(), me->fs); + nsset->nsproxy = create_new_namespaces(0, me->nsproxy, current_user_ns(), me->fs); if (IS_ERR(nsset->nsproxy)) return PTR_ERR(nsset->nsproxy); -- 2.47.3