Skip to contentSkip to conversation

hw/usb/dev-mtp: Fix assert crash on short CMD_SEND_OBJECT

PATCH Applied Tommaso Califano 4 participants 4 messages Oct 8

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hw/usb/dev-mtp: Fix assert crash on short CMD_SEND_OBJECT

In usb_mtp_get_data() there is a guest-triggerable assertion that fires when a guest declares a large object size in CMD_SEND_OBJECT_INFO but sends fewer bytes in the subsequent CMD_SEND_OBJECT. The assertion compares the declared size against the actual bytes received.

If the guest sends CMD_SEND_OBJECT_INFO with size=1000 and then CMD_SEND_OBJECT with only 50 bytes (short, non-64-byte-aligned final USB packet) the assertion fires, killing QEMU.

To prevent that is sufficient to remove the assertion, because the case is handled by usb_mtp_write_data() which returns RES_INCOMPLETE_TRANSFER.

Fixes 3e096650a64d ("dev-mtp: Add support for > 4GB file transfers")

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3993

---
V2:
- Add Fixes tag.
- Correct and improve commit message readability.

hw/usb/dev-mtp.c | 3 ---

 1 file changed, 3 deletions(-)
hw/usb/dev-mtp.c +0 -3
index 1d8cfd32dc..406793fc03 100644
@@ -1813,9 +1813,6 @@ static void usb_mtp_get_data(MTPState *s, mtp_container *container,
         d->offset += dlen;
         d->data_offset += dlen;
         if ((p->iov.size % 64) || !p->iov.size) {
-            assert((s->dataset.size == 0xFFFFFFFF) ||
-                   (s->dataset.size == d->offset));
-
             if (d->length == MTP_WRITE_BUF_SZ) {
                 d->write_status = WRITE_END;
             } else {
Signature · 1 line
2.56.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines · Tommaso Califano

In usb_mtp_get_data() there is a guest-triggerable assertion that fires when a guest declares a large object size in CMD_SEND_OBJECT_INFO but sends fewer bytes in the subsequent CMD_SEND_OBJECT. The assertion compares the declared size against the actual bytes received.

If the guest sends CMD_SEND_OBJECT_INFO with size=1000 and then CMD_SEND_OBJECT with only 50 bytes (short, non-64-byte-aligned final USB packet) the assertion fires, killing QEMU.

Quoted 6 lines

To prevent that is sufficient to remove the assertion, because the case is handled by usb_mtp_write_data() which returns RES_INCOMPLETE_TRANSFER.

Fixes 3e096650a64d ("dev-mtp: Add support for > 4GB file transfers")

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3993

Quoted 26 lines

---
V2:
- Add Fixes tag.
- Correct and improve commit message readability.

hw/usb/dev-mtp.c | 3 ---

 1 file changed, 3 deletions(-)
hw/usb/dev-mtp.c +0 -4
index 1d8cfd32dc..406793fc03 100644
@@ -1813,9 +1813,6 @@ static void usb_mtp_get_data(MTPState *s, mtp_container *container,
         d->offset += dlen;
         d->data_offset += dlen;
         if ((p->iov.size % 64) || !p->iov.size) {
-            assert((s->dataset.size == 0xFFFFFFFF) ||
-                   (s->dataset.size == d->offset));
-
             if (d->length == MTP_WRITE_BUF_SZ) {
                 d->write_status = WRITE_END;
             } else {
--

2.56.0

Signature · 1 line
Marc-André Lureau
Reviewed-by on v2 1/1
#2 lore raw
In reply to Tommaso Califano
Quoted 9 lines · Tommaso Califano

In usb_mtp_get_data() there is a guest-triggerable assertion that fires when a guest declares a large object size in CMD_SEND_OBJECT_INFO but sends fewer bytes in the subsequent CMD_SEND_OBJECT. The assertion compares the declared size against the actual bytes received.

If the guest sends CMD_SEND_OBJECT_INFO with size=1000 and then CMD_SEND_OBJECT with only 50 bytes (short, non-64-byte-aligned final USB packet) the assertion fires, killing QEMU.

Quoted 6 lines

To prevent that is sufficient to remove the assertion, because the case is handled by usb_mtp_write_data() which returns RES_INCOMPLETE_TRANSFER.

Fixes 3e096650a64d ("dev-mtp: Add support for > 4GB file transfers")

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3993

#3 lore raw
In reply to Tommaso Califano
Quoted 14 lines · Tommaso Califano

In usb_mtp_get_data() there is a guest-triggerable assertion that fires when a guest declares a large object size in CMD_SEND_OBJECT_INFO but sends fewer bytes in the subsequent CMD_SEND_OBJECT. The assertion compares the declared size against the actual bytes received.

If the guest sends CMD_SEND_OBJECT_INFO with size=1000 and then CMD_SEND_OBJECT with only 50 bytes (short, non-64-byte-aligned final USB packet) the assertion fires, killing QEMU.

To prevent that is sufficient to remove the assertion, because the case is handled by usb_mtp_write_data() which returns RES_INCOMPLETE_TRANSFER.

Fixes 3e096650a64d ("dev-mtp: Add support for > 4GB file transfers")

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3993

Quoted 8 lines

---
V2:
- Add Fixes tag.
- Correct and improve commit message readability.

hw/usb/dev-mtp.c | 3 ---

  1 file changed, 3 deletions(-)

Queued via hw-misc, thanks!