CVE-2026-143364: bpf: Clamp the trace length before the skip test in stackid_init()
In the Linux kernel, the following vulnerability has been resolved:
bpf: Clamp the trace length before the skip test in stackidinit()
stackidinit() gives a bucket of the stack map min(tracenr - skip, maxdepth - skip) trace entries. Here maxdepth is the size of a bucket plus skip, but at most perfeventmaxstack. Context markers can make tracenr larger than that, so the skip test can pass when maxdepth < skip. Then 'maxdepth - skip' wraps, and the kernel can write after the bucket.
Clamp tracenr to maxdepth before the skip test, as bpfgetstackpe() does. The result changes only when skip >= maxdepth. Then it is -EFAULT. Until now skip == maxdepth could give the id of an empty trace.
getperfcallchain() releases the trace, so an NMI can change trace->nr. Use READONCE() in bpfgetstackid(), so the compiler reads it one time.
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.2 - Upgrade
Upgrade
linux/Kernelto a version that resolves this vulnerability.Fixed in 6.7 - Upgrade
Upgrade
linux/Kernelto a version that resolves this vulnerability.Fixed in 6.12.120 - Upgrade
Upgrade
linux/Kernelto a version that resolves this vulnerability.Fixed in 6.18 - 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 - Compensating control
In Linux kernel stackid_init(), clamp trace_nr to max_depth before the skip test.
- Compensating control
In bpf_get_stackid(), use READ_ONCE() when reading trace->nr so the compiler reads it only once.
Event History
Frequently Asked Questions
When does the fix change observable behavior for BPF programs collecting stack IDs?
The result changes only when the requested skip value is greater than or equal to max_depth. In that case, the corrected behavior is to return -EFAULT; previously, skip equal to max_depth could return an ID for an empty trace.
What condition led to the out-of-bounds write?
Context markers can make the recorded trace length exceed max_depth. If the skip check then passes while max_depth is smaller than skip, subtracting skip from max_depth wraps and can cause writes beyond the stack-map bucket.
Does the fix account for NMI-related changes to the trace length?
Yes. bpf_get_stackid() uses READ_ONCE() when reading trace->nr because an NMI can change that value after get_perf_callchain() releases the trace.