Skip to content

Commit 87338c8

Browse files
borkmannAlexei Starovoitov
authored andcommitted
bpf, ppc64: 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 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. Fixes: 156d0e2 ("powerpc/ebpf/jit: Implement JIT compiler for extended BPF") Signed-off-by: Daniel Borkmann <[email protected]> Reviewed-by: Naveen N. Rao <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Tested-by: Sandipan Das <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 6d59b7d commit 87338c8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

arch/powerpc/net/bpf_jit_comp64.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,8 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
763763
func = (u8 *) __bpf_call_base + imm;
764764

765765
/* Save skb pointer if we need to re-cache skb data */
766-
if (bpf_helper_changes_pkt_data(func))
766+
if ((ctx->seen & SEEN_SKB) &&
767+
bpf_helper_changes_pkt_data(func))
767768
PPC_BPF_STL(3, 1, bpf_jit_stack_local(ctx));
768769

769770
bpf_jit_emit_func_call(image, ctx, (u64)func);
@@ -772,7 +773,8 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
772773
PPC_MR(b2p[BPF_REG_0], 3);
773774

774775
/* refresh skb cache */
775-
if (bpf_helper_changes_pkt_data(func)) {
776+
if ((ctx->seen & SEEN_SKB) &&
777+
bpf_helper_changes_pkt_data(func)) {
776778
/* reload skb pointer to r3 */
777779
PPC_BPF_LL(3, 1, bpf_jit_stack_local(ctx));
778780
bpf_jit_emit_skb_loads(image, ctx);

0 commit comments

Comments
 (0)