From nobody Mon Feb 9 11:28:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 14900532035751001.9842573940847; Mon, 20 Mar 2017 16:40:03 -0700 (PDT) Received: from localhost ([::1]:35642 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cq6uA-0001bQ-3q for importer@patchew.org; Mon, 20 Mar 2017 19:40:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41294) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cq6Qr-0001qT-IZ for qemu-devel@nongnu.org; Mon, 20 Mar 2017 19:09:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cq6Qm-00054p-IV for qemu-devel@nongnu.org; Mon, 20 Mar 2017 19:09:45 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:45262 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cq6Qm-00054T-AL for qemu-devel@nongnu.org; Mon, 20 Mar 2017 19:09:40 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2KN8pVa008175 for ; Mon, 20 Mar 2017 19:09:39 -0400 Received: from e11.ny.us.ibm.com (e11.ny.us.ibm.com [129.33.205.201]) by mx0b-001b2d01.pphosted.com with ESMTP id 29afu7a87k-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 20 Mar 2017 19:09:39 -0400 Received: from localhost by e11.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 20 Mar 2017 19:09:39 -0400 Received: from b01cxnp23032.gho.pok.ibm.com (9.57.198.27) by e11.ny.us.ibm.com (146.89.104.198) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 20 Mar 2017 19:09:36 -0400 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2KN9XxF41484448; Mon, 20 Mar 2017 23:09:36 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 854AC112056; Mon, 20 Mar 2017 19:09:34 -0400 (EDT) Received: from localhost (unknown [9.53.92.194]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP id 6964B112040; Mon, 20 Mar 2017 19:09:34 -0400 (EDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 20 Mar 2017 18:08:17 -0500 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490051325-3770-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1490051325-3770-1-git-send-email-mdroth@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17032023-2213-0000-0000-0000016A7CBD X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006819; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00836553; UDB=6.00411161; IPR=6.00614322; BA=6.00005224; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014732; XFM=3.00000013; UTC=2017-03-20 23:09:37 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17032023-2214-0000-0000-000054D5909C Message-Id: <1490051325-3770-54-git-send-email-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-20_16:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703200196 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH 53/81] virtio: fix up max size checks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-stable@nongnu.org, "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Michael S. Tsirkin" Coverity reports that ARRAY_SIZE(elem->out_sg) (and all the others too) is wrong because elem->out_sg is a pointer. However, the check is not in the right place and the max_size argument of virtqueue_map_iovec can be removed. The check on in_num/out_num should be moved to qemu_get_virtqueue_element instead, before the call to virtqueue_alloc_element. Cc: qemu-stable@nongnu.org Reported-by: Paolo Bonzini Fixes: 3724650db07057333879484c8bc7d900b5c1bf8e ("virtio: introduce virtque= ue_alloc_element") Signed-off-by: Michael S. Tsirkin Reviewed-by: Cornelia Huck (cherry picked from commit 6bdc21c050a2a7b92cbbd0b2a1f8934e9b5f896f) * dropped context dep on 8607f5c30 Signed-off-by: Michael Roth --- hw/virtio/virtio.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index e37641a..6dfc92f 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -592,24 +592,12 @@ static void virtqueue_undo_map_desc(unsigned int out_= num, unsigned int in_num, } =20 static void virtqueue_map_iovec(struct iovec *sg, hwaddr *addr, - unsigned int *num_sg, unsigned int max_siz= e, + unsigned int *num_sg, int is_write) { unsigned int i; hwaddr len; =20 - /* Note: this function MUST validate input, some callers - * are passing in num_sg values received over the network. - */ - /* TODO: teach all callers that this can fail, and return failure inst= ead - * of asserting here. - * When we do, we might be able to re-enable NDEBUG below. - */ -#ifdef NDEBUG -#error building with NDEBUG is not supported -#endif - assert(*num_sg <=3D max_size); - for (i =3D 0; i < *num_sg; i++) { len =3D sg[i].iov_len; sg[i].iov_base =3D cpu_physical_memory_map(addr[i], &len, is_write= ); @@ -626,10 +614,8 @@ static void virtqueue_map_iovec(struct iovec *sg, hwad= dr *addr, =20 void virtqueue_map(VirtQueueElement *elem) { - virtqueue_map_iovec(elem->in_sg, elem->in_addr, &elem->in_num, - VIRTQUEUE_MAX_SIZE, 1); - virtqueue_map_iovec(elem->out_sg, elem->out_addr, &elem->out_num, - VIRTQUEUE_MAX_SIZE, 0); + virtqueue_map_iovec(elem->in_sg, elem->in_addr, &elem->in_num, 1); + virtqueue_map_iovec(elem->out_sg, elem->out_addr, &elem->out_num, 0); } =20 static void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned= in_num) @@ -790,6 +776,16 @@ void *qemu_get_virtqueue_element(QEMUFile *f, size_t s= z) =20 qemu_get_buffer(f, (uint8_t *)&data, sizeof(VirtQueueElementOld)); =20 + /* TODO: teach all callers that this can fail, and return failure inst= ead + * of asserting here. + * When we do, we might be able to re-enable NDEBUG below. + */ +#ifdef NDEBUG +#error building with NDEBUG is not supported +#endif + assert(ARRAY_SIZE(data.in_addr) >=3D data.in_num); + assert(ARRAY_SIZE(data.out_addr) >=3D data.out_num); + elem =3D virtqueue_alloc_element(sz, data.out_num, data.in_num); elem->index =3D data.index; =20 --=20 2.7.4