hw/usb: Fix guest-triggerable assert crash via short CMD_SEND_OBJECT
PATCH 1/1 hw/usb: Fix guest-triggerable assert crash via short CMD_SEND_OBJECT
QEMU's USB MTP device has a guest-triggerable assertion in usb_mtp_get_data() 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 fire killing QEMU.
To prevent that is sufficient to remove the assertion, becouse the case is handled by usb_mtp_write_data() which return RES_INCOMPLETE_TRANSFER.
Resolve: https://gitlab.com/qemu-project/qemu/-/work_items/3993
--- hw/usb/dev-mtp.c | 3 --- 1 file changed, 3 deletions(-)
hw/usb/dev-mtp.c +0 -3
@@ -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.55.0
Ciao Tommaso,
Quoted 11 lines · Tommaso Califano
QEMU's USB MTP device has a guest-triggerable assertion in
usb_mtp_get_data()that fires when a guest declares a large object size inCMD_SEND_OBJECT_INFObut sends fewer bytes in the subsequentCMD_SEND_OBJECT. The assertion compares the declared size against the actual bytes received.If the guest sends
CMD_SEND_OBJECT_INFOwith size=1000 and thenCMD_SEND_OBJECTwith only 50 bytes (short, non-64-byte-aligned final USB packet) the assertion fire killing QEMU.To prevent that is sufficient to remove the assertion, becouse the case
/s/becouse/because
Quoted 2 lines
is handled by
usb_mtp_write_data()which returnRES_INCOMPLETE_TRANSFER.
Fixes tag and CC qemu stable?
Quoted 1 line
Resolve: https://gitlab.com/qemu-project/qemu/-/work_items/3993
/s/Resolve/Resolves
Quoted 23 lines
Signed-off-by Tommaso Califano <[email protected]>---
hw/usb/dev-mtp.c| 3 ---1 file changed, 3 deletions(-)hw/usb/dev-mtp.c +0
-3@@ -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.55.0
That said, code LGTM, with the changes i suggested:
Thanks,
Luigi