Skip to content

Commit 2357901

Browse files
arighianakryiko
authored andcommitted
bpf: Fix bpf_get_smp_processor_id() on !CONFIG_SMP
On x86-64 calling bpf_get_smp_processor_id() in a kernel with CONFIG_SMP disabled can trigger the following bug, as pcpu_hot is unavailable: [ 8.471774] BUG: unable to handle page fault for address: 00000000936a290c [ 8.471849] #PF: supervisor read access in kernel mode [ 8.471881] #PF: error_code(0x0000) - not-present page Fix by inlining a return 0 in the !CONFIG_SMP case. Fixes: 1ae6921 ("bpf: inline bpf_get_smp_processor_id() helper") Signed-off-by: Andrea Righi <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 78d4f34 commit 2357901

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

kernel/bpf/verifier.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21281,11 +21281,15 @@ static int do_misc_fixups(struct bpf_verifier_env *env)
2128121281
* changed in some incompatible and hard to support
2128221282
* way, it's fine to back out this inlining logic
2128321283
*/
21284+
#ifdef CONFIG_SMP
2128421285
insn_buf[0] = BPF_MOV32_IMM(BPF_REG_0, (u32)(unsigned long)&pcpu_hot.cpu_number);
2128521286
insn_buf[1] = BPF_MOV64_PERCPU_REG(BPF_REG_0, BPF_REG_0);
2128621287
insn_buf[2] = BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_0, 0);
2128721288
cnt = 3;
21288-
21289+
#else
21290+
insn_buf[0] = BPF_ALU32_REG(BPF_XOR, BPF_REG_0, BPF_REG_0);
21291+
cnt = 1;
21292+
#endif
2128921293
new_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);
2129021294
if (!new_prog)
2129121295
return -ENOMEM;

0 commit comments

Comments
 (0)