All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
* [PATCH hci-dev 0/1] hw/ide/atapi: fix abort on CD-ROM reads past LBA 2^31 #VSTOR-154795
@ 2026-11-12 13:47 Denis V. Lunev
  2026-11-12 13:47 ` [PATCH hci-dev 1/1] " Denis V. Lunev
  0 siblings, 1 reply; 4+ messages in thread
From: Denis V. Lunev @ 2026-11-12 13:47 UTC (permalink / raw)
  To: svt-core; +Cc: andrey.drobyshev, den

A VM with a CD-ROM larger than 4 TiB aborts on the first guest read at
LBA 2^31 or above:

  ide_atapi_cmd_read_pio: Assertion `0 <= lba && lba < (s->nb_sectors >> 2)' failed.

VSTOR-154795 hit it on a production node: the cinder volume behind the
CD-ROM was 8 GiB at one start of the VM and 8000 GiB at the next, and the
VM aborted 10 s after that second start. The 32-bit LBA from the CDB passes
the range check, then turns negative when passed on as an int. The patch
carries it as uint32_t and widens IDEState.lba to int64_t.

Upstream has the same code. The same patch goes to qemu-devel and is not
merged yet. The only difference here is hw/ide/trace-events: this tree
no longer has the cd_read_sector_sync event.

The new qtests /ahci/cdrom/{pio,dma}/high_lba abort on unpatched hci-dev
and pass with the patch, and ahci-test and ide-test pass. The x86_64
qtest and unit suites give the same result with and without the patch:
ivshmem-test, test-hmp and qom-test abort on this tree either way. The
upstream version also passed a full make check on all targets and the
raw and qcow2 iotests.

Denis V. Lunev (1):
  hw/ide/atapi: fix abort on CD-ROM reads past LBA 2^31 #VSTOR-154795

 hw/ide/atapi.c           | 18 +++++++++---------
 hw/ide/macio.c           |  2 +-
 hw/ide/trace-events      |  8 ++++----
 include/hw/ide/ide-dev.h |  2 +-
 tests/qtest/ahci-test.c  | 36 ++++++++++++++++++++++++++++++++++++
 5 files changed, 51 insertions(+), 15 deletions(-)


base-commit: b39d755d7ac95c46e771833f558e99196340ac66
-- 
2.53.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH hci-dev 1/1] hw/ide/atapi: fix abort on CD-ROM reads past LBA 2^31 #VSTOR-154795
  2026-11-12 13:47 [PATCH hci-dev 0/1] hw/ide/atapi: fix abort on CD-ROM reads past LBA 2^31 #VSTOR-154795 Denis V. Lunev
@ 2026-11-12 13:47 ` Denis V. Lunev
  2026-11-12 13:51   ` no-reply
  2026-11-12 17:12   ` Andrey Drobyshev
  0 siblings, 2 replies; 4+ messages in thread
From: Denis V. Lunev @ 2026-11-12 13:47 UTC (permalink / raw)
  To: svt-core; +Cc: andrey.drobyshev, den

From: Denis V. Lunev <den@openvz.org>

cmd_read() and cmd_read_cd() check the 32-bit LBA from the CDB against
the medium size, then pass it to ide_atapi_cmd_read() as an int. On a
medium larger than 4 TiB, a read at LBA 2^31 or above passes the range
check, turns negative and trips the assertion:

  hw/ide/atapi.c:315: ide_atapi_cmd_read_pio: Assertion
  `0 <= lba && lba < (s->nb_sectors >> 2)' failed.

Reading the last sector is enough, e.g. a UDF anchor probe, so the
guest aborts QEMU just by looking at the disc.

Pass the LBA as uint32_t, which is what the CDB carries, and widen
IDEState.lba to int64_t so it holds every valid LBA and keeps -1 as
the "not a sector read" marker. The field is not migrated.

