From patchwork Fri Jun 7 13:54:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 249729 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 E19C22C008F for ; Fri, 7 Jun 2013 23:56:08 +1000 (EST) Received: from localhost ([::1]:39665 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ukx9D-0005s0-1h for incoming@patchwork.ozlabs.org; Fri, 07 Jun 2013 09:56:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34130) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ukx88-00052b-Rr for qemu-devel@nongnu.org; Fri, 07 Jun 2013 09:55:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ukx85-0002Ba-Fz for qemu-devel@nongnu.org; Fri, 07 Jun 2013 09:55:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58417) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ukx85-0002BO-8n; Fri, 07 Jun 2013 09:54:57 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r57DsuiL012725 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 7 Jun 2013 09:54:56 -0400 Received: from localhost (ovpn-112-30.ams2.redhat.com [10.36.112.30]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r57Dst0J017024; Fri, 7 Jun 2013 09:54:55 -0400 From: Stefan Hajnoczi To: Date: Fri, 7 Jun 2013 15:54:48 +0200 Message-Id: <1370613288-14933-3-git-send-email-stefanha@redhat.com> In-Reply-To: <1370613288-14933-1-git-send-email-stefanha@redhat.com> References: <1370613288-14933-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Jason Wang , qemu-stable@nongnu.org, Stefan Hajnoczi , Stefan Hajnoczi , Paolo Bonzini , Laszlo Ersek Subject: [Qemu-devel] [PULL 2/2] tap: fix NULL dereference when passing invalid parameters to tap 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: Jason Wang This patch forbid the following invalid parameters to tap: 1) fd and vhostfds were specified but vhostfd were not specified 2) vhostfds were specified but fds were not specified 3) fds and vhostfd were specified For 1 and 2, net_init_tap_one() will still pass NULL as vhostfdname to monitor_handle_fd_param(), which may crash the qemu. Also remove the unnecessary has_fd check. Cc: Paolo Bonzini Cc: Stefan Hajnoczi Cc: Laszlo Ersek Cc: qemu-stable@nongnu.org Signed-off-by: Jason Wang Signed-off-by: Stefan Hajnoczi --- net/tap.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/net/tap.c b/net/tap.c index e0b7a2a..39c1cda 100644 --- a/net/tap.c +++ b/net/tap.c @@ -698,9 +698,10 @@ int net_init_tap(const NetClientOptions *opts, const char *name, if (tap->has_fd) { if (tap->has_ifname || tap->has_script || tap->has_downscript || tap->has_vnet_hdr || tap->has_helper || tap->has_queues || - tap->has_fds) { + tap->has_fds || tap->has_vhostfds) { error_report("ifname=, script=, downscript=, vnet_hdr=, " - "helper=, queues=, and fds= are invalid with fd="); + "helper=, queues=, fds=, and vhostfds= " + "are invalid with fd="); return -1; } @@ -725,9 +726,10 @@ int net_init_tap(const NetClientOptions *opts, const char *name, if (tap->has_ifname || tap->has_script || tap->has_downscript || tap->has_vnet_hdr || tap->has_helper || tap->has_queues || - tap->has_fd) { + tap->has_vhostfd) { error_report("ifname=, script=, downscript=, vnet_hdr=, " - "helper=, queues=, and fd= are invalid with fds="); + "helper=, queues=, and vhostfd= " + "are invalid with fds="); return -1; } @@ -765,9 +767,9 @@ int net_init_tap(const NetClientOptions *opts, const char *name, } } else if (tap->has_helper) { if (tap->has_ifname || tap->has_script || tap->has_downscript || - tap->has_vnet_hdr || tap->has_queues || tap->has_fds) { + tap->has_vnet_hdr || tap->has_queues || tap->has_vhostfds) { error_report("ifname=, script=, downscript=, and vnet_hdr= " - "queues=, and fds= are invalid with helper="); + "queues=, and vhostfds= are invalid with helper="); return -1; } @@ -785,6 +787,10 @@ int net_init_tap(const NetClientOptions *opts, const char *name, return -1; } } else { + if (tap->has_vhostfds) { + error_report("vhostfds= is invalid if fds= wasn't specified"); + return -1; + } script = tap->has_script ? tap->script : DEFAULT_NETWORK_SCRIPT; downscript = tap->has_downscript ? tap->downscript : DEFAULT_NETWORK_DOWN_SCRIPT;