Skip to content

Commit e6fd07c

Browse files
Jason Wangdavem330
authored andcommitted
tun: unbreak truncated packet signalling
Commit 6680ec6 (tuntap: hardware vlan tx support) breaks the truncated packet signal by nev return a length greater than iov length in tun_put_user(). This patch fixes by always return the length of packet plus possible vlan header. Caller can detect the truncated packet by comparing the return value and the size of io length. Cc: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com> Cc: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Vlad Yasevich <vyasevich@gmail.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>
1 parent 1598f7c commit e6fd07c

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

‎drivers/net/tun.c‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ static ssize_t tun_put_user(struct tun_struct *tun,
11841184
{
11851185
struct tun_pi pi = { 0, skb->protocol };
11861186
ssize_t total = 0;
1187-
int vlan_offset = 0;
1187+
int vlan_offset = 0, copied;
11881188

11891189
if (!(tun->flags & TUN_NO_PI)) {
11901190
if ((len -= sizeof(pi)) < 0)
@@ -1248,6 +1248,8 @@ static ssize_t tun_put_user(struct tun_struct *tun,
12481248
total += tun->vnet_hdr_sz;
12491249
}
12501250

1251+
copied = total;
1252+
total += skb->len;
12511253
if (!vlan_tx_tag_present(skb)) {
12521254
len = min_t(int, skb->len, len);
12531255
} else {
@@ -1262,24 +1264,24 @@ static ssize_t tun_put_user(struct tun_struct *tun,
12621264

12631265
vlan_offset = offsetof(struct vlan_ethhdr, h_vlan_proto);
12641266
len = min_t(int, skb->len + VLAN_HLEN, len);
1267+
total += VLAN_HLEN;
12651268

12661269
copy = min_t(int, vlan_offset, len);
1267-
ret = skb_copy_datagram_const_iovec(skb, 0, iv, total, copy);
1270+
ret = skb_copy_datagram_const_iovec(skb, 0, iv, copied, copy);
12681271
len -= copy;
1269-
total += copy;
1272+
copied += copy;
12701273
if (ret || !len)
12711274
goto done;
12721275

12731276
copy = min_t(int, sizeof(veth), len);
1274-
ret = memcpy_toiovecend(iv, (void *)&veth, total, copy);
1277+
ret = memcpy_toiovecend(iv, (void *)&veth, copied, copy);
12751278
len -= copy;
1276-
total += copy;
1279+
copied += copy;
12771280
if (ret || !len)
12781281
goto done;
12791282
}
12801283

1281-
skb_copy_datagram_const_iovec(skb, vlan_offset, iv, total, len);
1282-
total += len;
1284+
skb_copy_datagram_const_iovec(skb, vlan_offset, iv, copied, len);
12831285

12841286
done:
12851287
tun->dev->stats.tx_packets++;

0 commit comments

Comments
 (0)