]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
sched: Fix pick_next_task_fair() vs try_to_wake_up() race
authorPeter Zijlstra <peterz@infradead.org>
Wed, 23 Oct 2024 09:36:41 +0000 (11:36 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 23 Oct 2024 18:52:26 +0000 (20:52 +0200)
commitb55945c500c5723992504aa03b362fab416863a6
treea69e8e10526175d716041f0ce09e5e14030f6c57
parent42f7652d3eb527d03665b09edac47f85fb600924
sched: Fix pick_next_task_fair() vs try_to_wake_up() race

Syzkaller robot reported KCSAN tripping over the
ASSERT_EXCLUSIVE_WRITER(p->on_rq) in __block_task().

The report noted that both pick_next_task_fair() and try_to_wake_up()
were concurrently trying to write to the same p->on_rq, violating the
assertion -- even though both paths hold rq->__lock.

The logical consequence is that both code paths end up holding a
different rq->__lock. And looking through ttwu(), this is possible
when the __block_task() 'p->on_rq = 0' store is visible to the ttwu()
'p->on_rq' load, which then assumes the task is not queued and
continues to migrate it.

Rearrange things such that __block_task() releases @p with the store
and no code thereafter will use @p again.

Fixes: 152e11f6df29 ("sched/fair: Implement delayed dequeue")
Reported-by: syzbot+0ec1e96c2cdf5c0e512a@syzkaller.appspotmail.com
Reported-by: Kent Overstreet <kent.overstreet@linux.dev>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Marco Elver <elver@google.com>
Link: https://lkml.kernel.org/r/20241023093641.GE16066@noisy.programming.kicks-ass.net
kernel/sched/fair.c
kernel/sched/sched.h