Commit 4c93fc6
bpf: use preempt_disable/enable() to protect bpf_bprintf_buffers nesting
The bpf_bprintf_prepare() and related helpers (bpf_try_get_buffers() /
bpf_put_buffers()) rely on a per-CPU counter bpf_bprintf_nest_level to
manage nested buffer usage. However, when invoked from different contexts
(process, softirq, NMI), the nesting counter can become inconsistent if
task migration occurs between CPUs during these operations. This can
result in warnings such as:
WARNING: CPU: 1 PID: 6145 at kernel/bpf/helpers.c:781 bpf_try_get_buffers kernel/bpf/helpers.c:781 [inline]
WARNING: CPU: 1 PID: 6145 at kernel/bpf/helpers.c:781 bpf_bprintf_prepare+0x12cf/0x13a0 kernel/bpf/helpers.c:834
Having only migrate_disable is insufficient here to prevent nesting,
hence add preempt_disable()/enable() around buffer acquisition and release.
Reported-by: [email protected]
Closes: https://lore.kernel.org/all/[email protected]/
Fixes: 4223bf8 ("bpf: Remove preempt_disable in bpf_try_get_buffers")
Suggested-by: Yonghong Song <[email protected]>
Signed-off-by: Sahil Chandna <[email protected]>1 parent 4eb9670 commit 4c93fc6
1 file changed
+3
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
774 | 774 | | |
775 | 775 | | |
776 | 776 | | |
| 777 | + | |
777 | 778 | | |
778 | 779 | | |
779 | 780 | | |
| 781 | + | |
780 | 782 | | |
781 | 783 | | |
782 | 784 | | |
| |||
789 | 791 | | |
790 | 792 | | |
791 | 793 | | |
| 794 | + | |
792 | 795 | | |
793 | 796 | | |
794 | 797 | | |
| |||
0 commit comments