From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50988) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOogR-0003uj-24 for qemu-devel@nongnu.org; Wed, 25 Sep 2013 08:59:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VOogG-0000PC-DW for qemu-devel@nongnu.org; Wed, 25 Sep 2013 08:59:10 -0400 Sender: fluxion From: Michael Roth Date: Wed, 25 Sep 2013 07:58:00 -0500 Message-Id: <1380113886-16845-33-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1380113886-16845-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1380113886-16845-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 32/38] chardev: fix pty_chr_timer List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org From: Gerd Hoffmann pty_chr_timer first calls pty_chr_update_read_handler(), then clears timer_tag (because it is a one-shot timer). This is the wrong order though. pty_chr_update_read_handler might re-arm time timer, and the new timer_tag gets overwitten in that case. This leads to crashes when unplugging a pty chardev: pty_chr_close thinks no timer is running -> timer isn't canceled -> pty_chr_timer gets called with stale CharDevState -> BOOM. This patch fixes the ordering. Kill the pointless goto while being at it. https://bugzilla.redhat.com/show_bug.cgi?id=994414 Cc: qemu-stable@nongnu.org Signed-off-by: Gerd Hoffmann (cherry picked from commit b0d768c35e08d2057b63e8e77e7a513c447199fa) Signed-off-by: Michael Roth --- qemu-char.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index 1be1cf6..1621fbd 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -1026,15 +1026,11 @@ static gboolean pty_chr_timer(gpointer opaque) struct CharDriverState *chr = opaque; PtyCharDriver *s = chr->opaque; - if (s->connected) { - goto out; - } - - /* Next poll ... */ - pty_chr_update_read_handler(chr); - -out: s->timer_tag = 0; + if (!s->connected) { + /* Next poll ... */ + pty_chr_update_read_handler(chr); + } return FALSE; } -- 1.7.9.5