From nobody Fri Nov 7 00:45:56 2025 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544615828984317.61164380875744; Wed, 12 Dec 2018 03:57:08 -0800 (PST) Received: from localhost ([::1]:44050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX38S-0000E2-I3 for importer@patchew.org; Wed, 12 Dec 2018 06:57:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43977) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX31T-0003he-LG for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX31P-0004DL-Jd for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38186) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX31P-0004Cn-Bu for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:47 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9450B3001BC6; Wed, 12 Dec 2018 11:49:46 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-138.sin2.redhat.com [10.67.116.138]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A3FC608C5; Wed, 12 Dec 2018 11:49:44 +0000 (UTC) From: P J P To: Yuval Shaia Date: Wed, 12 Dec 2018 17:17:25 +0530 Message-Id: <20181212114726.24060-6-ppandit@redhat.com> In-Reply-To: <20181212114726.24060-1-ppandit@redhat.com> References: <20181212114726.24060-1-ppandit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 12 Dec 2018 11:49:46 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 5/6] pvrdma: check return value from pvrdma_idx_ring_has_ routines 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: Prasad J Pandit , Li Qiang , Qemu Developers , Saar Amar Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Prasad J Pandit pvrdma_idx_ring_has_[data/space] routines also return invalid index PVRDMA_INVALID_IDX[=3D-1], if ring has no data/space. Check return value from these routines to avoid plausible infinite loops. Reported-by: Li Qiang Signed-off-by: Prasad J Pandit --- hw/rdma/vmw/pvrdma_dev_ring.c | 37 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 19 deletions(-) Update v1: receive error code in idx variable, remove comments -> https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg02342.html diff --git a/hw/rdma/vmw/pvrdma_dev_ring.c b/hw/rdma/vmw/pvrdma_dev_ring.c index 01247fc041..2dccac8442 100644 --- a/hw/rdma/vmw/pvrdma_dev_ring.c +++ b/hw/rdma/vmw/pvrdma_dev_ring.c @@ -73,23 +73,22 @@ out: =20 void *pvrdma_ring_next_elem_read(PvrdmaRing *ring) { - unsigned int idx =3D 0, offset; + int idx; + unsigned int offset, head; =20 - /* - pr_dbg("%s: t=3D%d, h=3D%d\n", ring->name, ring->ring_state->prod_tail, - ring->ring_state->cons_head); - */ - - if (!pvrdma_idx_ring_has_data(ring->ring_state, ring->max_elems, &idx)= ) { + idx =3D pvrdma_idx_ring_has_data(ring->ring_state, ring->max_elems, &h= ead); + if (idx <=3D 0) { pr_dbg("No more data in ring\n"); return NULL; } =20 + idx =3D pvrdma_idx(&ring->ring_state->cons_head, ring->max_elems); + if (idx < 0 || head !=3D idx) { + pr_dbg("invalid idx\n"); + return NULL; + } + offset =3D idx * ring->elem_sz; - /* - pr_dbg("idx=3D%d\n", idx); - pr_dbg("offset=3D%d\n", offset); - */ return ring->pages[offset / TARGET_PAGE_SIZE] + (offset % TARGET_PAGE_= SIZE); } =20 @@ -105,20 +104,20 @@ void pvrdma_ring_read_inc(PvrdmaRing *ring) =20 void *pvrdma_ring_next_elem_write(PvrdmaRing *ring) { - unsigned int idx, offset, tail; + int idx; + unsigned int offset, tail; =20 - /* - pr_dbg("%s: t=3D%d, h=3D%d\n", ring->name, ring->ring_state->prod_tail, - ring->ring_state->cons_head); - */ - - if (!pvrdma_idx_ring_has_space(ring->ring_state, ring->max_elems, &tai= l)) { + idx =3D pvrdma_idx_ring_has_space(ring->ring_state, ring->max_elems, &= tail); + if (idx <=3D 0) { pr_dbg("CQ is full\n"); return NULL; } =20 idx =3D pvrdma_idx(&ring->ring_state->prod_tail, ring->max_elems); - /* TODO: tail =3D=3D idx */ + if (idx < 0 || tail !=3D idx) { + pr_dbg("invalid idx\n"); + return NULL; + } =20 offset =3D idx * ring->elem_sz; return ring->pages[offset / TARGET_PAGE_SIZE] + (offset % TARGET_PAGE_= SIZE); --=20 2.19.2