All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] locktorture: Invoke synchronize_rcu() before rcu_barrier() in chain cleanup phase
@ 2026-11-26  8:42 Zqiang
  0 siblings, 0 replies; only message in thread
From: Zqiang @ 2026-11-26  8:42 UTC (permalink / raw)
  To: dave, paulmck, josh, jfern; +Cc: linux-kernel, qiang.zhang

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-26  8:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  8:42 [PATCH] locktorture: Invoke synchronize_rcu() before rcu_barrier() in chain cleanup phase Zqiang

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.