virtio_net: stricter short buffer length checks
authorMichael S. Tsirkin <mst@redhat.com>
Thu, 23 Oct 2014 21:22:11 +0000 (00:22 +0300)
committerMichael S. Tsirkin <mst@redhat.com>
Tue, 9 Dec 2014 10:05:28 +0000 (12:05 +0200)
Our buffer length check is not strict enough for mergeable
buffers: buffer can still be shorter that header + address
by 2 bytes.

Fix that up.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Jason Wang <jasowang@redhat.com>
drivers/net/virtio_net.c

index 516f2cb034b548e5bebc3beccb74e43b6740229f..098f4432afa1b101cd050d45b5bbc5c2a0e81e83 100644 (file)
@@ -437,7 +437,7 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
        struct sk_buff *skb;
        struct virtio_net_hdr_mrg_rxbuf *hdr;
 
-       if (unlikely(len < sizeof(struct virtio_net_hdr) + ETH_HLEN)) {
+       if (unlikely(len < vi->hdr_len + ETH_HLEN)) {
                pr_debug("%s: short packet %i\n", dev->name, len);
                dev->stats.rx_length_errors++;
                if (vi->mergeable_rx_bufs) {