|
|
ddf19c |
From 8f6311159977b8ee4b78172caa411d3cee4d2ae5 Mon Sep 17 00:00:00 2001
|
|
|
ddf19c |
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
|
|
|
ddf19c |
Date: Tue, 14 Jan 2020 20:23:30 +0000
|
|
|
ddf19c |
Subject: [PATCH 4/5] usbredir: Prevent recursion in usbredir_write
|
|
|
ddf19c |
MIME-Version: 1.0
|
|
|
ddf19c |
Content-Type: text/plain; charset=UTF-8
|
|
|
ddf19c |
Content-Transfer-Encoding: 8bit
|
|
|
ddf19c |
|
|
|
ddf19c |
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
ddf19c |
Message-id: <20200114202331.51831-2-dgilbert@redhat.com>
|
|
|
ddf19c |
Patchwork-id: 93344
|
|
|
ddf19c |
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH 1/2] usbredir: Prevent recursion in usbredir_write
|
|
|
ddf19c |
Bugzilla: 1790844
|
|
|
ddf19c |
RH-Acked-by: Peter Xu <peterx@redhat.com>
|
|
|
ddf19c |
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
|
|
|
ddf19c |
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
|
|
|
ddf19c |
|
|
|
ddf19c |
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
|
|
|
ddf19c |
|
|
|
ddf19c |
I've got a case where usbredir_write manages to call back into itself
|
|
|
ddf19c |
via spice; this patch causes the recursion to fail (0 bytes) the write;
|
|
|
ddf19c |
this seems to avoid the deadlock I was previously seeing.
|
|
|
ddf19c |
|
|
|
ddf19c |
I can't say I fully understand the interaction of usbredir and spice;
|
|
|
ddf19c |
but there are a few similar guards in spice and usbredir
|
|
|
ddf19c |
to catch other cases especially onces also related to spice_server_char_device_wakeup
|
|
|
ddf19c |
|
|
|
ddf19c |
This case seems to be triggered by repeated migration+repeated
|
|
|
ddf19c |
reconnection of the viewer; but my debugging suggests the migration
|
|
|
ddf19c |
finished before this hits.
|
|
|
ddf19c |
|
|
|
ddf19c |
The backtrace of the hang looks like:
|
|
|
ddf19c |
reds_handle_ticket
|
|
|
ddf19c |
reds_handle_other_links
|
|
|
ddf19c |
reds_channel_do_link
|
|
|
ddf19c |
red_channel_connect
|
|
|
ddf19c |
spicevmc_connect
|
|
|
ddf19c |
usbredir_create_parser
|
|
|
ddf19c |
usbredirparser_do_write
|
|
|
ddf19c |
usbredir_write
|
|
|
ddf19c |
qemu_chr_fe_write
|
|
|
ddf19c |
qemu_chr_write
|
|
|
ddf19c |
qemu_chr_write_buffer
|
|
|
ddf19c |
spice_chr_write
|
|
|
ddf19c |
spice_server_char_device_wakeup
|
|
|
ddf19c |
red_char_device_wakeup
|
|
|
ddf19c |
red_char_device_write_to_device
|
|
|
ddf19c |
vmc_write
|
|
|
ddf19c |
usbredirparser_do_write
|
|
|
ddf19c |
usbredir_write
|
|
|
ddf19c |
qemu_chr_fe_write
|
|
|
ddf19c |
qemu_chr_write
|
|
|
ddf19c |
qemu_chr_write_buffer
|
|
|
ddf19c |
qemu_mutex_lock_impl
|
|
|
ddf19c |
|
|
|
ddf19c |
and we fail as we land through qemu_chr_write_buffer's lock
|
|
|
ddf19c |
twice.
|
|
|
ddf19c |
|
|
|
ddf19c |
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1752320
|
|
|
ddf19c |
|
|
|
ddf19c |
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
ddf19c |
Message-Id: <20191218113012.13331-1-dgilbert@redhat.com>
|
|
|
ddf19c |
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
|
|
|
ddf19c |
(cherry picked from commit 394642a8d3742c885e397d5bb5ee0ec40743cdc6)
|
|
|
ddf19c |
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
|
|
|
ddf19c |
---
|
|
|
ddf19c |
hw/usb/redirect.c | 9 +++++++++
|
|
|
ddf19c |
1 file changed, 9 insertions(+)
|
|
|
ddf19c |
|
|
|
ddf19c |
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
|
|
|
ddf19c |
index e0f5ca6..97f2c3a 100644
|
|
|
ddf19c |
--- a/hw/usb/redirect.c
|
|
|
ddf19c |
+++ b/hw/usb/redirect.c
|
|
|
ddf19c |
@@ -113,6 +113,7 @@ struct USBRedirDevice {
|
|
|
ddf19c |
/* Properties */
|
|
|
ddf19c |
CharBackend cs;
|
|
|
ddf19c |
bool enable_streams;
|
|
|
ddf19c |
+ bool in_write;
|
|
|
ddf19c |
uint8_t debug;
|
|
|
ddf19c |
int32_t bootindex;
|
|
|
ddf19c |
char *filter_str;
|
|
|
ddf19c |
@@ -290,6 +291,13 @@ static int usbredir_write(void *priv, uint8_t *data, int count)
|
|
|
ddf19c |
return 0;
|
|
|
ddf19c |
}
|
|
|
ddf19c |
|
|
|
ddf19c |
+ /* Recursion check */
|
|
|
ddf19c |
+ if (dev->in_write) {
|
|
|
ddf19c |
+ DPRINTF("usbredir_write recursion\n");
|
|
|
ddf19c |
+ return 0;
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+ dev->in_write = true;
|
|
|
ddf19c |
+
|
|
|
ddf19c |
r = qemu_chr_fe_write(&dev->cs, data, count);
|
|
|
ddf19c |
if (r < count) {
|
|
|
ddf19c |
if (!dev->watch) {
|
|
|
ddf19c |
@@ -300,6 +308,7 @@ static int usbredir_write(void *priv, uint8_t *data, int count)
|
|
|
ddf19c |
r = 0;
|
|
|
ddf19c |
}
|
|
|
ddf19c |
}
|
|
|
ddf19c |
+ dev->in_write = false;
|
|
|
ddf19c |
return r;
|
|
|
ddf19c |
}
|
|
|
ddf19c |
|
|
|
ddf19c |
--
|
|
|
ddf19c |
1.8.3.1
|
|
|
ddf19c |
|