Received: from eggs.gnu.org ([2001:4830:134:3::10]:43436) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYs2X-0005Ja-IX for qemu-devel@nongnu.org; Fri, 20 Mar 2015 04:12:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYs2U-0005p8-6g for qemu-devel@nongnu.org; Fri, 20 Mar 2015 04:12:21 -0400 Received: from e06smtp13.uk.ibm.com ([195.75.94.109]:33385) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYs2T-0005oj-TJ for qemu-devel@nongnu.org; Fri, 20 Mar 2015 04:12:18 -0400 Received: from /spool/local by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 20 Mar 2015 08:12:16 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 61872219005E for ; Fri, 20 Mar 2015 08:12:03 +0000 (GMT) Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t2K8CDko8388966 for ; Fri, 20 Mar 2015 08:12:13 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 t2K8CDQ1016137 for ; Fri, 20 Mar 2015 02:12:13 -0600 Date: Fri, 20 Mar 2015 09:12:09 +0100 From: Cornelia Huck Message-ID: <20150320091209.1e39e713.cornelia.huck@de.ibm.com> In-Reply-To: <1426678962-27545-1-git-send-email-mst@redhat.com> References: <1426678962-27545-1-git-send-email-mst@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] virtio: move sanity checks to ifdef DEBUG List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: Rusty Russell , qemu-devel@nongnu.org On Wed, 18 Mar 2015 12:42:46 +0100 "Michael S. Tsirkin" wrote: > All that happens when virtqueue_fill is invoked incorrectly is that we > corrupt guest memory, so this check is not a security measure. > Move the check to ifdef DEBUG to make sure we don't introduce new > crashes close to release. I don't really disagree with this patch, but is anybody actually making regular runs with VIRTIO_DEBUG activated? > Array scans aren't free either, so it's a good idea from performance > point of view, too. > > Cc: Rusty Russell > Signed-off-by: Michael S. Tsirkin > --- > hw/virtio/virtio.c | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 deletions(-) > > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c > index 27429c2..37fb2ee 100644 > --- a/hw/virtio/virtio.c > +++ b/hw/virtio/virtio.c > @@ -243,15 +243,22 @@ int virtio_queue_empty(VirtQueue *vq) > void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, > unsigned int len_written, unsigned int idx) > { > - unsigned int offset, tot_wlen; > + unsigned int offset; > int i; > > trace_virtqueue_fill(vq, elem, len_written, idx); > > - for (tot_wlen = i = 0; i < elem->in_num; i++) { > - tot_wlen += elem->in_sg[i].iov_len; > +#ifdef DEBUG_VIRTIO > + { > + /* Check that len_written is <= the writable length. */ > + unsigned int tot_wlen; > + > + for (tot_wlen = i = 0; i < elem->in_num; i++) { > + tot_wlen += elem->in_sg[i].iov_len; > + } > + assert(len_written <= tot_wlen); > } > - assert(len_written <= tot_wlen); > +#endif > > offset = 0; > for (i = 0; i < elem->in_num; i++) {