Skip to content

Commit ee438c4

Browse files
willdeacongregkh
authored andcommitted
vsock/virtio: Validate length in packet header before skb_put()
commit 0dab924 upstream. 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: <stable@vger.kernel.org> Fixes: 71dc9ec ("virtio/vsock: replace virtio_vsock_pkt with sk_buff") Signed-off-by: Will Deacon <will@kernel.org> Message-Id: <20250717090116.11987-3-will@kernel.org> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6ee4578 commit ee438c4

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

net/vmw_vsock/virtio_transport.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,9 @@ static void virtio_transport_rx_work(struct work_struct *work)
497497
do {
498498
virtqueue_disable_cb(vq);
499499
for (;;) {
500+
unsigned int len, payload_len;
501+
struct virtio_vsock_hdr *hdr;
500502
struct sk_buff *skb;
501-
unsigned int len;
502503

503504
if (!virtio_transport_more_replies(vsock)) {
504505
/* Stop rx until the device processes already
@@ -515,12 +516,19 @@ static void virtio_transport_rx_work(struct work_struct *work)
515516
vsock->rx_buf_nr--;
516517

517518
/* Drop short/long packets */
518-
if (unlikely(len < sizeof(struct virtio_vsock_hdr) ||
519+
if (unlikely(len < sizeof(*hdr) ||
519520
len > virtio_vsock_skb_len(skb))) {
520521
kfree_skb(skb);
521522
continue;
522523
}
523524

525+
hdr = virtio_vsock_hdr(skb);
526+
payload_len = le32_to_cpu(hdr->len);
527+
if (unlikely(payload_len > len - sizeof(*hdr))) {
528+
kfree_skb(skb);
529+
continue;
530+
}
531+
524532
virtio_vsock_skb_rx_put(skb);
525533
virtio_transport_deliver_tap_pkt(skb);
526534
virtio_transport_recv_pkt(&virtio_transport, skb);

0 commit comments

Comments
 (0)