From: Brian Gerst Date: Thu, 27 Feb 2025 19:53:02 +0000 (-0500) Subject: x86/bpf: Fix BPF percpu accesses X-Git-Tag: v6.15-rc1~216^2~86^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18cdd90aba794333f4c6dce39f5c3fe642af5575;p=thirdparty%2Flinux.git x86/bpf: Fix BPF percpu accesses Due to this recent commit in the x86 tree: 9d7de2aa8b41 ("Use relative percpu offsets") percpu addresses went from positive offsets from the GSBASE to negative kernel virtual addresses. The BPF verifier has an optimization for x86-64 that loads the address of cpu_number into a register, but was only doing a 32-bit load which truncates negative addresses. Change it to a 64-bit load so that the address is properly sign-extended. Fixes: 9d7de2aa8b41 ("Use relative percpu offsets") Signed-off-by: Brian Gerst Signed-off-by: Ingo Molnar Cc: Alexei Starovoitov Cc: Daniel Borkmann Cc: Uros Bizjak Cc: Linus Torvalds Link: https://lore.kernel.org/r/20250227195302.1667654-1-brgerst@gmail.com --- diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 9971c03adfd5d..f74263b206e43 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -21692,7 +21692,7 @@ patch_map_ops_generic: * way, it's fine to back out this inlining logic */ #ifdef CONFIG_SMP - insn_buf[0] = BPF_MOV32_IMM(BPF_REG_0, (u32)(unsigned long)&pcpu_hot.cpu_number); + insn_buf[0] = BPF_MOV64_IMM(BPF_REG_0, (u32)(unsigned long)&pcpu_hot.cpu_number); insn_buf[1] = BPF_MOV64_PERCPU_REG(BPF_REG_0, BPF_REG_0); insn_buf[2] = BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_0, 0); cnt = 3;