qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>,
	pbonzini@redhat.com, fam@euphon.net, qemu-devel@nongnu.org
Subject: Re: [PATCH 2/3] esp: restrict non-DMA transfer length to that of available data
Date: Wed, 27 Sep 2023 10:20:00 +0200	[thread overview]
Message-ID: <1632e156-f4a3-b782-d52a-c0862357b7c4@redhat.com> (raw)
In-Reply-To: <20230913204410.65650-3-mark.cave-ayland@ilande.co.uk>

On 13/09/2023 22.44, Mark Cave-Ayland wrote:
> In the case where a SCSI layer transfer is incorrectly terminated, it is
> possible for a TI command to cause a SCSI buffer overflow due to the
> expected transfer data length being less than the available data in the
> FIFO. When this occurs the unsigned async_len variable underflows and
> becomes a large offset which writes past the end of the allocated SCSI
> buffer.
> 
> Restrict the non-DMA transfer length to be the smallest of the expected
> transfer length and the available FIFO data to ensure that it is no longer
> possible for the SCSI buffer overflow to occur.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1810
> ---
>   hw/scsi/esp.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
> index 4218a6a960..9b11d8c573 100644
> --- a/hw/scsi/esp.c
> +++ b/hw/scsi/esp.c
> @@ -759,7 +759,8 @@ static void esp_do_nodma(ESPState *s)
>       }
>   
>       if (to_device) {
> -        len = MIN(fifo8_num_used(&s->fifo), ESP_FIFO_SZ);
> +        len = MIN(s->async_len, ESP_FIFO_SZ);
> +        len = MIN(len, fifo8_num_used(&s->fifo));
>           esp_fifo_pop_buf(&s->fifo, s->async_buf, len);
>           s->async_buf += len;
>           s->async_len -= len;

Thanks for taking care of this!

Reviewed-by: Thomas Huth <thuth@redhat.com>



  reply	other threads:[~2023-09-27  8:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-13 20:44 [PATCH 0/3] esp/scsi: minor fixes Mark Cave-Ayland
2023-09-13 20:44 ` [PATCH 1/3] esp: use correct type for esp_dma_enable() in sysbus_esp_gpio_demux() Mark Cave-Ayland
2023-09-14  6:43   ` Philippe Mathieu-Daudé
2023-09-27  8:28   ` Thomas Huth
2023-09-13 20:44 ` [PATCH 2/3] esp: restrict non-DMA transfer length to that of available data Mark Cave-Ayland
2023-09-27  8:20   ` Thomas Huth [this message]
2023-09-13 20:44 ` [PATCH 3/3] scsi-disk: ensure that FORMAT UNIT commands are terminated Mark Cave-Ayland
2023-09-27  8:26   ` Thomas Huth

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=1632e156-f4a3-b782-d52a-c0862357b7c4@redhat.com \
    --to=thuth@redhat.com \
    --cc=fam@euphon.net \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=pbonzini@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).