Skip to content

Commit 0a73a42

Browse files
willdeacongregkh
authored andcommitted
vhost/vsock: Avoid allocating arbitrarily-sized SKBs
commit 10a886a upstream. vhost_vsock_alloc_skb() returns NULL for packets advertising a length larger than VIRTIO_VSOCK_MAX_PKT_BUF_SIZE in the packet header. However, this is only checked once the SKB has been allocated and, if the length in the packet header is zero, the SKB may not be freed immediately. Hoist the size check before the SKB allocation so that an iovec larger than VIRTIO_VSOCK_MAX_PKT_BUF_SIZE + the header size is rejected outright. The subsequent check on the length field in the header can then simply check that the allocated SKB is indeed large enough to hold the packet. Cc: <stable@vger.kernel.org> Fixes: 71dc9ec ("virtio/vsock: replace virtio_vsock_pkt with sk_buff") Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Signed-off-by: Will Deacon <will@kernel.org> Message-Id: <20250717090116.11987-2-will@kernel.org> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 676f037 commit 0a73a42

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/vhost/vsock.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ vhost_vsock_alloc_skb(struct vhost_virtqueue *vq,
344344

345345
len = iov_length(vq->iov, out);
346346

347+
if (len > VIRTIO_VSOCK_MAX_PKT_BUF_SIZE + VIRTIO_VSOCK_SKB_HEADROOM)
348+
return NULL;
349+
347350
/* len contains both payload and hdr */
348351
skb = virtio_vsock_alloc_skb(len, GFP_KERNEL);
349352
if (!skb)
@@ -367,8 +370,7 @@ vhost_vsock_alloc_skb(struct vhost_virtqueue *vq,
367370
return skb;
368371

369372
/* The pkt is too big or the length in the header is invalid */
370-
if (payload_len > VIRTIO_VSOCK_MAX_PKT_BUF_SIZE ||
371-
payload_len + sizeof(*hdr) > len) {
373+
if (payload_len + sizeof(*hdr) > len) {
372374
kfree_skb(skb);
373375
return NULL;
374376
}

0 commit comments

Comments
 (0)