CVE-2026-139177: sched_ext: Reject rq-lock-taking kfuncs in tracing programs
In the Linux kernel, the following vulnerability has been resolved:
schedext: Reject rq-lock-taking kfuncs in tracing programs
scxbpfcpuperfset() and scxbpfcidperfset() are members of scxkfuncidsany, which is registered for BPFPROGTYPETRACING. A tracing program can run in a context which already holds the target rq lock, in which case scxcpuperfset() attempts to acquire the same lock again:
schedule() rqlock(rq); / rq->lock is held / traceschedswitch(); BPF tracing program scxbpfcpuperfset(smpprocessorid(), 1024); scxcpuperfset(); lockedrq = scxlockedrq(); / NULL / rqlockirqsave(rq, &rf); / same lock /
scxlockedrq() only tracks rq locks held during SCX callback invocations, so it cannot detect an rq lock held by the surrounding kernel code.
The deadlock can be reproduced with two BPF programs. The first is a minimal SCX scheduler, which only needs to be registered and enabled:
SEC(".structops.link") struct schedextops minimalops = { .name = "minimal", };
The second is a tracing program attached to tpbtf/schedswitch, which fires from schedule() with rq->lock already held:
SEC("tpbtf/schedswitch") int BPFPROG(onschedswitch, bool preempt, struct taskstruct prev, struct taskstruct next, unsigned int prevstate) { scxbpfcpuperfset(bpfgetsmpprocessorid(), 1024); return 0; }
With both programs attached, the next context switch on any CPU deadlocks that CPU. Lockdep reports:
WARNING: possible recursive locking detected 7.3.0-rc7 #3 Not tainted swapper/3/0 is trying to acquire lock: (&rq->lock){-.-.}-{2:2}, at: rawspinrqlocknested+0x1e/0x30
but task is already holding lock: (&rq->lock){-.-.}-{2:2}, at: schedule+0xeb/0x1430
Possible unsafe locking scenario:
CPU0 ---- lock(&rq->lock); lock(&rq->lock);
DEADLOCK
Call Trace: <TASK> printdeadlockbug.cold+0xc0/0xd0 lockacquire+0x12fa/0x1b80 lockacquire+0xd1/0x2f0 rawspinlocknested+0x32/0x40 rawspinrqlocknested+0x1e/0x30 scxcpuperfset+0x1e9/0x310 scxbpfcpuperfset+0x9b/0x230 bpfprog...onschedswitch+0x3d/0x41 bpftracerun4+0x125/0x450 traceiterschedswitch+0x4b/0x70 schedule+0x94a/0x1430 scheduleidle+0x26/0x50 cpustartupentry+0x2d/0x30 startsecondary+0xfc/0x100 </TASK>
The CPU remains locked up with interrupts disabled. scxbpfcidperfset() is similarly affected, as it resolves the CID through scxcidtocpu() before reaching the same rq-locking path.
There is no reliable way for these kfuncs to determine whether the surrounding tracing context already holds an rq lock. Reject calls to both kfuncs from tracing programs at verification time, while preserving their availability to SCX structops and syscall programs.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
Reject calls to scx_bpf_cpuperf_set() and scx_bpf_cidperf_set() from BPF tracing programs at verification time, while preserving their availability to SCX struct_ops and syscall programs.