CVE-2026-139306: bpf: Keep a program until its bpf_wq callback has ended
In the Linux kernel, the following vulnerability has been resolved:
bpf: Keep a program until its bpfwq callback has ended
bpfwqwork() runs the callback under rcureadlocktrace() only, since the callback may sleep. The program it belongs to need not be sleepable, and such a program is freed behind a plain RCU grace period. The reference that the bpfwq holds is dropped when the map element goes, or when another callback is set, no matter whether the work is running.
If that was the last reference the program is freed under the running callback, and the worker goes on in the freed JIT image:
Oops: int3: 0000 [#1] SMP NOPTI RIP: 0010:0xffffffffc0600947
All it takes is to close the map and the program while the callback runs.
Note in the program that it has a callback that runs sleepable, and wait for an RCU Tasks Trace grace period, which implies a plain one, before such a program is freed. Let bpfwqwork() enter its read side critical section before it reads callbackfn.
bpftaskwork holds a reference to the program until the callback is done.
Affected Software
Event History
Frequently Asked Questions
What condition is required to trigger the use-after-free?
A BPF workqueue callback must be running while the associated map and program are closed, causing the workqueue-held reference to be dropped. If that is the last program reference, the program can be freed while its callback continues executing in the freed JIT image.
Are only sleepable BPF programs affected?
No. The callback can sleep, but the program that owns it does not need to be sleepable. The issue arises because the callback runs under rcu_read_lock_trace(), while a non-sleepable program could be freed after only a plain RCU grace period.
What does the fix change?
The fix records that a program has a sleepable-running callback and waits for an RCU Tasks Trace grace period before freeing it. It also ensures bpf_wq_work() enters its read-side critical section before reading callback_fn, and bpf_task_work retains a program reference until the callback completes.