CVE-2026-143377: bpf: Drop percpu_counter from the htab element count
In the Linux kernel, the following vulnerability has been resolved:
bpf: Drop percpucounter from the htab element count
The element count of a large non-preallocated hash map is a percpucounter, whose slow path takes fbc->lock with rawspinlockirqsave(). That is not safe against BPF programs that run while the lock is held or contended: NMI programs and, as queuedspinlockslowpath() calls tracecontentionend() with the lock already held, programs attached to the contentionend tracepoint. If such a program updates the same map it spins on the lock its own CPU holds:
WARNING: possible recursive locking detected cend/250 is trying to acquire lock: (key#5){....}-{2:2}, at: rawspinlockirqsave+0x18/0x30 but task is already holding lock: (key#5){....}-{2:2}, at: rawspinlockirqsave+0x18/0x30 percpucounteraddbatch+0xd8/0x160 allochtabelem+0x408/0x480 htabmapupdateelem+0x1e8/0x6a0 bpfprog7a29a1ae68aedf07cend+0x14c/0x1f8 bpftracecontentionend+0x14/0x20 queuedspinlockslowpath+0x2e8/0x468 percpucounteraddbatch+0xd8/0x160 allochtabelem+0x408/0x480 htabmapupdateelem+0x1e8/0x6a0
ismapfull() is affected too, as percpucountercompare() falls back to percpucountersum(), which takes the same lock.
map.elemcount already is a lockless per-cpu count of the same elements. Make htab->count follow it in steps of PERCPUCOUNTERBATCH and let ismapfull() sum elemcount once count is within nrcpuids batch of maxentries. Each cpu's elemcount is ahead of count by less than the batch, so that is exact, in NMI as well.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
linux/Kernelto a version that resolves this vulnerability.Fixed in 6.18.66 - Upgrade
Upgrade
linux/Kernelto a version that resolves this vulnerability.Fixed in 7.3.7
Event History
Frequently Asked Questions
Which BPF workloads are exposed to this locking issue?
The issue affects large non-preallocated BPF hash maps whose element count uses a percpu counter. It can be triggered by BPF programs running in NMI context or by programs attached to the contention_end tracepoint.
What must happen for the issue to trigger?
A BPF program must update the same affected hash map while the percpu-counter lock is held or contended on its CPU. The map-full check path is also affected because its counter comparison can fall back to the same locking path.
What can be done if the fix cannot be deployed immediately?
Avoid updating an affected map from NMI-context BPF programs or from programs attached to contention_end. In particular, do not have those programs update the same large non-preallocated hash map that can enter the percpu-counter slow path.
How can an administrator recognize that this is occurring?
Kernel logs may report a "possible recursive locking detected" warning. The reported stack can include percpu_counter_add_batch, alloc_htab_elem, htab_map_update_elem, queued_spin_lock_slowpath, and __bpf_trace_contention_end.