diff options
| author | Kuba Piecuch <jpiecuch@google.com> | 2026-11-04 11:14:39 +0000 |
|---|---|---|
| committer | Tejun Heo <tj@kernel.org> | 2026-11-05 07:27:17 -1000 |
| commit | 3133107d98057595c0af39ff907c852134926912 (patch) | |
| tree | 602b9a176fb127eaed108c0f8683d8f131fb575a /rust/kernel/alloc/allocator | |
| parent | 4c2e0751d5e6d181a5b9b2a8ada869b5bee66a83 (diff) | |
sched_ext: Read exit_kind before flushing in scx_flush_disable_work()
scx_disable_workfn() sets exit_kind to SCX_EXIT_DONE before it tears the
scheduler down. scx_flush_disable_work() reads exit_kind after syncing
disable_irq_work and flushing disable_work, so it can observe DONE from
a disable_work that was queued after its flush and return while the
teardown is still running:
CPU A CPU B
----- -----
scx_vexit()
scx_claim_exit() -> true
bpf_struct_ops_map_link_detach()
bpf_scx_unreg()
scx_disable()
scx_claim_exit() -> false
scx_flush_disable_work()
irq_work_sync() // not queued
kthread_flush_work() // not queued
irq_work_queue()
scx_disable_irq_workfn()
kthread_queue_work()
scx_disable_workfn()
exit_kind = SCX_EXIT_DONE
scx_root_disable()
atomic_read() -> SCX_EXIT_DONE
bpf_map_put()
Once bpf_scx_unreg() returns, its caller drops the struct_ops map
reference, and the struct_ops trampolines can be freed while
scx_root_disable() is still running and can still call into the BPF
scheduler, e.g. ops.exit().
Read exit_kind before syncing and flushing, with acquire ordering paired
with the atomic_try_cmpxchg() in scx_disable_workfn(). DONE is only set
from disable_work, so once it is observed, the following
kthread_flush_work() sees the queued work and waits for the teardown to
finish.
This patch was created with the help of an AI coding assistant.
Fixes: d99f7a32f09d ("sched_ext: Fix scx_flush_disable_work() UAF race")
Cc: stable@vger.kernel.org # v7.1+
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-195908@kernel.org/
Signed-off-by: Kuba Piecuch <jpiecuch@google.com>
Reviewed-by: Andrea Righi <arighi@nvidia.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'rust/kernel/alloc/allocator')
0 files changed, 0 insertions, 0 deletions
