locktorture: Invoke synchronize_rcu() before rcu_barrier() in chain cleanup phase
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 CPUBcall_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() returnkfree(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
@@ -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