Skip to content

Commit 07aee94

Browse files
borkmannAlexei Starovoitov
authored andcommitted
bpf, sparc: fix usage of wrong reg for load_skb_regs after call
When LD_ABS/IND is used in the program, and we have a BPF helper call that changes packet data (bpf_helper_changes_pkt_data() returns true), then in case of sparc JIT, we try to reload cached skb data from bpf2sparc[BPF_REG_6]. However, there is no such guarantee or assumption that skb sits in R6 at this point, all helpers changing skb data only have a guarantee that skb sits in R1. Therefore, store BPF R1 in L7 temporarily and after procedure call use L7 to reload cached skb data. skb sitting in R6 is only true at the time when LD_ABS/IND is executed. Fixes: 7a12b50 ("sparc64: Add eBPF JIT.") Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: David S. Miller <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 04514d1 commit 07aee94

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

arch/sparc/net/bpf_jit_comp_64.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,14 +1245,16 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx)
12451245
u8 *func = ((u8 *)__bpf_call_base) + imm;
12461246

12471247
ctx->saw_call = true;
1248+
if (ctx->saw_ld_abs_ind && bpf_helper_changes_pkt_data(func))
1249+
emit_reg_move(bpf2sparc[BPF_REG_1], L7, ctx);
12481250

12491251
emit_call((u32 *)func, ctx);
12501252
emit_nop(ctx);
12511253

12521254
emit_reg_move(O0, bpf2sparc[BPF_REG_0], ctx);
12531255

1254-
if (bpf_helper_changes_pkt_data(func) && ctx->saw_ld_abs_ind)
1255-
load_skb_regs(ctx, bpf2sparc[BPF_REG_6]);
1256+
if (ctx->saw_ld_abs_ind && bpf_helper_changes_pkt_data(func))
1257+
load_skb_regs(ctx, L7);
12561258
break;
12571259
}
12581260

0 commit comments

Comments
 (0)