From patchwork Wed Sep 25 12:58:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 277868 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 28A852C008F for ; Wed, 25 Sep 2013 23:58:31 +1000 (EST) Received: from localhost ([::1]:52564 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOovk-0001jl-Vd for incoming@patchwork.ozlabs.org; Wed, 25 Sep 2013 09:15:00 -0400 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 Received: from mail-qa0-x229.google.com ([2607:f8b0:400d:c00::229]:36725) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOogG-0000O2-0C; Wed, 25 Sep 2013 08:59:00 -0400 Received: by mail-qa0-f41.google.com with SMTP id ii20so3352283qab.7 for ; Wed, 25 Sep 2013 05:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=1JIryuKWUuoqA4U2LbLCtYt+VPJS4/zJICUMqOemmk4=; b=CCMHmr3jWEs8IO7zuIBpHeGzjrz7Ug5gC6KppZYbwiNdTRHGdDhmDHs+QJj2fo2vw+ jJnrZfFGPmN4pKncK9WzKAC1UAlqJLATHtMmAI4V3q6hdR5elYbZDiWUW1hVrg7eSWYT iI47ggxBwhKiBeq5kfOWpt+CnV+WD45j0E3pbT8gcVrqSt+WOCAe9CGUX5h5LCACx6Vi jIUpkqkkJo43pq9bvYInfatTaeL6UrZ19tk3eq7P7MwsOkIR671PGRVhOlNGwQsUkma0 ErUPMTbWPm+w9UtWVsD18eoz7QWafkBBKs7UdVCcWDeQXcpD9x8ikfQWEWswAUVuQ440 fDBw== X-Received: by 10.229.79.137 with SMTP id p9mr22724957qck.12.1380113939526; Wed, 25 Sep 2013 05:58:59 -0700 (PDT) Received: from loki.morrigu.org ([70.114.130.150]) by mx.google.com with ESMTPSA id g2sm65250216qaf.12.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 25 Sep 2013 05:58:58 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 25 Sep 2013 07:58:00 -0500 Message-Id: <1380113886-16845-33-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 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> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c00::229 Cc: qemu-stable@nongnu.org Subject: [Qemu-devel] [PATCH 32/38] chardev: fix pty_chr_timer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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; }