Skip to content

Commit 0dab924

Browse files
willdeaconmstsirkin
authored andcommitted
vsock/virtio: Validate length in packet header before skb_put()
When receiving a vsock packet in the guest, only the virtqueue buffer size is validated prior to virtio_vsock_skb_rx_put(). Unfortunately, virtio_vsock_skb_rx_put() uses the length from the packet header as the length argument to skb_put(), potentially resulting in SKB overflow if the host has gone wonky. Validate the length as advertised by the packet header before calling virtio_vsock_skb_rx_put(). Cc: <[email protected]> Fixes: 71dc9ec ("virtio/vsock: replace virtio_vsock_pkt with sk_buff") Signed-off-by: Will Deacon <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Reviewed-by: Stefano Garzarella <[email protected]>
1 parent 10a886a commit 0dab924

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

net/vmw_vsock/virtio_transport.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,9 @@ static void virtio_transport_rx_work(struct work_struct *work)
624624
do {
625625
virtqueue_disable_cb(vq);
626626
for (;;) {
627+
unsigned int len, payload_len;
628+
struct virtio_vsock_hdr *hdr;
627629
struct sk_buff *skb;
628-
unsigned int len;
629630

630631
if (!virtio_transport_more_replies(vsock)) {
631632
/* Stop rx until the device processes already
@@ -642,12 +643,19 @@ static void virtio_transport_rx_work(struct work_struct *work)
642643
vsock->rx_buf_nr--;
643644

644645
/* Drop short/long packets */
645-
if (unlikely(len < sizeof(struct virtio_vsock_hdr) ||
646+
if (unlikely(len < sizeof(*hdr) ||
646647
len > virtio_vsock_skb_len(skb))) {
647648
kfree_skb(skb);
648649
continue;
649650
}
650651

652+
hdr = virtio_vsock_hdr(skb);
653+
payload_len = le32_to_cpu(hdr->len);
654+
if (unlikely(payload_len > len - sizeof(*hdr))) {
655+
kfree_skb(skb);
656+
continue;
657+
}
658+
651659
virtio_vsock_skb_rx_put(skb);
652660
virtio_transport_deliver_tap_pkt(skb);
653661
virtio_transport_recv_pkt(&virtio_transport, skb);

0 commit comments

Comments
 (0)