Commit 8f91efd
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: 461daba ("psi: eliminate kthread_worker from psi trigger scheduling mechanism")
Co-developed-by: ziwei.dai <ziwei.dai@unisoc.com>
Signed-off-by: ziwei.dai <ziwei.dai@unisoc.com>
Co-developed-by: ke.wang <ke.wang@unisoc.com>
Signed-off-by: ke.wang <ke.wang@unisoc.com>
Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Link: https://lkml.kernel.org/r/1623371374-15664-1-git-send-email-huangzhaoyang@gmail.com1 parent f418371 commit 8f91efd
1 file changed
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| 185 | + | |
| 186 | + | |
185 | 187 | | |
186 | 188 | | |
187 | 189 | | |
| |||
201 | 203 | | |
202 | 204 | | |
203 | 205 | | |
| 206 | + | |
| 207 | + | |
204 | 208 | | |
205 | 209 | | |
206 | 210 | | |
| |||
1157 | 1161 | | |
1158 | 1162 | | |
1159 | 1163 | | |
1160 | | - | |
1161 | 1164 | | |
1162 | | - | |
1163 | 1165 | | |
1164 | 1166 | | |
1165 | 1167 | | |
| |||
1211 | 1213 | | |
1212 | 1214 | | |
1213 | 1215 | | |
| 1216 | + | |
1214 | 1217 | | |
1215 | 1218 | | |
1216 | 1219 | | |
| |||
1223 | 1226 | | |
1224 | 1227 | | |
1225 | 1228 | | |
1226 | | - | |
| 1229 | + | |
1227 | 1230 | | |
1228 | 1231 | | |
1229 | 1232 | | |
1230 | 1233 | | |
1231 | 1234 | | |
1232 | 1235 | | |
1233 | | - | |
1234 | | - | |
1235 | 1236 | | |
1236 | | - | |
1237 | 1237 | | |
1238 | 1238 | | |
1239 | 1239 | | |
| |||
0 commit comments