From patchwork Mon Aug 21 15:50:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Otubo X-Patchwork-Id: 804061 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xbdd24bRhz9s82 for ; Tue, 22 Aug 2017 01:57:58 +1000 (AEST) Received: from localhost ([::1]:56829 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djp5Q-00052m-9c for incoming@patchwork.ozlabs.org; Mon, 21 Aug 2017 11:57:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60749) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djp4p-00050m-RF for qemu-devel@nongnu.org; Mon, 21 Aug 2017 11:57:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1djp4m-00059n-0v for qemu-devel@nongnu.org; Mon, 21 Aug 2017 11:57:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60762) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1djp4l-000590-RH; Mon, 21 Aug 2017 11:57:15 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 26B31356E3; Mon, 21 Aug 2017 15:50:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 26B31356E3 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=otubo@redhat.com Received: from vader.redhat.com (ovpn-117-175.ams2.redhat.com [10.36.117.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A85177BED; Mon, 21 Aug 2017 15:50:06 +0000 (UTC) From: Eduardo Otubo To: qemu-trivial@nongnu.org Date: Mon, 21 Aug 2017 17:50:05 +0200 Message-Id: <20170821155005.16885-1-otubo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 21 Aug 2017 15:50:09 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] 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: lizhijian@cn.fujitsu.com, mjt@tls.msk.ru, qemu-devel@nongnu.org, zhangchen.fnst@cn.fujitsu.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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)