From: Zqiang <qiang.zhang@linux.dev>
To: paulmck@kernel.org, frederic@kernel.org,
neeraj.upadhyay@kernel.org, joelagnelf@nvidia.com,
urezki@gmail.com, boqun@kernel.org
Cc: qiang.zhang@linux.dev, rcu@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] refscale: Fix possible oops in the typesafe_cleanup()
Date: Fri, 20 Nov 2026 18:04:50 +0800 [thread overview]
Message-ID: <20261120100453.5826-1-qiang.zhang@linux.dev> (raw)
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
next reply other threads:[~2026-11-20 10:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 10:04 Zqiang [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120100453.5826-1-qiang.zhang@linux.dev \
--to=qiang.zhang@linux.dev \
--cc=boqun@kernel.org \
--cc=frederic@kernel.org \
--cc=joelagnelf@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=neeraj.upadhyay@kernel.org \
--cc=paulmck@kernel.org \
--cc=rcu@vger.kernel.org \
--cc=urezki@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.