Received: from eggs.gnu.org ([2001:4830:134:3::10]:37721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VFKCC-0007TZ-Bw for qemu-devel@nongnu.org; Fri, 30 Aug 2013 04:36:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VFKC6-0002xw-DU for qemu-devel@nongnu.org; Fri, 30 Aug 2013 04:36:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53911) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VFKC6-0002xk-5d for qemu-devel@nongnu.org; Fri, 30 Aug 2013 04:36:38 -0400 Message-ID: <1377851793.7780.4.camel@nilsson.home.kraxel.org> From: Gerd Hoffmann Date: Fri, 30 Aug 2013 10:36:33 +0200 In-Reply-To: <1377165441-28827-1-git-send-email-kraxel@redhat.com> References: <1377165441-28827-1-git-send-email-kraxel@redhat.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] chardev: fix pty_chr_timer List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori On Do, 2013-08-22 at 11:57 +0200, Gerd Hoffmann wrote: > 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. Ping? > > https://bugzilla.redhat.com/show_bug.cgi?id=994414 > > Signed-off-by: Gerd Hoffmann > --- > 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; > } >