Fixes: b8d7f1bc5927 ("ide: atapi: check logical block address and read size (CVE-2020-29443)")
Signed-off-by: Denis V. Lunev <den@openvz.org>
Cc: John Snow <jsnow@redhat.com>
Cc: Fabiano Rosas <farosas@suse.de>
Cc: Laurent Vivier <lvivier@redhat.com>
---
 hw/ide/atapi.c           | 18 +++++++++---------
 hw/ide/macio.c           |  2 +-
 hw/ide/trace-events      |  8 ++++----
 include/hw/ide/ide-dev.h |  2 +-
 tests/qtest/ahci-test.c  | 36 ++++++++++++++++++++++++++++++++++++
 5 files changed, 51 insertions(+), 15 deletions(-)

diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index a31b945a66a..1fa73041938 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -47,7 +47,7 @@ static void padstr8(uint8_t *buf, int buf_size, const char *src)
     }
 }
 
-static void lba_to_msf(uint8_t *buf, int lba)
+static void lba_to_msf(uint8_t *buf, int64_t lba)
 {
     lba += 150;
     buf[0] = (lba / 75) / 60;
@@ -71,7 +71,7 @@ static inline int media_is_cd(IDEState *s)
     return (media_present(s) && s->nb_sectors <= CD_MAX_SECTORS);
 }
 
-static void cd_data_to_raw(uint8_t *buf, int lba)
+static void cd_data_to_raw(uint8_t *buf, int64_t lba)
 {
     /* sync bytes */
     buf[0] = 0x00;
@@ -318,10 +318,10 @@ static void ide_atapi_cmd_reply(IDEState *s, int size, int max_size)
 }
 
 /* start a CD-ROM read command */
