From: Zqiang <qiang.zhang@linux.dev>
To: dave@stgolabs.net, paulmck@kernel.org, josh@joshtriplett.org,
jfern@kernel.org
Cc: linux-kernel@vger.kernel.org, qiang.zhang@linux.dev
Subject: [PATCH] locktorture: Invoke synchronize_rcu() before rcu_barrier() in chain cleanup phase
Date: Thu, 26 Nov 2026 16:42:49 +0800 [thread overview]
Message-ID: <20261126084249.17746-1-qiang.zhang@linux.dev> (raw)
A currently-executing chain callback can read the old crc_stop=false and
re-enqueues itself via call_rcu() only after rcu_barrier() has been
inserted barrier callback. the late callback is invisible to rcu_barrier(),
so kfree() races with loading the freed crcp->crc_stop:
CPUA CPUB
call_rcu_chain_cleanup() rcu callback run:
call_rcu_chain_cb()
->smp_load_acquire(crc_stop) is false
->smp_store_release(crc_stop, true)
->rcu_barrier() start
->call_rcu() after rcu_barrier() start
and rcu_barrier() miss this rcu callback
->rcu_barrier() return
kfree(chain_list)
call_rcu_chain_cb() run again and
load crcp->crc_stop //UAF
This commit add a synchronize_rcu() between the flag store and rcu_barrier(),
it makes crcp->crc_stop visible on all CPUs once the RCU grace period has
elapsed and also wait any in-flight rcu callback to re-enqueue before it
completes. so rcu_barrier() can see and waits for that last callback complete
before kfree().
Signed-off-by: Zqiang <qiang.zhang@linux.dev>
---
kernel/locking/locktorture.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
index e618bcf75e2d..665fa79c93e6 100644
--- a/kernel/locking/locktorture.c
+++ b/kernel/locking/locktorture.c
@@ -1148,6 +1148,7 @@ static void call_rcu_chain_cleanup(void)
return;
for (i = 0; i < call_rcu_chains; i++)
smp_store_release(&call_rcu_chain_list[i].crc_stop, true);
+ synchronize_rcu();
rcu_barrier();
kfree(call_rcu_chain_list);
call_rcu_chain_list = NULL;
--
2.17.1
reply other threads:[~2026-11-26 8:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261126084249.17746-1-qiang.zhang@linux.dev \
--to=qiang.zhang@linux.dev \
--cc=dave@stgolabs.net \
--cc=jfern@kernel.org \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
/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 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®