On Fri Nov 13, 2026 at 9:33 AM CET, marcandre.lureau wrote:
>> usb_mtp_get_data() subtracts sizeof(mtp_container) from the number of
>> bytes received, without checking. A short packet or a header declaring
>> less than 12 bytes makes these unsigned values wrap around.
>> 
>> Reject the transfer if is smaller than the container header.
>> 
>> Cc: [email protected]
>> Fixes: 88d5f381ecb2 ("usb-mtp: Introduce write support for MTP objects")
>> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4529
>> Suggested-by: Hui Peng <https://gitlab.com/benquike>
>> Signed-off-by: Tommaso Califano <[email protected]>
>> Message-ID: <[email protected]>
>> ---
>>  hw/usb/dev-mtp.c | 7 +++++++
>>  1 file changed, 7 insertions(+)
>>
>> diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
>> index 7233470558db..6fd92e5a687b 100644
>> --- a/hw/usb/dev-mtp.c
>> +++ b/hw/usb/dev-mtp.c
>> @@ -1784,6 +1784,13 @@ static void usb_mtp_get_data(MTPState *s, 
>> mtp_container *container,
>>              return;
>>      }
>>      if (d->first) {
>> +        if (cpu_to_le32(container->length) < sizeof(mtp_container)) {
>> +            usb_mtp_queue_result(s, RES_PARAMETER_NOT_SUPPORTED, d->trans,
>> +                                 0, 0, 0, 0);
>> +            usb_mtp_data_free(s->data_out);
>> +            s->data_out = NULL;
>> +            return;
>
> Should it call usb_mtp_reset_pending_write(s) here as well?

Yes, I'll add it.

Thanks,
Tommaso


Reply via email to