Commit 5e93a95d authored by Herbert Xu's avatar Herbert Xu Committed by Ben Hutchings

tun: Fix TUN_PKT_STRIP setting

commit 2eb783c4 upstream.

We set the flag TUN_PKT_STRIP if the user buffer provided is too
small to contain the entire packet plus meta-data.  However, this
has been broken ever since we added GSO meta-data.  VLAN acceleration
also has the same problem.

This patch fixes this by taking both into account when setting the
TUN_PKT_STRIP flag.

The fact that this has been broken for six years without anyone
realising means that nobody actually uses this flag.

Fixes: f43798c2 ("tun: Allow GSO using virtio_net_hdr")
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent f8efa7a2
...@@ -1227,15 +1227,19 @@ static ssize_t tun_put_user(struct tun_struct *tun, ...@@ -1227,15 +1227,19 @@ static ssize_t tun_put_user(struct tun_struct *tun,
ssize_t total = 0; ssize_t total = 0;
int vlan_offset = 0, copied; int vlan_offset = 0, copied;
int vlan_hlen = 0; int vlan_hlen = 0;
int vnet_hdr_sz = 0;
if (vlan_tx_tag_present(skb)) if (vlan_tx_tag_present(skb))
vlan_hlen = VLAN_HLEN; vlan_hlen = VLAN_HLEN;
if (tun->flags & TUN_VNET_HDR)
vnet_hdr_sz = tun->vnet_hdr_sz;
if (!(tun->flags & TUN_NO_PI)) { if (!(tun->flags & TUN_NO_PI)) {
if ((len -= sizeof(pi)) < 0) if ((len -= sizeof(pi)) < 0)
return -EINVAL; return -EINVAL;
if (len < skb->len) { if (len < skb->len + vlan_hlen + vnet_hdr_sz) {
/* Packet will be striped */ /* Packet will be striped */
pi.flags |= TUN_PKT_STRIP; pi.flags |= TUN_PKT_STRIP;
} }
...@@ -1245,9 +1249,9 @@ static ssize_t tun_put_user(struct tun_struct *tun, ...@@ -1245,9 +1249,9 @@ static ssize_t tun_put_user(struct tun_struct *tun,
total += sizeof(pi); total += sizeof(pi);
} }
if (tun->flags & TUN_VNET_HDR) { if (vnet_hdr_sz) {
struct virtio_net_hdr gso = { 0 }; /* no info leak */ struct virtio_net_hdr gso = { 0 }; /* no info leak */
if ((len -= tun->vnet_hdr_sz) < 0) if ((len -= vnet_hdr_sz) < 0)
return -EINVAL; return -EINVAL;
if (skb_is_gso(skb)) { if (skb_is_gso(skb)) {
...@@ -1291,7 +1295,7 @@ static ssize_t tun_put_user(struct tun_struct *tun, ...@@ -1291,7 +1295,7 @@ static ssize_t tun_put_user(struct tun_struct *tun,
if (unlikely(memcpy_toiovecend(iv, (void *)&gso, total, if (unlikely(memcpy_toiovecend(iv, (void *)&gso, total,
sizeof(gso)))) sizeof(gso))))
return -EFAULT; return -EFAULT;
total += tun->vnet_hdr_sz; total += vnet_hdr_sz;
} }
copied = total; copied = total;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment