Files
linux/kernel
Zhaoyang Huang 8f91efd870 psi: Fix race between psi_trigger_create/destroy
Race detected between psi_trigger_destroy/create as shown below, which
cause panic by accessing invalid psi_system->poll_wait->wait_queue_entry
and psi_system->poll_timer->entry->next. Under this modification, the
race window is removed by initialising poll_wait and poll_timer in
group_init which are executed only once at beginning.

  psi_trigger_destroy()                   psi_trigger_create()

  mutex_lock(trigger_lock);
  rcu_assign_pointer(poll_task, NULL);
  mutex_unlock(trigger_lock);
					  mutex_lock(trigger_lock);
					  if (!rcu_access_pointer(group->poll_task)) {
					    timer_setup(poll_timer, poll_timer_fn, 0);
					    rcu_assign_pointer(poll_task, task);
					  }
					  mutex_unlock(trigger_lock);

  synchronize_rcu();
  del_timer_sync(poll_timer); <-- poll_timer has been reinitialized by
                                  psi_trigger_create()

So, trigger_lock/RCU correctly protects destruction of
group->poll_task but misses this race affecting poll_timer and
poll_wait.

Fixes: 461daba06b ("psi: eliminate kthread_worker from psi trigger scheduling mechanism")
Co-developed-by: ziwei.dai <[email protected]>
Signed-off-by: ziwei.dai <[email protected]>
Co-developed-by: ke.wang <[email protected]>
Signed-off-by: ke.wang <[email protected]>
Signed-off-by: Zhaoyang Huang <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Reviewed-by: Suren Baghdasaryan <[email protected]>
Acked-by: Johannes Weiner <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
2021-06-24 09:07:50 +02:00
..
2021-06-18 11:43:09 +02:00
2021-06-18 11:43:09 +02:00
2021-06-18 11:43:07 +02:00
2021-06-18 11:43:09 +02:00
2021-04-08 19:37:21 +02:00
2021-06-18 11:43:09 +02:00
2021-03-24 12:11:48 -04:00
…
2021-04-08 16:04:20 -07:00
…
…
…
2021-05-06 19:24:11 -07:00
…
…
2021-06-18 11:43:09 +02:00
2021-06-18 11:43:08 +02:00
2021-06-18 11:43:09 +02:00
…
…
2021-05-07 00:26:33 -07:00
…
2021-06-18 11:43:09 +02:00
…
2020-11-14 11:26:04 -08:00
2021-06-18 11:43:09 +02:00
…
2020-12-01 10:30:28 +00:00
2021-06-18 11:43:07 +02:00
…
2021-06-18 11:43:07 +02:00
2021-05-12 11:43:31 +02:00
2021-02-09 12:27:29 -05:00
…
…
…
2021-05-07 00:26:34 -07:00
…
…