Skip to content

Commit ce232ce

Browse files
Jason Wangdavem330
authored andcommitted
macvtap: signal truncated packets
macvtap_put_user() never return a value grater than iov length, this in fact bypasses the truncated checking in macvtap_recvmsg(). Fix this by always returning the size of packet plus the possible vlan header to let the trunca checking work. Cc: Vlad Yasevich <vyasevich@gmail.com> Cc: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com> Cc: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Jason Wang <jasowang@redhat.com> Acked-by: Vlad Yasevich <vyasevich@gmail.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e6fd07c commit ce232ce

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎drivers/net/macvtap.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ static ssize_t macvtap_put_user(struct macvtap_queue *q,
770770
int ret;
771771
int vnet_hdr_len = 0;
772772
int vlan_offset = 0;
773-
int copied;
773+
int copied, total;
774774

775775
if (q->flags & IFF_VNET_HDR) {
776776
struct virtio_net_hdr vnet_hdr;
@@ -785,7 +785,8 @@ static ssize_t macvtap_put_user(struct macvtap_queue *q,
785785
if (memcpy_toiovecend(iv, (void *)&vnet_hdr, 0, sizeof(vnet_hdr)))
786786
return -EFAULT;
787787
}
788-
copied = vnet_hdr_len;
788+
total = copied = vnet_hdr_len;
789+
total += skb->len;
789790

790791
if (!vlan_tx_tag_present(skb))
791792
len = min_t(int, skb->len, len);
@@ -800,6 +801,7 @@ static ssize_t macvtap_put_user(struct macvtap_queue *q,
800801

801802
vlan_offset = offsetof(struct vlan_ethhdr, h_vlan_proto);
802803
len = min_t(int, skb->len + VLAN_HLEN, len);
804+
total += VLAN_HLEN;
803805

804806
copy = min_t(int, vlan_offset, len);
805807
ret = skb_copy_datagram_const_iovec(skb, 0, iv, copied, copy);
@@ -817,10 +819,9 @@ static ssize_t macvtap_put_user(struct macvtap_queue *q,
817819
}
818820

819821
ret = skb_copy_datagram_const_iovec(skb, vlan_offset, iv, copied, len);
820-
copied += len;
821822

822823
done:
823-
return ret ? ret : copied;
824+
return ret ? ret : total;
824825
}
825826

826827
static ssize_t macvtap_do_read(struct macvtap_queue *q, struct kiocb *iocb,
@@ -875,7 +876,7 @@ static ssize_t macvtap_aio_read(struct kiocb *iocb, const struct iovec *iv,
875876
}
876877

877878
ret = macvtap_do_read(q, iocb, iv, len, file->f_flags & O_NONBLOCK);
878-
ret = min_t(ssize_t, ret, len); /* XXX copied from tun.c. Why? */
879+
ret = min_t(ssize_t, ret, len);
879880
if (ret > 0)
880881
iocb->ki_pos = ret;
881882
out:

0 commit comments

Comments
 (0)