[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251109-namespace-6-19-fixes-v1-6-ae8a4ad5a3b3@kernel.org>
Date: Sun, 09 Nov 2025 22:11:27 +0100
From: Christian Brauner <brauner@...nel.org>
To: linux-fsdevel@...r.kernel.org, Josef Bacik <josef@...icpanda.com>,
Jeff Layton <jlayton@...nel.org>
Cc: Jann Horn <jannh@...gle.com>, Mike Yuan <me@...dnzj.com>,
Zbigniew Jędrzejewski-Szmek <zbyszek@...waw.pl>,
Lennart Poettering <mzxreary@...inter.de>,
Daan De Meyer <daan.j.demeyer@...il.com>, Aleksa Sarai <cyphar@...har.com>,
Amir Goldstein <amir73il@...il.com>, Tejun Heo <tj@...nel.org>,
Johannes Weiner <hannes@...xchg.org>, Thomas Gleixner <tglx@...utronix.de>,
Alexander Viro <viro@...iv.linux.org.uk>, Jan Kara <jack@...e.cz>,
linux-kernel@...r.kernel.org, cgroups@...r.kernel.org, bpf@...r.kernel.org,
Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>,
netdev@...r.kernel.org, Arnd Bergmann <arnd@...db.de>,
Christian Brauner <brauner@...nel.org>
Subject: [PATCH 6/8] ns: add asserts for active refcount underflow
Add a few more assert to detect active reference count underflows.
Signed-off-by: Christian Brauner <brauner@...nel.org>
---
include/linux/ns_common.h | 1 -
kernel/nscommon.c | 18 ++++++++++++++----
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/include/linux/ns_common.h b/include/linux/ns_common.h
index 3aaba2ca31d7..66ea09b48377 100644
--- a/include/linux/ns_common.h
+++ b/include/linux/ns_common.h
@@ -294,7 +294,6 @@ void __ns_ref_active_put(struct ns_common *ns);
static __always_inline struct ns_common *__must_check ns_get_unless_inactive(struct ns_common *ns)
{
- VFS_WARN_ON_ONCE(__ns_ref_active_read(ns) && !__ns_ref_read(ns));
if (!__ns_ref_active_read(ns)) {
VFS_WARN_ON_ONCE(is_ns_init_id(ns));
return NULL;
diff --git a/kernel/nscommon.c b/kernel/nscommon.c
index bfd2d6805776..c910b979e433 100644
--- a/kernel/nscommon.c
+++ b/kernel/nscommon.c
@@ -170,8 +170,10 @@ void __ns_ref_active_put(struct ns_common *ns)
if (is_ns_init_id(ns))
return;
- if (!atomic_dec_and_test(&ns->__ns_ref_active))
+ if (!atomic_dec_and_test(&ns->__ns_ref_active)) {
+ VFS_WARN_ON_ONCE(__ns_ref_active_read(ns) < 0);
return;
+ }
VFS_WARN_ON_ONCE(is_ns_init_id(ns));
VFS_WARN_ON_ONCE(!__ns_ref_read(ns));
@@ -181,8 +183,10 @@ void __ns_ref_active_put(struct ns_common *ns)
if (!ns)
return;
VFS_WARN_ON_ONCE(is_ns_init_id(ns));
- if (!atomic_dec_and_test(&ns->__ns_ref_active))
+ if (!atomic_dec_and_test(&ns->__ns_ref_active)) {
+ VFS_WARN_ON_ONCE(__ns_ref_active_read(ns) < 0);
return;
+ }
}
}
@@ -280,12 +284,16 @@ void __ns_ref_active_put(struct ns_common *ns)
*/
void __ns_ref_active_get(struct ns_common *ns)
{
+ int prev;
+
/* Initial namespaces are always active. */
if (is_ns_init_id(ns))
return;
/* If we didn't resurrect the namespace we're done. */
- if (atomic_fetch_add(1, &ns->__ns_ref_active))
+ prev = atomic_fetch_add(1, &ns->__ns_ref_active);
+ VFS_WARN_ON_ONCE(prev < 0);
+ if (likely(prev))
return;
/*
@@ -298,7 +306,9 @@ void __ns_ref_active_get(struct ns_common *ns)
return;
VFS_WARN_ON_ONCE(is_ns_init_id(ns));
- if (atomic_fetch_add(1, &ns->__ns_ref_active))
+ prev = atomic_fetch_add(1, &ns->__ns_ref_active);
+ VFS_WARN_ON_ONCE(prev < 0);
+ if (likely(prev))
return;
}
}
--
2.47.3
Powered by blists - more mailing lists