]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
net: fix generic XDP to handle if eth header was mangled
authorJesper Dangaard Brouer <brouer@redhat.com>
Tue, 9 Oct 2018 10:04:43 +0000 (12:04 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 10 Oct 2018 04:59:09 +0000 (21:59 -0700)
XDP can modify (and resize) the Ethernet header in the packet.

There is a bug in generic-XDP, because skb->protocol and skb->pkt_type
are setup before reaching (netif_receive_)generic_xdp.

This bug was hit when XDP were popping VLAN headers (changing
eth->h_proto), as skb->protocol still contains VLAN-indication
(ETH_P_8021Q) causing invocation of skb_vlan_untag(skb), which corrupt
the packet (basically popping the VLAN again).

This patch catch if XDP changed eth header in such a way, that SKB
fields needs to be updated.

V2: on request from Song Liu, use ETH_HLEN instead of mac_len,
in __skb_push() as eth_type_trans() use ETH_HLEN in paired skb_pull_inline().

Fixes: d445516966dc ("net: xdp: support xdp generic on virtual devices")
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
net/core/dev.c

index 0b2d777e5b9e85ec95f5204b0d81fa006f5a3a27..ec96f50b0782225b7624ab4e7831d42b20d10d8b 100644 (file)
@@ -4258,6 +4258,9 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb,
        struct netdev_rx_queue *rxqueue;
        void *orig_data, *orig_data_end;
        u32 metalen, act = XDP_DROP;
+       __be16 orig_eth_type;
+       struct ethhdr *eth;
+       bool orig_bcast;
        int hlen, off;
        u32 mac_len;
 
@@ -4298,6 +4301,9 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb,
        xdp->data_hard_start = skb->data - skb_headroom(skb);
        orig_data_end = xdp->data_end;
        orig_data = xdp->data;
+       eth = (struct ethhdr *)xdp->data;
+       orig_bcast = is_multicast_ether_addr_64bits(eth->h_dest);
+       orig_eth_type = eth->h_proto;
 
        rxqueue = netif_get_rxqueue(skb);
        xdp->rxq = &rxqueue->xdp_rxq;
@@ -4321,6 +4327,14 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb,
 
        }
 
+       /* check if XDP changed eth hdr such SKB needs update */
+       eth = (struct ethhdr *)xdp->data;
+       if ((orig_eth_type != eth->h_proto) ||
+           (orig_bcast != is_multicast_ether_addr_64bits(eth->h_dest))) {
+               __skb_push(skb, ETH_HLEN);
+               skb->protocol = eth_type_trans(skb, skb->dev);
+       }
+
        switch (act) {
        case XDP_REDIRECT:
        case XDP_TX: