Commit 269e7e9
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://syzkaller.appspot.com/bug?extid=b0cff308140f79a9c4cb
Fixes: 7c33e97 ("bpf: Do not disable preemption in bpf_test_run().")
Suggested-by: Yonghong Song <[email protected]>
Signed-off-by: Sahil Chandna <[email protected]>1 parent 4eb9670 commit 269e7e9
1 file changed
+6
-1
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 | | |
| |||
786 | 788 | | |
787 | 789 | | |
788 | 790 | | |
789 | | - | |
| 791 | + | |
| 792 | + | |
790 | 793 | | |
| 794 | + | |
791 | 795 | | |
| 796 | + | |
792 | 797 | | |
793 | 798 | | |
794 | 799 | | |
| |||
0 commit comments