summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManos Pitsidianakis <manos.pitsidianakis@linaro.org>2026-02-20 11:40:15 +0200
committerMichael Tokarev <mjt@tls.msk.ru>2026-02-23 21:55:24 +0300
commit4e6f36d19069f7bc6be3da2593db1275e7cc8b47 (patch)
treee46479adfbe8379184831f9e45e5b1e61989a68f
parente55b8cd5f7a255b03e13bfc8a0c6c484515cee02 (diff)
downloadqemu-4e6f36d19069f7bc6be3da2593db1275e7cc8b47.tar.gz
qemu-4e6f36d19069f7bc6be3da2593db1275e7cc8b47.zip
virtio-snd: fix max_size bounds check in input cb
In 98e77e3d we calculated the max size and checked that each buffer is smaller than it. We neglected to subtract the size of the virtio_snd_pcm_status header from the max size, and max_size was thus larger than the correct value, leading to potential OOB writes. If the buffer cannot fit the header or can fit only the header, return the buffer immediately. Cc: qemu-stable@nongnu.org Fixes: 98e77e3dd8dd6e7aa9a7dffa60f49c8c8a49d4e3 ("virtio-snd: add max size bounds check in input cb") Reported-by: DARKNAVY <vr@darknavy.com> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20260220-virtio-snd-series-v1-4-207c4f7200a2@linaro.org> (cherry picked from commit bcb53328aa70023f1405fade4e253e7f77567261) Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
-rw-r--r--hw/audio/virtio-snd.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
index 38d9a9712c..effae20bf0 100644
--- a/hw/audio/virtio-snd.c
+++ b/hw/audio/virtio-snd.c
@@ -1255,6 +1255,12 @@ static void virtio_snd_pcm_in_cb(void *data, int available)
}
max_size = iov_size(buffer->elem->in_sg, buffer->elem->in_num);
+ if (max_size <= sizeof(virtio_snd_pcm_status)) {
+ return_rx_buffer(stream, buffer);
+ continue;
+ }
+ max_size -= sizeof(virtio_snd_pcm_status);
+
for (;;) {
if (buffer->size >= max_size) {
return_rx_buffer(stream, buffer);