Skip to contentSkip to conversation

locktorture: Invoke synchronize_rcu() before rcu_barrier() in chain cleanup phase

PATCH New Zqiang 1 participant 1 message Nov 26 Torture-test modules

lore
Share & tools
lore

Zqiang

author
#0 lore raw

PATCH 1/1 locktorture: Invoke synchronize_rcu() before rcu_barrier() in chain cleanup phase

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().

---
 kernel/locking/locktorture.c | 1 +
 1 file changed, 1 insertion(+)
kernel/locking/locktorture.c +1 -0
index e618bcf75e2d..665fa79c93e6 100644
@@ -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;
Signature · 1 line
2.17.1