aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Wang <jasowang@redhat.com>2013-07-10 01:43:28 -0400
committerDavid S. Miller <davem@davemloft.net>2013-07-10 21:45:52 -0400
commit61d46bf979d5cd7c164709a80ad5676a35494aae (patch)
treec7054c34dacaa95f2e4b63c61baf8227deab7581
parent3dd5c3308e8b671e8e8882ba972f51cefbe9fd0d (diff)
macvtap: correctly linearize skb when zerocopy is used
Userspace may produce vectors greater than MAX_SKB_FRAGS. When we try to linearize parts of the skb to let the rest of iov to be fit in the frags, we need count copylen into linear when calling macvtap_alloc_skb() instead of partly counting it into data_len. Since this breaks zerocopy_sg_from_iovec() since its inner counter assumes nr_frags should be zero at beginning. This cause nr_frags to be increased wrongly without setting the correct frags. This bug were introduced from b92946e2919134ebe2a4083e4302236295ea2a73 (macvtap: zerocopy: validate vectors before building skb). Cc: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Jason Wang <jasowang@redhat.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/macvtap.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
index f2c4a3b218fc..876c72246ae9 100644
--- a/drivers/net/macvtap.c
+++ b/drivers/net/macvtap.c
@@ -712,6 +712,7 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
712 int vnet_hdr_len = 0; 712 int vnet_hdr_len = 0;
713 int copylen = 0; 713 int copylen = 0;
714 bool zerocopy = false; 714 bool zerocopy = false;
715 size_t linear;
715 716
716 if (q->flags & IFF_VNET_HDR) { 717 if (q->flags & IFF_VNET_HDR) {
717 vnet_hdr_len = q->vnet_hdr_sz; 718 vnet_hdr_len = q->vnet_hdr_sz;
@@ -766,11 +767,14 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
766 copylen = vnet_hdr.hdr_len; 767 copylen = vnet_hdr.hdr_len;
767 if (!copylen) 768 if (!copylen)
768 copylen = GOODCOPY_LEN; 769 copylen = GOODCOPY_LEN;
769 } else 770 linear = copylen;
771 } else {
770 copylen = len; 772 copylen = len;
773 linear = vnet_hdr.hdr_len;
774 }
771 775
772 skb = macvtap_alloc_skb(&q->sk, NET_IP_ALIGN, copylen, 776 skb = macvtap_alloc_skb(&q->sk, NET_IP_ALIGN, copylen,
773 vnet_hdr.hdr_len, noblock, &err); 777 linear, noblock, &err);
774 if (!skb) 778 if (!skb)
775 goto err; 779 goto err;
776 780