From: Dmitry Frolov Date: Thu, 13 Jun 2024 14:35:30 +0000 (+0300) Subject: hw/net/virtio-net.c: fix crash in iov_copy() X-Git-Tag: v9.1.0-rc0~46^2~40 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d4f471eb7e562c2cc398448a1c1e7ee838ec30bd;p=thirdparty%2Fqemu.git hw/net/virtio-net.c: fix crash in iov_copy() A crash found while fuzzing device virtio-net-socket-check-used. Assertion "offset == 0" in iov_copy() fails if less than guest_hdr_len bytes were transmited. Signed-off-by: Dmitry Frolov Message-Id: <20240613143529.602591-2-frolov@swemel.ru> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 9c7e85caea1..8f309727086 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -2735,6 +2735,10 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q) */ assert(n->host_hdr_len <= n->guest_hdr_len); if (n->host_hdr_len != n->guest_hdr_len) { + if (iov_size(out_sg, out_num) < n->guest_hdr_len) { + virtio_error(vdev, "virtio-net header is invalid"); + goto detach; + } unsigned sg_num = iov_copy(sg, ARRAY_SIZE(sg), out_sg, out_num, 0, n->host_hdr_len);