* [PATCH] virtio-blk: fix short scsi inhdr host OOB write
@ 2026-05-27 16:03 Jia Jia
2026-05-27 18:11 ` Stefan Hajnoczi
0 siblings, 1 reply; 2+ messages in thread
From: Jia Jia @ 2026-05-27 16:03 UTC (permalink / raw)
To: qemu-devel; +Cc: mst, stefanha, kwolf, hreitz, qemu-block, Jia Jia, qemu-stable
virtio_blk_handle_scsi() only validates the input/output descriptor
counts and then unconditionally treats the second-to-last input
descriptor as a struct virtio_scsi_inhdr.
If that descriptor is shorter than struct virtio_scsi_inhdr, the host
still performs a 4-byte virtio_stl_p() store while writing scsi->errors.
This is reproducible as a host-side heap-buffer-overflow under ASAN:
==4022698==ERROR: AddressSanitizer: heap-buffer-overflow on address
0x504000023570 at pc 0x5e4be9c09800 bp 0x7ffebf4d7510 sp 0x7ffebf4d7500
WRITE of size 4 at 0x504000023570 thread T0
#0 0x5e4be9c097ff in stl_he_p include/qemu/bswap.h:284
#1 0x5e4be9c09c4d in stl_le_p include/qemu/bswap.h:331
#2 0x5e4be9c0a48b in virtio_stl_p include/hw/virtio/virtio-access.h:38
#3 0x5e4be9c0c201 in virtio_blk_handle_scsi ../hw/block/virtio-blk.c:207
#4 0x5e4be9c1578b in virtio_blk_handle_request ../hw/block/virtio-blk.c:926
#5 0x5e4be9c160e3 in virtio_blk_handle_vq ../hw/block/virtio-blk.c:1025
#6 0x5e4be9c16529 in virtio_blk_handle_output ../hw/block/virtio-blk.c:1058
#7 0x5e4bea713ad9 in virtio_queue_notify_vq ../hw/virtio/virtio.c:2507
#8 0x5e4bea724bfc in virtio_queue_host_notifier_read ../hw/virtio/virtio.c:3981
The same run shows the short descriptor being mapped through the
bounce-buffer path:
allocated by thread T0 here:
#0 0x736faf8b4a57 in __interceptor_calloc
#1 0x736faf1a5c50 in g_malloc0
#2 0x5e4bea925458 in address_space_map ../system/physmem.c:3746
#3 0x5e4bea6f7633 in dma_memory_map include/system/dma.h:212
#4 0x5e4bea70610a in virtqueue_map_desc ../hw/virtio/virtio.c:1637
#5 0x5e4bea70824e in virtqueue_split_pop ../hw/virtio/virtio.c:1817
#6 0x5e4bea70c9a8 in virtqueue_pop ../hw/virtio/virtio.c:2039
#7 0x5e4be9c0be03 in virtio_blk_get_request ../hw/block/virtio-blk.c:172
Reject requests whose second-to-last input descriptor is too short to
hold struct virtio_scsi_inhdr.
Cc: qemu-stable@nongnu.org
Signed-off-by: Jia Jia <physicalmtea@gmail.com>
---
hw/block/virtio-blk.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 9cb9f1fb2b..418e0dd9c6 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -197,6 +197,12 @@ static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
goto fail;
}
+ if (elem->in_sg[elem->in_num - 2].iov_len <
+ sizeof(struct virtio_scsi_inhdr)) {
+ status = VIRTIO_BLK_S_IOERR;
+ goto fail;
+ }
+
/*
* The scsi inhdr is placed in the second-to-last input segment, just
* before the regular inhdr.
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] virtio-blk: fix short scsi inhdr host OOB write
2026-05-27 16:03 [PATCH] virtio-blk: fix short scsi inhdr host OOB write Jia Jia
@ 2026-05-27 18:11 ` Stefan Hajnoczi
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2026-05-27 18:11 UTC (permalink / raw)
To: Jia Jia; +Cc: qemu-devel, mst, kwolf, hreitz, qemu-block, qemu-stable
[-- Attachment #1: Type: text/plain, Size: 461 bytes --]
On Thu, May 28, 2026 at 12:03:28AM +0800, Jia Jia wrote:
> virtio_blk_handle_scsi() only validates the input/output descriptor
> counts and then unconditionally treats the second-to-last input
> descriptor as a struct virtio_scsi_inhdr.
Hi,
A fix for this is already available here and is currently under review:
https://lore.kernel.org/qemu-devel/20260526154957.1741622-1-stefanha@redhat.com/
Please review and test the fix if you have time. Thanks!
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-27 18:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-27 16:03 [PATCH] virtio-blk: fix short scsi inhdr host OOB write Jia Jia
2026-05-27 18:11 ` Stefan Hajnoczi
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.