bpf: make virtio compatible w/ bpf_xdp_adjust_tail
authorNikita V. Shirokov <tehnerd@tehnerd.com>
Wed, 18 Apr 2018 04:42:20 +0000 (21:42 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 18 Apr 2018 21:34:16 +0000 (23:34 +0200)
w/ bpf_xdp_adjust_tail helper xdp's data_end pointer could be changed as
well (only "decrease" of pointer's location is going to be supported).
changing of this pointer will change packet's size.
for virtio driver we need to adjust XDP_PASS handling by recalculating
length of the packet if it was passed to the TCP/IP stack

Reviewed-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Nikita V. Shirokov <tehnerd@tehnerd.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
drivers/net/virtio_net.c

index 01694e26f03ebca812bef528c530a956a2342e45..779a4f7985228d8f45e7cfaf077517e0f634b748 100644 (file)
@@ -606,6 +606,7 @@ static struct sk_buff *receive_small(struct net_device *dev,
                case XDP_PASS:
                        /* Recalculate length in case bpf program changed it */
                        delta = orig_data - xdp.data;
+                       len = xdp.data_end - xdp.data;
                        break;
                case XDP_TX:
                        xdpf = convert_to_xdp_frame(&xdp);
@@ -642,7 +643,7 @@ static struct sk_buff *receive_small(struct net_device *dev,
                goto err;
        }
        skb_reserve(skb, headroom - delta);
-       skb_put(skb, len + delta);
+       skb_put(skb, len);
        if (!delta) {
                buf += header_offset;
                memcpy(skb_vnet_hdr(skb), buf, vi->hdr_len);
@@ -757,6 +758,10 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
                        offset = xdp.data -
                                        page_address(xdp_page) - vi->hdr_len;
 
+                       /* recalculate len if xdp.data or xdp.data_end were
+                        * adjusted
+                        */
+                       len = xdp.data_end - xdp.data;
                        /* We can only create skb based on xdp_page. */
                        if (unlikely(xdp_page != page)) {
                                rcu_read_unlock();