aboutsummaryrefslogtreecommitdiff
path: root/arch/x86/net
diff options
context:
space:
mode:
authorGravatar Yonghong Song <yonghong.song@linux.dev> 2023-07-27 18:12:31 -0700
committerGravatar Alexei Starovoitov <ast@kernel.org> 2023-07-27 18:52:33 -0700
commit4cd58e9af8b9d9fff6b7145e742abbfcda0af4af (patch)
tree2b6a5c2980c745a2b0096f544a17b6d82bb0fc89 /arch/x86/net
parentbpf: Fix jit blinding with new sdiv/smov insns (diff)
downloadlinux-4cd58e9af8b9d9fff6b7145e742abbfcda0af4af.tar.gz
linux-4cd58e9af8b9d9fff6b7145e742abbfcda0af4af.tar.bz2
linux-4cd58e9af8b9d9fff6b7145e742abbfcda0af4af.zip
bpf: Support new 32bit offset jmp instruction
Add interpreter/jit/verifier support for 32bit offset jmp instruction. If a conditional jmp instruction needs more than 16bit offset, it can be simulated with a conditional jmp + a 32bit jmp insn. Acked-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Yonghong Song <yonghong.song@linux.dev> Link: https://lore.kernel.org/r/20230728011231.3716103-1-yonghong.song@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'arch/x86/net')
-rw-r--r--arch/x86/net/bpf_jit_comp.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index a89b62eb2b40..a5930042139d 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -1815,16 +1815,24 @@ emit_cond_jmp: /* Convert BPF opcode to x86 */
break;
case BPF_JMP | BPF_JA:
- if (insn->off == -1)
- /* -1 jmp instructions will always jump
- * backwards two bytes. Explicitly handling
- * this case avoids wasting too many passes
- * when there are long sequences of replaced
- * dead code.
- */
- jmp_offset = -2;
- else
- jmp_offset = addrs[i + insn->off] - addrs[i];
+ case BPF_JMP32 | BPF_JA:
+ if (BPF_CLASS(insn->code) == BPF_JMP) {
+ if (insn->off == -1)
+ /* -1 jmp instructions will always jump
+ * backwards two bytes. Explicitly handling
+ * this case avoids wasting too many passes
+ * when there are long sequences of replaced
+ * dead code.
+ */
+ jmp_offset = -2;
+ else
+ jmp_offset = addrs[i + insn->off] - addrs[i];
+ } else {
+ if (insn->imm == -1)
+ jmp_offset = -2;
+ else
+ jmp_offset = addrs[i + insn->imm] - addrs[i];
+ }
if (!jmp_offset) {
/*