CVE-2026-143365: bpf: Clamp the trace length in __bpf_get_stack() again
In the Linux kernel, the following vulnerability has been resolved:
bpf: Clamp the trace length in bpfgetstack() again
getperfcallchain() and getcallchainentryfortask() store a trace in a per-CPU entry, one per context. They release the entry before they return it. Thus a second user in the same context can write to the entry while the first user reads it. preemptdisable() stops only other tasks.
bpfgetstack() requests at most maxdepth frames. This is skip plus the frames that fit in the buffer, but not more than perfeventmaxstack. Since the commit below, it copies 'trace->nr - skip' frames with no limit. But a second user can store a longer trace. The unwinders of PowerPC add context markers that maxdepth does not limit. In both cases the copy writes after the end of the buffer.
Read trace->nr one time. Clamp the value to maxdepth before the skip test, as bpfgetstackpe() does. Thus when maxdepth is less than skip, the helper returns -EFAULT, and 'tracenr - skip' does not underflow. The copied frames can still be those of the second user.
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.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
Event History
Frequently Asked Questions
What conditions trigger the out-of-bounds copy?
The issue requires a second user in the same context to write a longer stack trace into the shared per-CPU trace entry while the first user is reading it. The affected path can then copy more frames than fit in the caller's buffer.
Does disabling preemption prevent this race?
No. preempt_disable() prevents other tasks from running, but it does not prevent another user in the same context from updating the per-CPU trace entry.
What changes after applying the fix?
The trace frame count is read once and clamped to max_depth before skip handling and copying. If max_depth is smaller than skip, the helper returns -EFAULT rather than allowing an underflow or oversized copy.
Can the returned stack still contain frames from another user after the fix?
Yes. The fix prevents copying beyond the buffer, but the copied frames can still be those written by the second user.
How can I determine whether the fix is present?
Check whether the kernel source or applied stable patches include any of the referenced commits: 7735e81c34d7aed929b4a3864941f675f34ea07f, 5e0ae0ed5db60a22aca6ef1f8aeed677bed323f9, or f9045c09e95923b91d99916f0c821a4efbff4be4.