Skip to content

Commit

Permalink
net: fix bpf_xdp_adjust_head regression for generic-XDP
Browse files Browse the repository at this point in the history
When generic-XDP was moved to a later processing step by commit
458bf2f ("net: core: support XDP generic on stacked devices.")
a regression was introduced when using bpf_xdp_adjust_head.

The issue is that after this commit the skb->network_header is now
changed prior to calling generic XDP and not after. Thus, if the header
is changed by XDP (via bpf_xdp_adjust_head), then skb->network_header
also need to be updated again.  Fix by calling skb_reset_network_header().

Fixes: 458bf2f ("net: core: support XDP generic on stacked devices.")
Reported-by: Brandon Cazander <[email protected]>
Signed-off-by: Jesper Dangaard Brouer <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
netoptimizer authored and davem330 committed Aug 5, 2019
1 parent 13978d1 commit 065af35
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -4374,12 +4374,17 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb,

act = bpf_prog_run_xdp(xdp_prog, xdp);

/* check if bpf_xdp_adjust_head was used */
off = xdp->data - orig_data;
if (off > 0)
__skb_pull(skb, off);
else if (off < 0)
__skb_push(skb, -off);
skb->mac_header += off;
if (off) {
if (off > 0)
__skb_pull(skb, off);
else if (off < 0)
__skb_push(skb, -off);

skb->mac_header += off;
skb_reset_network_header(skb);
}

/* check if bpf_xdp_adjust_tail was used. it can only "shrink"
* pckt.
Expand Down

0 comments on commit 065af35

Please sign in to comment.