From patchwork Wed Aug 28 05:10:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 270329 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 7A22D2C009E for ; Wed, 28 Aug 2013 15:11:53 +1000 (EST) Received: from localhost ([::1]:60357 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VEY2o-0006Ca-IA for incoming@patchwork.ozlabs.org; Wed, 28 Aug 2013 01:11:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VEY2H-0006BS-Hy for qemu-devel@nongnu.org; Wed, 28 Aug 2013 01:11:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VEY2A-000514-Ev for qemu-devel@nongnu.org; Wed, 28 Aug 2013 01:11:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46830) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VEY2A-00050y-61; Wed, 28 Aug 2013 01:11:10 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r7S5B8Wi004425 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Aug 2013 01:11:08 -0400 Received: from localhost (dhcp193-119.pnq.redhat.com [10.65.193.119]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r7S5B7gl029449; Wed, 28 Aug 2013 01:11:07 -0400 From: Amit Shah To: qemu list Date: Wed, 28 Aug 2013 10:40:43 +0530 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-stable@nongnu.org, Hans de Goede , Gerd Hoffmann , Anthony Liguori , Amit Shah , Paolo Bonzini Subject: [Qemu-devel] [PATCH 1/9] char: remove watch callback on chardev detach from frontend 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 If a frontend device releases the chardev (via unplug), the chr handlers are set to NULL via qdev's exit callbacks invoking qemu_chr_add_handlers(). If the chardev had a pending operation, a callback will be invoked, which will try to access data in the just-released frontend, causing a NULL pointer dereference. Ensure the callbacks are disabled when frontends release chardevs. This was seen when a virtio-serial port was unplugged when heavy guest->host IO was in progress (causing a callback to be registered). In the window in which the throttling was active, unplugging ports caused a qemu segfault. https://bugzilla.redhat.com/show_bug.cgi?id=985205 CC: Reported-by: Sibiao Luo Signed-off-by: Amit Shah --- include/sysemu/char.h | 1 + qemu-char.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/include/sysemu/char.h b/include/sysemu/char.h index 8053130..3400b04 100644 --- a/include/sysemu/char.h +++ b/include/sysemu/char.h @@ -69,6 +69,7 @@ struct CharDriverState { void (*chr_accept_input)(struct CharDriverState *chr); void (*chr_set_echo)(struct CharDriverState *chr, bool echo); void (*chr_set_fe_open)(struct CharDriverState *chr, int fe_open); + void (*chr_detach)(struct CharDriverState *chr); void *opaque; char *label; char *filename; diff --git a/qemu-char.c b/qemu-char.c index 6259496..f27fdb6 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -203,6 +203,9 @@ void qemu_chr_add_handlers(CharDriverState *s, if (!opaque && !fd_can_read && !fd_read && !fd_event) { fe_open = 0; + if (s->handler_opaque && s->chr_detach) { + s->chr_detach(s); + } } else { fe_open = 1; }