Skip to content

Commit 6d59b7d

Browse files
borkmannAlexei Starovoitov
authored and
Alexei Starovoitov
committed
bpf, s390x: do not reload skb pointers in non-skb context
The assumption of unconditionally reloading skb pointers on BPF helper calls where bpf_helper_changes_pkt_data() holds true is wrong. There can be different contexts where the BPF helper would enforce a reload such as in case of XDP. Here, we do have a struct xdp_buff instead of struct sk_buff as context, thus this will access garbage. JITs only ever need to deal with cached skb pointer reload when ld_abs/ind was seen, therefore guard the reload behind SEEN_SKB only. Tested on s390x. Fixes: 9db7f2b ("s390/bpf: recache skb->data/hlen for skb_vlan_push/pop") Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Cc: Michael Holzheu <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 2d17d8d commit 6d59b7d

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

arch/s390/net/bpf_jit_comp.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ struct bpf_jit {
5555
#define SEEN_LITERAL 8 /* code uses literals */
5656
#define SEEN_FUNC 16 /* calls C functions */
5757
#define SEEN_TAIL_CALL 32 /* code uses tail calls */
58-
#define SEEN_SKB_CHANGE 64 /* code changes skb data */
59-
#define SEEN_REG_AX 128 /* code uses constant blinding */
58+
#define SEEN_REG_AX 64 /* code uses constant blinding */
6059
#define SEEN_STACK (SEEN_FUNC | SEEN_MEM | SEEN_SKB)
6160

6261
/*
@@ -448,12 +447,12 @@ static void bpf_jit_prologue(struct bpf_jit *jit, u32 stack_depth)
448447
EMIT6_DISP_LH(0xe3000000, 0x0024, REG_W1, REG_0,
449448
REG_15, 152);
450449
}
451-
if (jit->seen & SEEN_SKB)
450+
if (jit->seen & SEEN_SKB) {
452451
emit_load_skb_data_hlen(jit);
453-
if (jit->seen & SEEN_SKB_CHANGE)
454452
/* stg %b1,ST_OFF_SKBP(%r0,%r15) */
455453
EMIT6_DISP_LH(0xe3000000, 0x0024, BPF_REG_1, REG_0, REG_15,
456454
STK_OFF_SKBP);
455+
}
457456
}
458457

459458
/*
@@ -983,8 +982,8 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, int i
983982
EMIT2(0x0d00, REG_14, REG_W1);
984983
/* lgr %b0,%r2: load return value into %b0 */
985984
EMIT4(0xb9040000, BPF_REG_0, REG_2);
986-
if (bpf_helper_changes_pkt_data((void *)func)) {
987-
jit->seen |= SEEN_SKB_CHANGE;
985+
if ((jit->seen & SEEN_SKB) &&
986+
bpf_helper_changes_pkt_data((void *)func)) {
988987
/* lg %b1,ST_OFF_SKBP(%r15) */
989988
EMIT6_DISP_LH(0xe3000000, 0x0004, BPF_REG_1, REG_0,
990989
REG_15, STK_OFF_SKBP);

0 commit comments

Comments
 (0)