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=1795030553; b=dmm+i4H7HkfwT1vA7SXOyHTHGD4H94D52ob5yxkHeIxiwp47iEk3c7j6K9VJeCt+LF6n 8NNpNO/VkbWk41mVS2VoRQ3msx/Sz6Y/NjN2rjOEEdOJ6tH7i7hju1GrF/ZJ6jH6YdMYA 6/k3CeXuz3mQao1MhcFc3vjZLy7vGo9JiJfnaZvjMZ3jOS+0fGTReZzleS4Ww8d9dIFDx xcm5O9mq1HVdt9TthwTXa+m7AzLaG5G6MkEzmb618lMlfJz+V3g0XzlxRNYQ9BvvLuzR9 X3XUezYN6u/JsvjcNxg2/R5VvaJq1V6uKp3kioGCa+b51RNFo8yOZFcVb14bIevxKCQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795030553; 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=1FQ+3wraTu9FOJG/QJcv4lFHDW8iXZDCDeRcHKp4RxD66veJnhhXuWzpyCjHBXldm7UE KoxiMI/33AGbOE20N63S/rqG4JVQvkgVXQORtK9lKnrh0ASu/QxvNmWaRr58YgB3aBXXT b1KohigppgBqoOkwfxll5Vex/0aRItQb35svSDt+G0WCiiDFTBIHSwu1nK1dKfzeV+jTB agTnIyFD/rvNC1+YZ6CspbwN5yC+q8JRrWELqNq0J0TBTSlRPGaC221WCz0X+9207v34M jIQE2shLfr3pEsXk74P438qd+myJ+q+xD7InJSl2wk3qtHfL7nfedAxPTGWl8KrmqqA== 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=KALLz5Qa; 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 37F8E606C733; Wed, 18 Nov 2026 19:35: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=KALLz5Qa Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 4E14C1F000C5; Wed, 18 Nov 2026 19:35:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795030553; bh=glmqSz2x+APivEM/vonQfanbbokAEU7WMuncz0VaekQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KALLz5Qa0xo3dgf99GmRRZI3kaXuy8ffj4AmAdcU6IUpWIq9o3rJJAOa3KO1QLHf6 NpCGxHjvUkHYpFYFOwe7r8EmoMvyoii7KdbfVvpsdRmdJCN7gzqbdLyJetSXjpazad rV7VL2mi62IgF4UfZFFyUyqRJX62aHEsor7d1ysyF+ZUljeYc4TNbgwW23x6IkUt81 WII7huMAnZanX3DAoBqQG3DHHvM6NewgJzyGKOjWYXPalKsXW6Bcc4PjXsc2KmwpH3 XT/ZbYek13JAfQwElU+R7POwev1fR0Dwuh5tNvHt59bpG3JgQLr/tuwHDp1VGxel3g hG51CZ1+fgxjA== From: Jarkko Sakkinen To: David Howells Cc: Jarkko Sakkinen , linux-api@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, Alexander Viro , Andrew Morton , Andy Lutomirski , Anna-Maria Behnsen , Ben Segall , Christian Brauner , David Hildenbrand , Davidlohr Bueso , Dietmar Eggemann , Frederic Weisbecker , Ingo Molnar , Jan Kara , John Johansen , 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 , Thomas Gleixner , Valentin Schneider , Vincent Guittot , Vincenzo Frascino , Vlastimil Babka , Zygmunt Krynicki Subject: [RFC PATCH v3 01/13] nsproxy: Pass nsproxy to create_new_namespaces() Date: Wed, 18 Nov 2026 21:35:27 +0200 Message-ID: <20261118193539.240065-2-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261118193539.240065-1-jarkko@kernel.org> References: <20261118193539.240065-1-jarkko@kernel.org> X-Mailing-List: linux-api@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