Skip to content

Commit be708ed

Browse files
puranjaymohanAlexei Starovoitov
authored andcommitted
bpf/arm64: Fix BPF_ST into arena memory
The arm64 JIT supports BPF_ST with BPF_PROBE_MEM32 (arena) by using the tmp2 register to hold the dst + arena_vm_base value and using tmp2 as the new dst register. But this is broken because in case is_lsi_offset() returns false the tmp2 will be clobbered by emit_a64_mov_i(1, tmp2, off, ctx); and hence the emitted store instruction will be of the form: strb w10, [x11, x11] Fix this by using the third temporary register to hold the dst + arena_vm_base. Fixes: 339af57 ("bpf: Add arm64 JIT support for PROBE_MEM32 pseudo instructions.") Signed-off-by: Puranjay Mohan <puranjay@kernel.org> Link: https://lore.kernel.org/r/20251030121715.55214-1-puranjay@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 14a7f23 commit be708ed

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

arch/arm64/net/bpf_jit_comp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
12131213
u8 src = bpf2a64[insn->src_reg];
12141214
const u8 tmp = bpf2a64[TMP_REG_1];
12151215
const u8 tmp2 = bpf2a64[TMP_REG_2];
1216+
const u8 tmp3 = bpf2a64[TMP_REG_3];
12161217
const u8 fp = bpf2a64[BPF_REG_FP];
12171218
const u8 arena_vm_base = bpf2a64[ARENA_VM_START];
12181219
const u8 priv_sp = bpf2a64[PRIVATE_SP];
@@ -1757,8 +1758,8 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
17571758
case BPF_ST | BPF_PROBE_MEM32 | BPF_W:
17581759
case BPF_ST | BPF_PROBE_MEM32 | BPF_DW:
17591760
if (BPF_MODE(insn->code) == BPF_PROBE_MEM32) {
1760-
emit(A64_ADD(1, tmp2, dst, arena_vm_base), ctx);
1761-
dst = tmp2;
1761+
emit(A64_ADD(1, tmp3, dst, arena_vm_base), ctx);
1762+
dst = tmp3;
17621763
}
17631764
if (dst == fp) {
17641765
dst_adj = ctx->priv_sp_used ? priv_sp : A64_SP;

0 commit comments

Comments
 (0)