[Qemu-devel] [PATCH] usb-audio: ignore usb packages with wrong size

Gerd Hoffmann posted 1 patch 5 years, 4 months ago
Test asan passed
Test checkpatch passed
Test docker-mingw@fedora passed
Test docker-quick@centos7 passed
Test docker-clang@ubuntu passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20181211072649.20700-1-kraxel@redhat.com
hw/usb/dev-audio.c | 3 +++
1 file changed, 3 insertions(+)
[Qemu-devel] [PATCH] usb-audio: ignore usb packages with wrong size
Posted by Gerd Hoffmann 5 years, 4 months ago
usb packets with no payload (zero length) seem to happen in practice for
whatever reason.  Add a check and skip the packet then, otherwise we'll
trigger an assert.

Reported-by: Leonardo Soares Müller <leozinho29_eu@hotmail.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb/dev-audio.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/usb/dev-audio.c b/hw/usb/dev-audio.c
index ee43e4914d..28ac7c5165 100644
--- a/hw/usb/dev-audio.c
+++ b/hw/usb/dev-audio.c
@@ -321,6 +321,9 @@ static int streambuf_put(struct streambuf *buf, USBPacket *p)
     if (!free) {
         return 0;
     }
+    if (p->iov.size != USBAUDIO_PACKET_SIZE) {
+        return 0;
+    }
     assert(free >= USBAUDIO_PACKET_SIZE);
     usb_packet_copy(p, buf->data + (buf->prod % buf->size),
                     USBAUDIO_PACKET_SIZE);
-- 
2.9.3


Re: [Qemu-devel] [PATCH] usb-audio: ignore usb packages with wrong size
Posted by Philippe Mathieu-Daudé 5 years, 4 months ago
On 12/11/18 8:26 AM, Gerd Hoffmann wrote:
> usb packets with no payload (zero length) seem to happen in practice for
> whatever reason.  Add a check and skip the packet then, otherwise we'll
> trigger an assert.
> 
> Reported-by: Leonardo Soares Müller <leozinho29_eu@hotmail.com>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>  hw/usb/dev-audio.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/hw/usb/dev-audio.c b/hw/usb/dev-audio.c
> index ee43e4914d..28ac7c5165 100644
> --- a/hw/usb/dev-audio.c
> +++ b/hw/usb/dev-audio.c
> @@ -321,6 +321,9 @@ static int streambuf_put(struct streambuf *buf, USBPacket *p)
>      if (!free) {
>          return 0;
>      }
> +    if (p->iov.size != USBAUDIO_PACKET_SIZE) {
> +        return 0;
> +    }
>      assert(free >= USBAUDIO_PACKET_SIZE);
>      usb_packet_copy(p, buf->data + (buf->prod % buf->size),
>                      USBAUDIO_PACKET_SIZE);
>