mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] refscale: Fix possible oops in the typesafe_cleanup()
@ 2026-11-20 10:04 Zqiang
  2026-11-20 10:04 ` [PATCH] rcuscale: Handle cur_ops->init() failures for srcu testing Zqiang
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Zqiang @ 2026-11-20 10:04 UTC (permalink / raw)
  To: paulmck, frederic, neeraj.upadhyay, joelagnelf, urezki, boqun
  Cc: qiang.zhang, rcu, linux-kernel

If typesafe_alloc_one() fails partway through populating rtsarray[],
the typesafe_init() returns false but leaves rtsarray_size set to the
full requested count.  The unwind path then calls typesafe_cleanup(),
which loops over rtsarray_size and passes the NULL pointer to the
kmem_cache_free(). unlike kfree(), kmem_cache_free() does not accept
a NULL pointer, this will cause oops.

This commit set rtsarray_size to the number of successfully allocated
elements before returning false, so that typesafe_cleanup() only frees
the objects that were actually allocated.

Signed-off-by: Zqiang <qiang.zhang@linux.dev>
---
 kernel/rcu/refscale.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/rcu/refscale.c b/kernel/rcu/refscale.c
index 4157774f01ca..0843bff9c3da 100644
--- a/kernel/rcu/refscale.c
+++ b/kernel/rcu/refscale.c
@@ -1143,8 +1143,10 @@ static bool typesafe_init(void)
 		return false;
 	for (idx = 0; idx < rtsarray_size; idx++) {
 		rtsarray[idx] = typesafe_alloc_one();
-		if (!rtsarray[idx])
+		if (!rtsarray[idx]) {
+			rtsarray_size = idx;
 			return false;
+		}
 	}
 	if (cur_ops == &typesafe_ref_ops) {
 		rts_acquire = typesafe_ref_acquire;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-20 10:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 10:04 [PATCH] refscale: Fix possible oops in the typesafe_cleanup() Zqiang
2026-11-20 10:04 ` [PATCH] rcuscale: Handle cur_ops->init() failures for srcu testing Zqiang
2026-11-20 10:04 ` [PATCH] rcuscale: Disable gp_exp when cur_ops->exp_completed is not implemented Zqiang
2026-11-20 10:04 ` [PATCH] rcuscale: Invoke cur_ops->cleanup() in kfree_scale_cleanup() Zqiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®