CVE-2026-139558: sched: Set TIF_NEED_RESCHED before calling __trace_set_need_resched()
In the Linux kernel, the following vulnerability has been resolved:
sched: Set TIFNEEDRESCHED before calling tracesetneedresched()
settskneedresched() tests TIFNEEDRESCHED, calls tracesetneedresched() if the flag is clear, then sets it via settskthreadflag(). A BPF rawtp program attached to schedsetneedresched executes synchronously inside bpftracerun(). On return, bpftracerun() drops the RCU lock with rcureadunlockmigrate(), which on the preempt-or-BH-disabled path calls setneedreschedcurrent() -> settskneedresched() again.
settskthreadflag() follows the tracepoint call, so every re-entrant frame sees TIFNEEDRESCHED clear and calls tracesetneedresched() again:
BUG: TASK stack guard page was hit at ffffc9001224ff98 Oops: stack guard page: 0000 [#1] SMP KASAN PTI RIP: 0010:bpftraceschedsetneedreschedtp+0x1c/0x190 Call Trace: traceschedsetneedreschedtp+0x110/0x130 settskneedresched include/linux/sched.h:2076 setneedreschedcurrent include/linux/sched.h:2094 rcureadunlockspecial+0x43a/0x440 rcureadunlock+0x9e/0x120 rcureadunlockmigrate+0xa9/0x240 bpftracerun+0x131/0x180 bpftracerun3+0x333/0x430 bpftraceschedsetneedreschedtp+0x13a/0x190 traceschedsetneedreschedtp+0x110/0x130 settskneedresched include/linux/sched.h:2076 ...
reschedcurr() has the same ordering, firing the tracepoint before setting the flag via settithreadflag() or setnrandnotpolling(). Fix it for consistency.
Replace the separate testtskthreadflag() + settskthreadflag() pair in settskneedresched() with testandsettskthreadflag(). In reschedcurr(), move the tracepoint call after the flag is set in each path.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
In the scheduler reschedule path, set TIF_NEED_RESCHED before invoking __trace_set_need_resched(); move the tracepoint call after the flag is set so re-entrant calls do not observe it as clear.
Event History
Frequently Asked Questions
What systems are exposed to this failure mode?
The described recursion requires a BPF raw tracepoint program attached to sched_set_need_resched. Systems without such an attached program are not described as triggering this issue.
What causes the kernel stack overflow?
The tracepoint runs the attached BPF program synchronously. When the BPF execution path drops its RCU lock, it can re-enter set_tsk_need_resched() before TIF_NEED_RESCHED has been set, repeatedly invoking the tracepoint until the task stack guard page is hit.
What can be done before the kernel fix is deployed?
Avoid attaching, or detach, BPF raw tracepoint programs from sched_set_need_resched. This removes the tracepoint attachment required for the re-entrant path described in the report.
How might this appear in logs or crash output?
The report shows a TASK stack guard page hit and an Oops, potentially with KASAN and call frames including __bpf_trace_sched_set_need_resched_tp, trace_sched_set_need_resched_tp, set_tsk_need_resched, rcu_read_unlock_migrate, and __bpf_trace_run.