[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <690dc683.a70a0220.22f260.0033.GAE@google.com>
Date: Fri, 07 Nov 2025 02:14:27 -0800
From: syzbot <syzbot+0b2e79f91ff6579bfa5b@...kaller.appspotmail.com>
To: linux-kernel@...r.kernel.org, syzkaller-bugs@...glegroups.com
Subject: Forwarded: [PATCH] fs/nsfs: skip dropping active refs on initial namespaces
For archival purposes, forwarding an incoming command email to
linux-kernel@...r.kernel.org, syzkaller-bugs@...glegroups.com.
***
Subject: [PATCH] fs/nsfs: skip dropping active refs on initial namespaces
Author: kartikey406@...il.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
Initial namespaces (init_net, init_uts_ns, init_ipc_ns, etc.) are
statically allocated and exist for the entire lifetime of the system.
They should never go through the normal namespace cleanup and release
paths.
When setns() is called with a file descriptor pointing to an initial
namespace, the kernel creates a temporary nsproxy structure during the
operation. In the cleanup path, nsproxy_ns_active_put() was blindly
dropping active references on all namespaces in the nsproxy, including
initial namespaces. This caused the active reference count on initial
namespaces to hit zero, triggering a WARNING in __ns_ref_active_put().
The WARNING fired because when an active reference count reaches zero,
the code path assumes the namespace is being released, which should
never happen for initial namespaces.
Fix this by checking if each namespace is an initial namespace before
dropping its active reference in nsproxy_ns_active_put(). Initial
namespaces are skipped, preventing their active reference counts from
incorrectly reaching zero.
Reported-by: syzbot+0b2e79f91ff6579bfa5b@...kaller.appspotmail.com
Signed-off-by: Deepanshu Kartikey <kartikey406@...il.com>
---
fs/nsfs.c | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/fs/nsfs.c b/fs/nsfs.c
index ba6c8975c82e..ffe31c66d1d8 100644
--- a/fs/nsfs.c
+++ b/fs/nsfs.c
@@ -19,6 +19,7 @@
#include <linux/exportfs.h>
#include <linux/nstree.h>
#include <net/net_namespace.h>
+#include <linux/ns_common.h>
#include "mount.h"
#include "internal.h"
@@ -698,12 +699,20 @@ void nsproxy_ns_active_get(struct nsproxy *ns)
void nsproxy_ns_active_put(struct nsproxy *ns)
{
- ns_ref_active_put(ns->mnt_ns);
- ns_ref_active_put(ns->uts_ns);
- ns_ref_active_put(ns->ipc_ns);
- ns_ref_active_put(ns->pid_ns_for_children);
- ns_ref_active_put(ns->cgroup_ns);
- ns_ref_active_put(ns->net_ns);
- ns_ref_active_put(ns->time_ns);
- ns_ref_active_put(ns->time_ns_for_children);
+ if (ns->mnt_ns && !is_initial_namespace(&ns->mnt_ns->ns))
+ ns_ref_active_put(ns->mnt_ns);
+ if (ns->uts_ns && !is_initial_namespace(&ns->uts_ns->ns))
+ ns_ref_active_put(ns->uts_ns);
+ if (ns->ipc_ns && !is_initial_namespace(&ns->ipc_ns->ns))
+ ns_ref_active_put(ns->ipc_ns);
+ if (ns->pid_ns_for_children && !is_initial_namespace(&ns->pid_ns_for_children->ns))
+ ns_ref_active_put(ns->pid_ns_for_children);
+ if (ns->cgroup_ns && !is_initial_namespace(&ns->cgroup_ns->ns))
+ ns_ref_active_put(ns->cgroup_ns);
+ if (ns->net_ns && !is_initial_namespace(&ns->net_ns->ns))
+ ns_ref_active_put(ns->net_ns);
+ if (ns->time_ns && !is_initial_namespace(&ns->time_ns->ns))
+ ns_ref_active_put(ns->time_ns);
+ if (ns->time_ns_for_children && !is_initial_namespace(&ns->time_ns_for_children->ns))
+ ns_ref_active_put(ns->time_ns_for_children);
}
--
2.43.0
Powered by blists - more mailing lists