Received: from eggs.gnu.org ([2001:4830:134:3::10]:57682) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmilq-0004Os-5S for qemu-devel@nongnu.org; Wed, 21 Sep 2016 10:45:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bmili-0004Ml-GL for qemu-devel@nongnu.org; Wed, 21 Sep 2016 10:45:08 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:36268) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmile-0004Kr-RP for qemu-devel@nongnu.org; Wed, 21 Sep 2016 10:45:02 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u8LEhpx6032731 for ; Wed, 21 Sep 2016 10:44:41 -0400 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0a-001b2d01.pphosted.com with ESMTP id 25kkb68d7m-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 21 Sep 2016 10:44:31 -0400 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 21 Sep 2016 15:43:59 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 6D53C17D805D for ; Wed, 21 Sep 2016 15:45:56 +0100 (BST) Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u8LEhvlN13762968 for ; Wed, 21 Sep 2016 14:43:57 GMT Received: from d06av03.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u8LEhu8F025072 for ; Wed, 21 Sep 2016 08:43:57 -0600 Date: Wed, 21 Sep 2016 16:43:54 +0200 From: Cornelia Huck In-Reply-To: <20160921163826.2203884e@bahia.lab.toulouse-stg.fr.ibm.com> References: <147446363181.4880.18104448248886932114.stgit@bahia> <147446364067.4880.17009801693705082626.stgit@bahia> <20160921161659.7c8f40b9.cornelia.huck@de.ibm.com> <20160921163826.2203884e@bahia.lab.toulouse-stg.fr.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-Id: <20160921164354.2c461d09.cornelia.huck@de.ibm.com> Subject: Re: [Qemu-devel] [PATCH 1/7] virtio-9p: handle handle_9p_output() error List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Greg Kurz Cc: qemu-devel@nongnu.org, Kevin Wolf , "Michael S. Tsirkin" , Jason Wang , Max Reitz , "Aneesh Kumar K.V" , Stefan Hajnoczi , Paolo Bonzini On Wed, 21 Sep 2016 16:38:26 +0200 Greg Kurz wrote: > On Wed, 21 Sep 2016 16:16:59 +0200 > Cornelia Huck wrote: > > > On Wed, 21 Sep 2016 15:14:00 +0200 > > Greg Kurz wrote: > > > > > A broken guest may send a request with only non-empty out buffers > > > or only non-empty in buffers, virtqueue_pop() will then return a > > > VirtQueueElement with out_num == 0 or in_num == 0 respectively. > > > > > > All 9P requests are expected to start with the following 7-byte header: > > > > > > uint32_t size_le; > > > uint8_t id; > > > uint16_t tag_le; > > > > > > If iov_to_buf() fails to return these 7 bytes, then something is wrong in > > > the guest. > > > > > > In both cases, it is wrong to crash QEMU, since the root cause lies in the > > > guest. Let's switch the device to the broken state instead. > > > > > > Signed-off-by: Greg Kurz > > > --- > > > hw/9pfs/virtio-9p-device.c | 14 ++++++++++++-- > > > 1 file changed, 12 insertions(+), 2 deletions(-) > > > > > > diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c > > > index 009b43f6d045..0f09bef13392 100644 > > > --- a/hw/9pfs/virtio-9p-device.c > > > +++ b/hw/9pfs/virtio-9p-device.c > > > @@ -56,13 +56,23 @@ static void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq) > > > break; > > > } > > > > > > - BUG_ON(elem->out_num == 0 || elem->in_num == 0); > > > + if (elem->out_num == 0 || elem->in_num == 0) { > > > + virtio_error(vdev, > > > + "The guest sent a VirtFS request without headers"); > > > + pdu_free(pdu); > > > + return; > > > > Make that 'break;' to be more consistent with the code right above? > > > > The code right above isn't an error path, unlike here. Maybe I should > even add an out_err: label to make it explicit. I think our tastes differ a bit. But it's your code :)