AZL-117067: CVE-2026-139325 affecting package kernel 6.6.161.1-1
In the Linux kernel, the following vulnerability has been resolved:
bpf: Forbid sleeping in hash map foreach callbacks
A sleepable program (e.g. SEC("syscall"), lsm.s, fentry.s) can pass a callback to bpfforeachmapelem() on a hash map and call a sleepable helper or kfunc such as bpfcopyfromuser() from it. The verifier accepts this, but at run time the callback is invoked from inside an RCU read-side critical section:
bpfforeachhashelem() rcureadlock(); callbackfn(map, key, val, ctx, 0); bpfcopyfromuser() <- may fault and sleep rcureadunlock();
bpfeachrhashelem() does the same for BPFMAPTYPERHASH. Sleeping there triggers the "Voluntary context switch within RCU read-side critical section!" warning, delays grace periods, and with CONFIGPREEMPTRCU=n silently ends the read-side critical section that the bucket walk relies on.
Synchronous callbacks are verified with the caller's state, so kernel/bpf/verifier.c:insleepablecontext() only looks at the program's sleepability and the locks the program took itself, and does not know that the helper holds rcureadlock() around the callback.
With a SEC("syscall") program whose callback reads a page that has to be read from disk first:
BUG: sleeping function called from invalid context at include/linux/uaccess.h:169 RCU nest depth: 1, expected: 0 mightfault+0x29/0x80 copyfromuser+0x26/0x90 bpfcopyfromuser+0x23/0x60 bpfprog17d44fa39eebd6cccb+0x35/0x46 bpfforeachhashelem+0xdb/0x280
Fix by marking the callback frame of hash map iteration as running under RCU and making insleepablecontext() false while such a frame is on the call stack, so sleepable helpers, kfuncs and global functions are rejected there as inside bpfrcureadlock(). The rules for trusting RCU protected pointers are left alone, which is conservative and keeps callbacks that verify today and do not sleep working. The flag is compared in funcstatesequal() so that pruning never mixes the two contexts. Array map callbacks run without any lock and keep the caller's context.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
Do not call sleepable helpers, kfuncs, or global functions from hash map for_each callbacks.
Event History
Frequently Asked Questions
What conditions are required to trigger the issue?
A sleepable BPF program, such as one using SEC("syscall"), lsm.s, or fentry.s, must pass a callback to bpf_for_each_map_elem() for a hash map and invoke a sleepable helper or kfunc from that callback. The described example uses bpf_copy_from_user(), which can fault and sleep.
Which map types are implicated?
The issue affects callbacks iterating hash maps through bpf_for_each_hash_elem() and resizable hash maps using BPF_MAP_TYPE_RHASH through bpf_each_rhash_elem(). In both cases, the callback runs while an RCU read-side critical section is active.
What is the impact on systems without preemptible RCU?
With CONFIG_PREEMPT_RCU=n, sleeping in the callback can silently end the RCU read-side critical section relied upon by the hash-bucket walk. The issue can also produce a "Voluntary context switch within RCU read-side critical section!" warning and delay RCU grace periods.