From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33922) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjjnW-0000SG-GZ for qemu-devel@nongnu.org; Tue, 04 Jun 2013 01:28:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UjjnQ-0002Bd-BW for qemu-devel@nongnu.org; Tue, 04 Jun 2013 01:28:42 -0400 From: Jason Wang Date: Tue, 4 Jun 2013 13:18:17 +0800 Message-Id: <1370323097-11179-1-git-send-email-jasowang@redhat.com> Subject: [Qemu-devel] [PATCH V2] net: tap: fix NULL dereference when passing invalid parameters to tap List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: aliguori@us.ibm.com, stefanha@redhat.com, qemu-devel@nongnu.org Cc: Paolo Bonzini , Jason Wang , Stefan Hajnoczi , qemu-stable@nongnu.org, Laszlo Ersek 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 --- Changes from v1: - check vhostfds for has_helper and all other cases - remove the unnecessary check for has_fd when fds were specified --- net/tap.c | 18 ++++++++++++------ 1 files 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; -- 1.7.1