Skip to content

Commit df7589c

Browse files
committed
vsock/virtio: Validate length in packet header before skb_put()
jira LE-4603 cve CVE-2025-39718 Rebuild_History Non-Buildable kernel-5.14.0-570.58.1.el9_6 commit-author Will Deacon <will@kernel.org> commit 0dab924 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> (cherry picked from commit 0dab924) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent e986468 commit df7589c

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
@@ -582,8 +582,9 @@ static void virtio_transport_rx_work(struct work_struct *work)
582582
do {
583583
virtqueue_disable_cb(vq);
584584
for (;;) {
585+
unsigned int len, payload_len;
586+
struct virtio_vsock_hdr *hdr;
585587
struct sk_buff *skb;
586-
unsigned int len;
587588

588589
if (!virtio_transport_more_replies(vsock)) {
589590
/* Stop rx until the device processes already
@@ -600,12 +601,19 @@ static void virtio_transport_rx_work(struct work_struct *work)
600601
vsock->rx_buf_nr--;
601602

602603
/* Drop short/long packets */
603-
if (unlikely(len < sizeof(struct virtio_vsock_hdr) ||
604+
if (unlikely(len < sizeof(*hdr) ||
604605
len > virtio_vsock_skb_len(skb))) {
605606
kfree_skb(skb);
606607
continue;
607608
}
608609

610+
hdr = virtio_vsock_hdr(skb);
611+
payload_len = le32_to_cpu(hdr->len);
612+
if (unlikely(payload_len > len - sizeof(*hdr))) {
613+
kfree_skb(skb);
614+
continue;
615+
}
616+
609617
virtio_vsock_skb_rx_put(skb);
610618
virtio_transport_deliver_tap_pkt(skb);
611619
virtio_transport_recv_pkt(&virtio_transport, skb);

0 commit comments

Comments
 (0)