From patchwork Sun Sep 24 21:22:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 9968823 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CEC9460383 for ; Sun, 24 Sep 2017 21:33:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C13BD28BEF for ; Sun, 24 Sep 2017 21:33:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B622E28BF2; Sun, 24 Sep 2017 21:33:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 28FF128BF1 for ; Sun, 24 Sep 2017 21:33:28 +0000 (UTC) Received: from localhost ([::1]:39514 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dwEWl-0004sv-CN for patchwork-qemu-devel@patchwork.kernel.org; Sun, 24 Sep 2017 17:33:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dwEVQ-0004sK-JP for qemu-devel@nongnu.org; Sun, 24 Sep 2017 17:32:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dwEVO-0000J4-3k for qemu-devel@nongnu.org; Sun, 24 Sep 2017 17:32:04 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:45383) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dwEVN-0000Ip-Sq; Sun, 24 Sep 2017 17:32:02 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id D791F41C96; Mon, 25 Sep 2017 00:31:59 +0300 (MSK) Received: from tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by tsrv.corpit.ru (Postfix) with SMTP id B8FB4BF7; Mon, 25 Sep 2017 00:22:55 +0300 (MSK) Received: (nullmailer pid 28274 invoked by uid 1000); Sun, 24 Sep 2017 21:22:52 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Date: Mon, 25 Sep 2017 00:22:35 +0300 Message-Id: <8b1fd84c8da075ed20d1c5284aab458940b8cb04.1506288070.git.mjt@msgid.tls.msk.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 86.62.121.231 Subject: [Qemu-devel] [PULL 17/31] filter-mirror: segfault when specifying non existent device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Otubo , qemu-trivial@nongnu.org, Michael Tokarev Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Eduardo Otubo When using filter-mirror like the example below where the interface 'ndev0' does not exist on the host, QEMU crashes into segmentation fault. $ qemu-system-x86_64 -S -machine pc -netdev user,id=ndev0 -object filter-mirror,id=test-object,netdev=ndev0 This happens because the function filter_mirror_setup() does not checks if the device actually exists and still keep on processing calling qemu_chr_find(). This patch fixes this issue. Signed-off-by: Eduardo Otubo Reviewed-by: Zhang Chen Signed-off-by: Michael Tokarev --- net/filter-mirror.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/net/filter-mirror.c b/net/filter-mirror.c index 90e2c92337..e18a4b16a0 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -213,14 +213,22 @@ static void filter_mirror_setup(NetFilterState *nf, Error **errp) MirrorState *s = FILTER_MIRROR(nf); Chardev *chr; + if (s->outdev == NULL) { + goto err; + } + chr = qemu_chr_find(s->outdev); + if (chr == NULL) { - error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, - "Device '%s' not found", s->outdev); - return; + goto err; } qemu_chr_fe_init(&s->chr_out, chr, errp); + +err: + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, "Device '%s' not found", + nf->netdev_id); + return; } static void redirector_rs_finalize(SocketReadState *rs)