-static void ide_atapi_cmd_read_pio(IDEState *s, int lba, int nb_sectors,
-                                   int sector_size)
+static void ide_atapi_cmd_read_pio(IDEState *s, uint32_t lba,
+                                   int nb_sectors, int sector_size)
 {
-    assert(0 <= lba && lba < (s->nb_sectors >> 2));
+    assert(lba < (s->nb_sectors >> 2));
 
     s->lba = lba;
     s->packet_transfer_size = nb_sectors * sector_size;
@@ -423,10 +423,10 @@ eot:
 
 /* start a CD-ROM read command with DMA */
 /* XXX: test if DMA is available */
-static void ide_atapi_cmd_read_dma(IDEState *s, int lba, int nb_sectors,
-                                   int sector_size)
+static void ide_atapi_cmd_read_dma(IDEState *s, uint32_t lba,
+                                   int nb_sectors, int sector_size)
 {
-    assert(0 <= lba && lba < (s->nb_sectors >> 2));
+    assert(lba < (s->nb_sectors >> 2));
 
     s->lba = lba;
     s->packet_transfer_size = nb_sectors * sector_size;
@@ -441,7 +441,7 @@ static void ide_atapi_cmd_read_dma(IDEState *s, int lba, int nb_sectors,
     ide_start_dma(s, ide_atapi_cmd_read_dma_cb);
 }
 
-static void ide_atapi_cmd_read(IDEState *s, int lba, int nb_sectors,
+static void ide_atapi_cmd_read(IDEState *s, uint32_t lba, int nb_sectors,
                                int sector_size)
 {
     trace_ide_atapi_cmd_read(s, s->atapi_dma ? "dma" : "pio",
diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index c23bf32d2b1..b539a31f1ce 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -396,7 +396,7 @@ static void ide_dbdma_start(const IDEDMA *dma, IDEState *s,
     MACIO_DPRINTF("\n\n------------ IDE transfer\n");
     MACIO_DPRINTF("buffer_size: %x   buffer_index: %x\n",
                   s->io_buffer_size, s->io_buffer_index);
-    MACIO_DPRINTF("lba: %x    size: %x\n", s->lba, s->io_buffer_size);
+    MACIO_DPRINTF("lba: %" PRIx64 "    size: %x\n", s->lba, s->io_buffer_size);
     MACIO_DPRINTF("-------------------------\n");
 
     m->dma_active = true;
diff --git a/hw/ide/trace-events b/hw/ide/trace-events
index ca696ebd6d7..c0aaeb15a03 100644
--- a/hw/ide/trace-events
+++ b/hw/ide/trace-events
@@ -47,17 +47,17 @@ bmdma_read_via(uint64_t addr, uint32_t val) "bmdma: readb 0x%"PRIx64" : 0x%02x"
 bmdma_write_via(uint64_t addr, uint64_t val) "bmdma: writeb 0x%"PRIx64" : 0x%02"PRIx64
 
 # atapi.c
-cd_read_sector_cb(int lba, int ret) "lba=%d ret=%d"
-cd_read_sector(int lba) "lba=%d"
+cd_read_sector_cb(int64_t lba, int ret) "lba=%"PRId64" ret=%d"
+cd_read_sector(int64_t lba) "lba=%"PRId64
 ide_atapi_cmd_error(void *s, int sense_key, int asc) "IDEState: %p; sense=0x%x asc=0x%x"
 ide_atapi_cmd_reply_end(void *s, int tx_size, int elem_tx_size, int32_t index) "IDEState %p; reply: tx_size=%d elem_tx_size=%d index=%"PRId32
 ide_atapi_cmd_reply_end_eot(void *s, int status) "IDEState: %p; end of transfer, status=0x%x"
 ide_atapi_cmd_reply_end_bcl(void *s, int bcl) "IDEState: %p; byte_count_limit=%d"
 ide_atapi_cmd_reply_end_new(void *s, int status) "IDEState: %p; new transfer started, status=0x%x"
 ide_atapi_cmd_check_status(void *s) "IDEState: %p"
-ide_atapi_cmd_read(void *s, const char *method, int lba, int nb_sectors) "IDEState: %p; read %s: LBA=%d nb_sectors=%d"
+ide_atapi_cmd_read(void *s, const char *method, uint32_t lba, int nb_sectors) "IDEState: %p; read %s: LBA=%"PRIu32" nb_sectors=%d"
 ide_atapi_cmd(void *s, uint8_t cmd) "IDEState: %p; cmd: 0x%02x"
-ide_atapi_cmd_read_dma_cb_aio(void *s, int lba, int n) "IDEState: %p; aio read: lba=%d n=%d"
+ide_atapi_cmd_read_dma_cb_aio(void *s, int64_t lba, int n) "IDEState: %p; aio read: lba=%"PRId64" n=%d"
 # Warning: Verbose
 ide_atapi_cmd_packet(void *s, uint16_t limit, const char *packet) "IDEState: %p; limit=0x%x packet: %s"
 
diff --git a/include/hw/ide/ide-dev.h b/include/hw/ide/ide-dev.h
index 92e88687800..d6f646528aa 100644
--- a/include/hw/ide/ide-dev.h
+++ b/include/hw/ide/ide-dev.h
@@ -101,7 +101,7 @@ struct IDEState {
     int packet_transfer_size;
     int elementary_transfer_size;
     int32_t io_buffer_index;
-    int lba;
+    int64_t lba;
     int cd_sector_size;
     int atapi_dma; /* true if dma is requested for the packet cmd */
     BlockAcctCookie acct;
diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
index 26082eed3a1..30564982722 100644
--- a/tests/qtest/ahci-test.c
+++ b/tests/qtest/ahci-test.c
@@ -1691,6 +1691,40 @@ static void test_cdrom_pio_raw(void)
     ahci_test_cdrom_raw(3, false);
 }
 
+/* Regression test: read the last sector of a medium over 4 TiB. */
+static void ahci_test_cdrom_high_lba(bool dma)
+{
+    AHCIQState *ahci;
+    g_autofree unsigned char *tx = g_malloc0(ATAPI_SECTOR_SIZE);
+    uint64_t lba = (uint64_t)INT32_MAX + 1;
+    AHCIOpts opts = {
+        .size = ATAPI_SECTOR_SIZE,
+        .lba = lba,
+        .atapi = true,
+        .atapi_dma = dma,
+        .post_cb = ahci_cb_cmp_buff,
+        .opaque = tx,
+    };
+
+    ahci = ahci_boot_and_enable("-blockdev driver=null-co,node-name=cd0,"
+                                "read-only=on,read-zeroes=on,size=%" PRIu64 " "
+                                "-M q35 "
+                                "-device ide-cd,drive=cd0 ",
+                                (lba + 1) * ATAPI_SECTOR_SIZE);
+    ahci_exec(ahci, ahci_port_select(ahci), CMD_ATAPI_READ_10, &opts);
+    ahci_shutdown(ahci);
+}
+
+static void test_cdrom_dma_high_lba(void)
+{
+    ahci_test_cdrom_high_lba(true);
+}
+
+static void test_cdrom_pio_high_lba(void)
+{
+    ahci_test_cdrom_high_lba(false);
+}
+
 /*
  * Regression test: a buffered ATAPI read completing after a command
  * engine restart must not dereference the cleared cur_cmd. Cover both
@@ -2234,6 +2268,8 @@ int main(int argc, char **argv)
     qtest_add_func("/ahci/cdrom/pio/single", test_cdrom_pio);
     qtest_add_func("/ahci/cdrom/pio/multi", test_cdrom_pio_multi);
     qtest_add_func("/ahci/cdrom/pio/raw", test_cdrom_pio_raw);
+    qtest_add_func("/ahci/cdrom/dma/high_lba", test_cdrom_dma_high_lba);
+    qtest_add_func("/ahci/cdrom/pio/high_lba", test_cdrom_pio_high_lba);
 
     qtest_add_func("/ahci/cdrom/pio/bcl", test_atapi_bcl);
     qtest_add_func("/ahci/cdrom/eject", test_atapi_tray);
-- 
2.53.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH hci-dev 1/1] hw/ide/atapi: fix abort on CD-ROM reads past LBA 2^31 #VSTOR-154795
  2026-11-12 13:47 ` [PATCH hci-dev 1/1] " Denis V. Lunev
@ 2026-11-12 13:51   ` no-reply
  2026-11-12 17:12   ` Andrey Drobyshev
  1 sibling, 0 replies; 4+ messages in thread
From: no-reply @ 2026-11-12 13:51 UTC (permalink / raw)
  To: Denis V. Lunev, svt-core; +Cc: andrey.drobyshev, den

> From: Denis V. Lunev <den@openvz.org>
> 
> cmd_read() and cmd_read_cd() check the 32-bit LBA from the CDB against
> the medium size, then pass it to ide_atapi_cmd_read() as an int. On a
> medium larger than 4 TiB, a read at LBA 2^31 or above passes the range
> check, turns negative and trips the assertion:
> 
>   hw/ide/atapi.c:315: ide_atapi_cmd_read_pio: Assertion
>   `0 <= lba && lba < (s->nb_sectors >> 2)' failed.
> 
> Reading the last sector is enough, e.g. a UDF anchor probe, so the
> guest aborts QEMU just by looking at the disc.
> 
> Pass the LBA as uint32_t, which is what the CDB carries, and widen
> IDEState.lba to int64_t so it holds every valid LBA and keeps -1 as
> the "not a sector read" marker. The field is not migrated.
> 
> Fixes: b8d7f1bc5927 ("ide: atapi: check logical block address and read size (CVE-2020-29443)")
> Signed-off-by: Denis V. Lunev <den@openvz.org>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261112134758.646697-1-den@openvz.org?part=1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH hci-dev 1/1] hw/ide/atapi: fix abort on CD-ROM reads past LBA 2^31 #VSTOR-154795
  2026-11-12 13:47 ` [PATCH hci-dev 1/1] " Denis V. Lunev
  2026-11-12 13:51   ` no-reply
@ 2026-11-12 17:12   ` Andrey Drobyshev
  1 sibling, 0 replies; 4+ messages in thread
From: Andrey Drobyshev @ 2026-11-12 17:12 UTC (permalink / raw)
  To: Denis V. Lunev, svt-core

Ack
Applied to hci-dev

On 11/12/26 3:47 PM, Denis V. Lunev wrote:
> From: Denis V. Lunev <den@openvz.org>
> 
> cmd_read() and cmd_read_cd() check the 32-bit LBA from the CDB against
> the medium size, then pass it to ide_atapi_cmd_read() as an int. On a
> medium larger than 4 TiB, a read at LBA 2^31 or above passes the range
> check, turns negative and trips the assertion:
> 
>   hw/ide/atapi.c:315: ide_atapi_cmd_read_pio: Assertion
>   `0 <= lba && lba < (s->nb_sectors >> 2)' failed.
> 
> Reading the last sector is enough, e.g. a UDF anchor probe, so the
> guest aborts QEMU just by looking at the disc.
> 
> Pass the LBA as uint32_t, which is what the CDB carries, and widen
> IDEState.lba to int64_t so it holds every valid LBA and keeps -1 as
> the "not a sector read" marker. The field is not migrated.
> 
> Fixes: b8d7f1bc5927 ("ide: atapi: check logical block address and read size (CVE-2020-29443)")
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> Cc: John Snow <jsnow@redhat.com>
> Cc: Fabiano Rosas <farosas@suse.de>
> Cc: Laurent Vivier <lvivier@redhat.com>
> ---
>  hw/ide/atapi.c           | 18 +++++++++---------
>  hw/ide/macio.c           |  2 +-
>  hw/ide/trace-events      |  8 ++++----
>  include/hw/ide/ide-dev.h |  2 +-
>  tests/qtest/ahci-test.c  | 36 ++++++++++++++++++++++++++++++++++++
>  5 files changed, 51 insertions(+), 15 deletions(-)
> 
> diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
> index a31b945a66a..1fa73041938 100644
> --- a/hw/ide/atapi.c
> +++ b/hw/ide/atapi.c
> @@ -47,7 +47,7 @@ static void padstr8(uint8_t *buf, int buf_size, const char *src)
>      }
>  }
>  
> -static void lba_to_msf(uint8_t *buf, int lba)
> +static void lba_to_msf(uint8_t *buf, int64_t lba)
>  {
>      lba += 150;
>      buf[0] = (lba / 75) / 60;
> @@ -71,7 +71,7 @@ static inline int media_is_cd(IDEState *s)
>      return (media_present(s) && s->nb_sectors <= CD_MAX_SECTORS);
>  }
>  
> -static void cd_data_to_raw(uint8_t *buf, int lba)
> +static void cd_data_to_raw(uint8_t *buf, int64_t lba)
>  {
>      /* sync bytes */
>      buf[0] = 0x00;
> @@ -318,10 +318,10 @@ static void ide_atapi_cmd_reply(IDEState *s, int size, int max_size)
>  }
>  
>  /* start a CD-ROM read command */
> -static void ide_atapi_cmd_read_pio(IDEState *s, int lba, int nb_sectors,
> -                                   int sector_size)
> +static void ide_atapi_cmd_read_pio(IDEState *s, uint32_t lba,
> +                                   int nb_sectors, int sector_size)
>  {
> -    assert(0 <= lba && lba < (s->nb_sectors >> 2));
> +    assert(lba < (s->nb_sectors >> 2));
>  
>      s->lba = lba;
>      s->packet_transfer_size = nb_sectors * sector_size;
> @@ -423,10 +423,10 @@ eot:
>  
>  /* start a CD-ROM read command with DMA */
>  /* XXX: test if DMA is available */
> -static void ide_atapi_cmd_read_dma(IDEState *s, int lba, int nb_sectors,
> -                                   int sector_size)
> +static void ide_atapi_cmd_read_dma(IDEState *s, uint32_t lba,
> +                                   int nb_sectors, int sector_size)
>  {
> -    assert(0 <= lba && lba < (s->nb_sectors >> 2));
> +    assert(lba < (s->nb_sectors >> 2));
>  
>      s->lba = lba;
>      s->packet_transfer_size = nb_sectors * sector_size;
> @@ -441,7 +441,7 @@ static void ide_atapi_cmd_read_dma(IDEState *s, int lba, int nb_sectors,
>      ide_start_dma(s, ide_atapi_cmd_read_dma_cb);
>  }
>  
> -static void ide_atapi_cmd_read(IDEState *s, int lba, int nb_sectors,
> +static void ide_atapi_cmd_read(IDEState *s, uint32_t lba, int nb_sectors,
>                                 int sector_size)
>  {
>      trace_ide_atapi_cmd_read(s, s->atapi_dma ? "dma" : "pio",
> diff --git a/hw/ide/macio.c b/hw/ide/macio.c
> index c23bf32d2b1..b539a31f1ce 100644
> --- a/hw/ide/macio.c
> +++ b/hw/ide/macio.c
> @@ -396,7 +396,7 @@ static void ide_dbdma_start(const IDEDMA *dma, IDEState *s,
>      MACIO_DPRINTF("\n\n------------ IDE transfer\n");
>      MACIO_DPRINTF("buffer_size: %x   buffer_index: %x\n",
>                    s->io_buffer_size, s->io_buffer_index);
> -    MACIO_DPRINTF("lba: %x    size: %x\n", s->lba, s->io_buffer_size);
> +    MACIO_DPRINTF("lba: %" PRIx64 "    size: %x\n", s->lba, s->io_buffer_size);
>      MACIO_DPRINTF("-------------------------\n");
>  
>      m->dma_active = true;
> diff --git a/hw/ide/trace-events b/hw/ide/trace-events
> index ca696ebd6d7..c0aaeb15a03 100644
> --- a/hw/ide/trace-events
> +++ b/hw/ide/trace-events
> @@ -47,17 +47,17 @@ bmdma_read_via(uint64_t addr, uint32_t val) "bmdma: readb 0x%"PRIx64" : 0x%02x"
>  bmdma_write_via(uint64_t addr, uint64_t val) "bmdma: writeb 0x%"PRIx64" : 0x%02"PRIx64
>  
>  # atapi.c
> -cd_read_sector_cb(int lba, int ret) "lba=%d ret=%d"
> -cd_read_sector(int lba) "lba=%d"
> +cd_read_sector_cb(int64_t lba, int ret) "lba=%"PRId64" ret=%d"
> +cd_read_sector(int64_t lba) "lba=%"PRId64
>  ide_atapi_cmd_error(void *s, int sense_key, int asc) "IDEState: %p; sense=0x%x asc=0x%x"
>  ide_atapi_cmd_reply_end(void *s, int tx_size, int elem_tx_size, int32_t index) "IDEState %p; reply: tx_size=%d elem_tx_size=%d index=%"PRId32
>  ide_atapi_cmd_reply_end_eot(void *s, int status) "IDEState: %p; end of transfer, status=0x%x"
>  ide_atapi_cmd_reply_end_bcl(void *s, int bcl) "IDEState: %p; byte_count_limit=%d"
>  ide_atapi_cmd_reply_end_new(void *s, int status) "IDEState: %p; new transfer started, status=0x%x"
>  ide_atapi_cmd_check_status(void *s) "IDEState: %p"
> -ide_atapi_cmd_read(void *s, const char *method, int lba, int nb_sectors) "IDEState: %p; read %s: LBA=%d nb_sectors=%d"
> +ide_atapi_cmd_read(void *s, const char *method, uint32_t lba, int nb_sectors) "IDEState: %p; read %s: LBA=%"PRIu32" nb_sectors=%d"
>  ide_atapi_cmd(void *s, uint8_t cmd) "IDEState: %p; cmd: 0x%02x"
> -ide_atapi_cmd_read_dma_cb_aio(void *s, int lba, int n) "IDEState: %p; aio read: lba=%d n=%d"
> +ide_atapi_cmd_read_dma_cb_aio(void *s, int64_t lba, int n) "IDEState: %p; aio read: lba=%"PRId64" n=%d"
>  # Warning: Verbose
>  ide_atapi_cmd_packet(void *s, uint16_t limit, const char *packet) "IDEState: %p; limit=0x%x packet: %s"
>  
> diff --git a/include/hw/ide/ide-dev.h b/include/hw/ide/ide-dev.h
> index 92e88687800..d6f646528aa 100644
> --- a/include/hw/ide/ide-dev.h
> +++ b/include/hw/ide/ide-dev.h
> @@ -101,7 +101,7 @@ struct IDEState {
>      int packet_transfer_size;
>      int elementary_transfer_size;
>      int32_t io_buffer_index;
> -    int lba;
> +    int64_t lba;
>      int cd_sector_size;
>      int atapi_dma; /* true if dma is requested for the packet cmd */
>      BlockAcctCookie acct;
> diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
> index 26082eed3a1..30564982722 100644
> --- a/tests/qtest/ahci-test.c
> +++ b/tests/qtest/ahci-test.c
> @@ -1691,6 +1691,40 @@ static void test_cdrom_pio_raw(void)
>      ahci_test_cdrom_raw(3, false);
>  }
>  
> +/* Regression test: read the last sector of a medium over 4 TiB. */
> +static void ahci_test_cdrom_high_lba(bool dma)
> +{
> +    AHCIQState *ahci;
> +    g_autofree unsigned char *tx = g_malloc0(ATAPI_SECTOR_SIZE);
> +    uint64_t lba = (uint64_t)INT32_MAX + 1;
> +    AHCIOpts opts = {
> +        .size = ATAPI_SECTOR_SIZE,
> +        .lba = lba,
> +        .atapi = true,
> +        .atapi_dma = dma,
> +        .post_cb = ahci_cb_cmp_buff,
> +        .opaque = tx,
> +    };
> +
> +    ahci = ahci_boot_and_enable("-blockdev driver=null-co,node-name=cd0,"
> +                                "read-only=on,read-zeroes=on,size=%" PRIu64 " "
> +                                "-M q35 "
> +                                "-device ide-cd,drive=cd0 ",
> +                                (lba + 1) * ATAPI_SECTOR_SIZE);
> +    ahci_exec(ahci, ahci_port_select(ahci), CMD_ATAPI_READ_10, &opts);
> +    ahci_shutdown(ahci);
> +}
> +
> +static void test_cdrom_dma_high_lba(void)
> +{
> +    ahci_test_cdrom_high_lba(true);
> +}
> +
> +static void test_cdrom_pio_high_lba(void)
> +{
> +    ahci_test_cdrom_high_lba(false);
> +}
> +
>  /*
>   * Regression test: a buffered ATAPI read completing after a command
>   * engine restart must not dereference the cleared cur_cmd. Cover both
> @@ -2234,6 +2268,8 @@ int main(int argc, char **argv)
>      qtest_add_func("/ahci/cdrom/pio/single", test_cdrom_pio);
>      qtest_add_func("/ahci/cdrom/pio/multi", test_cdrom_pio_multi);
>      qtest_add_func("/ahci/cdrom/pio/raw", test_cdrom_pio_raw);
> +    qtest_add_func("/ahci/cdrom/dma/high_lba", test_cdrom_dma_high_lba);
> +    qtest_add_func("/ahci/cdrom/pio/high_lba", test_cdrom_pio_high_lba);
>  
>      qtest_add_func("/ahci/cdrom/pio/bcl", test_atapi_bcl);
>      qtest_add_func("/ahci/cdrom/eject", test_atapi_tray);


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-12 17:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-12 13:47 [PATCH hci-dev 0/1] hw/ide/atapi: fix abort on CD-ROM reads past LBA 2^31 #VSTOR-154795 Denis V. Lunev
2026-11-12 13:47 ` [PATCH hci-dev 1/1] " Denis V. Lunev
2026-11-12 13:51   ` no-reply
2026-11-12 17:12   ` Andrey Drobyshev

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.