[PATCH] hw/usb/dev-storage: Fix heap overflow on BOT reset (CVE-2026-121860)

Tommaso Califano posted 1 patch 1 day, 12 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20261126131312.47658-1-tcalifano@redhat.com
hw/usb/dev-storage.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] hw/usb/dev-storage: Fix heap overflow on BOT reset (CVE-2026-121860)
Posted by Tommaso Califano 1 day, 12 hours ago
Handling a Bulk-Only Mass Storage Reset only reset the state machine to
USB_MSDM_CBW, leaving active SCSI requests in flight. Subsequent CBWs
would overwrite s->req without unreferencing the old request, causing
late callbacks to pair stale transfer lengths (s->scsi_len) with new,
smaller request buffers leading to a guest-controlled heap buffer
overflow of up to ~124 KiB on DATAOUT transfers.

Route the class reset through usb_msd_handle_reset() instead of
open-coding the state transition. This also ensures s->needs_reset is
cleared, allowing a guest that triggered usb_msd_fatal_error() to
recover without requiring a full port reset.

This aligns with the "Universal Serial Bus Mass Storage Class Bulk-Only
Transport" specification (section 5.3.3.1).

Cc: qemu-stable@nongnu.org
Fixes: CVE-2026-121860
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4578
Signed-off-by: Tommaso Califano <tcalifano@redhat.com>
---
 hw/usb/dev-storage.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index 040cf15051..4f1e33506d 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -358,8 +358,8 @@ static void usb_msd_handle_control(USBDevice *dev, USBPacket *p,
         break;
         /* Class specific requests.  */
     case ClassInterfaceOutRequest | MassStorageReset:
-        /* Reset state ready for the next CBW.  */
-        s->mode = USB_MSDM_CBW;
+        /* Reset the device for the next CBW.  */
+        usb_msd_handle_reset(dev);
         break;
     case ClassInterfaceRequest | GetMaxLun:
         maxlun = 0;
-- 
2.56.1
Re: [PATCH] hw/usb/dev-storage: Fix heap overflow on BOT reset (CVE-2026-121860)
Posted by Peter Maydell 9 hours ago
On Thu, 26 Nov 2026 at 13:13, Tommaso Califano <tcalifano@redhat.com> wrote:
>
> Handling a Bulk-Only Mass Storage Reset only reset the state machine to
> USB_MSDM_CBW, leaving active SCSI requests in flight. Subsequent CBWs
> would overwrite s->req without unreferencing the old request, causing
> late callbacks to pair stale transfer lengths (s->scsi_len) with new,
> smaller request buffers leading to a guest-controlled heap buffer
> overflow of up to ~124 KiB on DATAOUT transfers.
>
> Route the class reset through usb_msd_handle_reset() instead of
> open-coding the state transition. This also ensures s->needs_reset is
> cleared, allowing a guest that triggered usb_msd_fatal_error() to
> recover without requiring a full port reset.
>
> This aligns with the "Universal Serial Bus Mass Storage Class Bulk-Only
> Transport" specification (section 5.3.3.1).
>
> Cc: qemu-stable@nongnu.org
> Fixes: CVE-2026-121860
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4578
> Signed-off-by: Tommaso Califano <tcalifano@redhat.com>
> ---
>  hw/usb/dev-storage.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
> index 040cf15051..4f1e33506d 100644
> --- a/hw/usb/dev-storage.c
> +++ b/hw/usb/dev-storage.c
> @@ -358,8 +358,8 @@ static void usb_msd_handle_control(USBDevice *dev, USBPacket *p,
>          break;
>          /* Class specific requests.  */
>      case ClassInterfaceOutRequest | MassStorageReset:
> -        /* Reset state ready for the next CBW.  */
> -        s->mode = USB_MSDM_CBW;
> +        /* Reset the device for the next CBW.  */
> +        usb_msd_handle_reset(dev);
>          break;
>      case ClassInterfaceRequest | GetMaxLun:
>          maxlun = 0;

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM