Patchwork usb-redir: fix use-after-free

login
register
mail settings
Submitter Gerd Hoffmann
Date July 31, 2013, 9:21 a.m.
Message ID <1375262511-28604-1-git-send-email-kraxel@redhat.com>
Download mbox | patch
Permalink /patch/263641/
State New
Headers show

Comments

Gerd Hoffmann - July 31, 2013, 9:21 a.m.
Reinitialize dev->cs to NULL after deleting it, to make sure it isn't
used afterwards.

Reported-by: Martin Cerveny <M.Cerveny@computer.org>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb/redirect.c |    1 +
 1 file changed, 1 insertion(+)
Laszlo Ersek - July 31, 2013, 12:25 p.m.
On 07/31/13 11:21, Gerd Hoffmann wrote:
> Reinitialize dev->cs to NULL after deleting it, to make sure it isn't
> used afterwards.
> 
> Reported-by: Martin Cerveny <M.Cerveny@computer.org>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  hw/usb/redirect.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
> index 8b8c010..e3b9f32 100644
> --- a/hw/usb/redirect.c
> +++ b/hw/usb/redirect.c
> @@ -1334,6 +1334,7 @@ static void usbredir_handle_destroy(USBDevice *udev)
>      USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev);
>  
>      qemu_chr_delete(dev->cs);
> +    dev->cs = NULL;
>      /* Note must be done after qemu_chr_close, as that causes a close event */
>      qemu_bh_delete(dev->chardev_close_bh);
>  
> 

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Patch

diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index 8b8c010..e3b9f32 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -1334,6 +1334,7 @@  static void usbredir_handle_destroy(USBDevice *udev)
     USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev);
 
     qemu_chr_delete(dev->cs);
+    dev->cs = NULL;
     /* Note must be done after qemu_chr_close, as that causes a close event */
     qemu_bh_delete(dev->chardev_close_bh);