All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim MacArthur <jim.macarthur@linaro.org>
To: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Cc: qemu-devel@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [PATCH v2 5/6] virtio-snd: cap maximum buffer_bytes to half a GiB
Date: Wed, 11 Nov 2026 10:48:13 +0000	[thread overview]
Message-ID: <avRH7Q2ghdJuSOjd@linaro.org> (raw)
In-Reply-To: <20261110-virtio-snd-fixes-v2-5-d5b654217676@linaro.org>

On Tue, Nov 10, 2026 at 02:39:34PM +0200, Manos Pitsidianakis wrote:
> A faulty/malicious guest can try to exhaust host memory. Cap the buffer
> size to 500 MiB.
> 
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3587
> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> ---
>  hw/audio/virtio-snd.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
> index a7d749f24f..a6036d5b75 100644
> --- a/hw/audio/virtio-snd.c
> +++ b/hw/audio/virtio-snd.c
> @@ -17,6 +17,7 @@
>  
>  #include "qemu/osdep.h"
>  #include "qemu/iov.h"
> +#include "qemu/units.h"
>  #include "qemu/log.h"
>  #include "qemu/error-report.h"
>  #include "system/runstate.h"
> @@ -24,6 +25,8 @@
>  #include "qapi/error.h"
>  #include "hw/audio/virtio-snd.h"
>  
> +#define MAX_BUFFER_MIB 500
> +
>  #define VIRTIO_SOUND_JACK_DEFAULT 0
>  #define VIRTIO_SOUND_STREAM_DEFAULT 2
>  #define VIRTIO_SOUND_CHMAP_DEFAULT 0
> @@ -368,6 +371,14 @@ uint32_t virtio_snd_set_pcm_params(VirtIOSound *s,
>                       & ~(stream->info.features));
>          return cpu_to_le32(VIRTIO_SND_S_BAD_MSG);
>      }
> +    if (le32_to_cpu(params->buffer_bytes) > MAX_BUFFER_MIB * MiB) {
> +        error_report("%s: given buffer_bytes value %"PRIu32" "
> +                     "is too big: over %d MiB",
> +                     VIRTIO_DEVICE(s)->name,
> +                     le32_to_cpu(params->buffer_bytes),
> +                     MAX_BUFFER_MIB);
> +        return cpu_to_le32(VIRTIO_SND_S_BAD_MSG);
> +    }
>  
>      st_params = virtio_snd_pcm_get_params(s, stream_id);
>  
> @@ -1037,6 +1048,8 @@ static void virtio_snd_handle_tx_xfer(VirtIODevice *vdev, VirtQueue *vq)
>          }
>  
>          stream = &vsnd->streams[stream_id];
> +        size = MIN(stream->params.buffer_bytes, size);
> +
>          if (stream->info.direction != VIRTIO_SND_D_OUTPUT) {
>              goto tx_err;
>          }
> 
> -- 
> 2.56.0
> 
> 

Reviewed-by: Jim MacArthur <jim.macarthur@linaro.org>



  reply	other threads:[~2026-11-11 10:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 12:39 [PATCH v2 0/6] Various virtio-snd fixes again Manos Pitsidianakis
2026-11-10 12:39 ` [PATCH v2 1/6] virtio-snd: convert virtio_error to error_report Manos Pitsidianakis
2026-11-11 10:46   ` Jim MacArthur
2026-11-10 12:39 ` [PATCH v2 2/6] virtio-snd: add pcm_state_to_str() Manos Pitsidianakis
2026-11-11 10:47   ` Jim MacArthur
2026-11-10 12:39 ` [PATCH v2 3/6] virtio-snd: reject invalid feats in set_pcm_params Manos Pitsidianakis
2026-11-11 10:47   ` Jim MacArthur
2026-11-10 12:39 ` [PATCH v2 4/6] virtio-snd: don't allocate pcm_info zero-count buf Manos Pitsidianakis
2026-11-11 10:47   ` Jim MacArthur
2026-11-10 12:39 ` [PATCH v2 5/6] virtio-snd: cap maximum buffer_bytes to half a GiB Manos Pitsidianakis
2026-11-11 10:48   ` Jim MacArthur [this message]
2026-11-10 12:39 ` [PATCH v2 6/6] virtio-snd: period_bytes divides buffer_bytes Manos Pitsidianakis
2026-11-11 10:48   ` Jim MacArthur

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=avRH7Q2ghdJuSOjd@linaro.org \
    --to=jim.macarthur@linaro.org \
    --cc=kraxel@redhat.com \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.