Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ns: add asserts for initial namespace reference counts

They always remain fixed at one. Notice when that assumptions is broken.

Link: https://patch.msgid.link/20251110-work-namespace-nstree-fixes-v1-13-e8a9264e0fb9@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>

+17 -9
+17 -9
include/linux/ns_common.h
··· 60 60 return atomic_read(&ns->__ns_ref_active); 61 61 } 62 62 63 + static __always_inline __must_check int __ns_ref_read(const struct ns_common *ns) 64 + { 65 + return refcount_read(&ns->__ns_ref); 66 + } 67 + 63 68 static __always_inline __must_check bool __ns_ref_put(struct ns_common *ns) 64 69 { 65 - if (is_ns_init_id(ns)) 70 + if (is_ns_init_id(ns)) { 71 + VFS_WARN_ON_ONCE(__ns_ref_read(ns) != 1); 66 72 return false; 73 + } 67 74 if (refcount_dec_and_test(&ns->__ns_ref)) { 68 75 VFS_WARN_ON_ONCE(__ns_ref_active_read(ns)); 69 76 return true; ··· 80 73 81 74 static __always_inline __must_check bool __ns_ref_get(struct ns_common *ns) 82 75 { 83 - if (is_ns_init_id(ns)) 76 + if (is_ns_init_id(ns)) { 77 + VFS_WARN_ON_ONCE(__ns_ref_read(ns) != 1); 84 78 return true; 79 + } 85 80 if (refcount_inc_not_zero(&ns->__ns_ref)) 86 81 return true; 87 82 VFS_WARN_ON_ONCE(__ns_ref_active_read(ns)); 88 83 return false; 89 84 } 90 85 91 - static __always_inline __must_check int __ns_ref_read(const struct ns_common *ns) 92 - { 93 - return refcount_read(&ns->__ns_ref); 94 - } 95 - 96 86 static __always_inline void __ns_ref_inc(struct ns_common *ns) 97 87 { 98 - if (is_ns_init_id(ns)) 88 + if (is_ns_init_id(ns)) { 89 + VFS_WARN_ON_ONCE(__ns_ref_read(ns) != 1); 99 90 return; 91 + } 100 92 refcount_inc(&ns->__ns_ref); 101 93 } 102 94 103 95 static __always_inline __must_check bool __ns_ref_dec_and_lock(struct ns_common *ns, 104 96 spinlock_t *ns_lock) 105 97 { 106 - if (is_ns_init_id(ns)) 98 + if (is_ns_init_id(ns)) { 99 + VFS_WARN_ON_ONCE(__ns_ref_read(ns) != 1); 107 100 return false; 101 + } 108 102 return refcount_dec_and_lock(&ns->__ns_ref, ns_lock); 109 103 } 110 104