From patchwork Fri Oct 8 17:40:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 67253 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AA9AE1007D9 for ; Sat, 9 Oct 2010 04:41:57 +1100 (EST) Received: from localhost ([127.0.0.1]:45023 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P4Gx7-0003f4-GF for incoming@patchwork.ozlabs.org; Fri, 08 Oct 2010 13:41:53 -0400 Received: from [140.186.70.92] (port=46006 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P4Gvk-0003cU-1U for qemu-devel@nongnu.org; Fri, 08 Oct 2010 13:40:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P4GvS-0005vb-Tl for qemu-devel@nongnu.org; Fri, 08 Oct 2010 13:40:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41777) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P4GvS-0005vU-Ly for qemu-devel@nongnu.org; Fri, 08 Oct 2010 13:40: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.13.8/8.13.8) with ESMTP id o98He6sS011707 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 8 Oct 2010 13:40:06 -0400 Received: from doriath (ovpn-113-81.phx2.redhat.com [10.3.113.81]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id o98He2GJ025689 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 8 Oct 2010 13:40:04 -0400 Date: Fri, 8 Oct 2010 14:40:02 -0300 From: Luiz Capitulino To: "Michael S. Tsirkin" Subject: Re: [Qemu-devel] [PATCH] monitor: properly handle invalid fd/vhostfd from command line Message-ID: <20101008144002.245d55e1@doriath> In-Reply-To: <20100928145743.GC15294@redhat.com> References: <20100927075244.8835.530.stgit@dhcp-91-7.nay.redhat.com.englab.nay.redhat.com> <20100928115343.78357291@doriath> <20100928145743.GC15294@redhat.com> Organization: Red Hat Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Jason Wang , qemu-devel@nongnu.org X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Tue, 28 Sep 2010 16:57:44 +0200 "Michael S. Tsirkin" wrote: > On Tue, Sep 28, 2010 at 11:53:43AM -0300, Luiz Capitulino wrote: > > On Mon, 27 Sep 2010 15:52:44 +0800 > > Jason Wang wrote: > > > > > monitor_get_fd() may also be used to parse fd or vhostfd from command line, so > > > we need to check whether the pointer of mon is NULL to avoid segmentation fault > > > when user pass invalid name of fd or vhostfd. > > > > Invalid fdname is handled just fine, I have the impression this patch fixes > > something else. > > > > Could you elaborate on the real problem here and/or show to reproduce? > > Try pasing fd= (no value) as a parameter, and see what happens. Sorry for the delay on this one. If I'm reading this code correctly, we have two kinds of fd passing being handled by net_handle_fd_param(): fds passed via SCM_RIGHTS (handled by the monitor) and -net fds, passed via the command-line. In this case, we don't want the fd passed via SCM_RIGHTS, so net_handle_fd_param() has to be fixed to check for !mon and also check strtol()'s return: There's more: qemu doesn't exit when an invalid fd is passed: """ ~/stuff/virt/ ./qemu-qmp -hda disks/test.img -enable-kvm -m 1G -snapshot -net tap,fd=40 qemu-qmp: -net tap,fd=40: TUNGETIFF ioctl() failed: Bad file descriptor TUNSETOFFLOAD ioctl() failed: Bad file descriptor Warning: vlan 0 with no nics """ And QEMU is up and running... > > > > Signed-off-by: Jason Wang > > > --- > > > monitor.c | 4 ++++ > > > 1 files changed, 4 insertions(+), 0 deletions(-) > > > > > > diff --git a/monitor.c b/monitor.c > > > index e602480..5bb4ff0 100644 > > > --- a/monitor.c > > > +++ b/monitor.c > > > @@ -2345,6 +2345,10 @@ int monitor_get_fd(Monitor *mon, const char *fdname) > > > { > > > mon_fd_t *monfd; > > > > > > + if (mon == NULL) { > > > + return -1; > > > + } > > > + > > > QLIST_FOREACH(monfd, &mon->fds, next) { > > > int fd; > > > > > > > > > > diff --git a/net.c b/net.c index 3d0fde7..6aaa653 100644 --- a/net.c +++ b/net.c @@ -739,9 +739,9 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models, int net_handle_fd_param(Monitor *mon, const char *param) { - if (!qemu_isdigit(param[0])) { - int fd; + int fd; + if (!qemu_isdigit(param[0]) && mon) { fd = monitor_get_fd(mon, param); if (fd == -1) { error_report("No file descriptor named %s found", param); @@ -750,7 +750,13 @@ int net_handle_fd_param(Monitor *mon, const char *param) return fd; } else { - return strtol(param, NULL, 0); + char *endptr = NULL; + + fd = strtol(param, &endptr, 10); + if (*endptr || (fd == 0 && param == endptr)) { + return -1; + } + return fd; } }