[PATCH] locktorture: Invoke synchronize_rcu() before rcu_barrier() in chain cleanup phase
From: Zqiang
Date: Thu Nov 26 2026 - 03:42:56 EST
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@xxxxxxxxx>
---
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