aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Wang <jasowang@redhat.com>2013-07-10 01:43:27 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-07-28 19:29:58 -0400
commitd09ec76aebab878e0dc583484152e20a2172a7b4 (patch)
treeadb0981a16f2b44be0d7b1fcd02039adcbbf42cd
parent6683151aeea6c7aade12dde7ec2008fc380f0728 (diff)
tuntap: correctly linearize skb when zerocopy is used
[ Upstream commit 3dd5c3308e8b671e8e8882ba972f51cefbe9fd0d ] 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 tun_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 0690899b4d4501b3505be069b9a687e68ccbe15b (tun: experimental zero copy tx support) 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/net/tun.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 9c61f8734a40..c3cb60b1d1a2 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1044,7 +1044,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
1044{ 1044{
1045 struct tun_pi pi = { 0, cpu_to_be16(ETH_P_IP) }; 1045 struct tun_pi pi = { 0, cpu_to_be16(ETH_P_IP) };
1046 struct sk_buff *skb; 1046 struct sk_buff *skb;
1047 size_t len = total_len, align = NET_SKB_PAD; 1047 size_t len = total_len, align = NET_SKB_PAD, linear;
1048 struct virtio_net_hdr gso = { 0 }; 1048 struct virtio_net_hdr gso = { 0 };
1049 int offset = 0; 1049 int offset = 0;
1050 int copylen; 1050 int copylen;
@@ -1108,10 +1108,13 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
1108 copylen = gso.hdr_len; 1108 copylen = gso.hdr_len;
1109 if (!copylen) 1109 if (!copylen)
1110 copylen = GOODCOPY_LEN; 1110 copylen = GOODCOPY_LEN;
1111 } else 1111 linear = copylen;
1112 } else {
1112 copylen = len; 1113 copylen = len;
1114 linear = gso.hdr_len;
1115 }
1113 1116
1114 skb = tun_alloc_skb(tfile, align, copylen, gso.hdr_len, noblock); 1117 skb = tun_alloc_skb(tfile, align, copylen, linear, noblock);
1115 if (IS_ERR(skb)) { 1118 if (IS_ERR(skb)) {
1116 if (PTR_ERR(skb) != -EAGAIN) 1119 if (PTR_ERR(skb) != -EAGAIN)
1117 tun->dev->stats.rx_dropped++; 1120 tun->dev->stats.rx_dropped++;