From patchwork Fri Jul 8 13:59:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fan Zhang X-Patchwork-Id: 113836 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EBA24A00C5; Fri, 8 Jul 2022 15:59:20 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9E731406B4; Fri, 8 Jul 2022 15:59:20 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id BCD474021E for ; Fri, 8 Jul 2022 15:59:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657288759; x=1688824759; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jLUgYWR4OfdyaqV147W7iu+E4XA6ZLSKT7Lt/OkaJxc=; b=Ug6Tf5pxb6mTcCH8c2CwDWomcQpRfY7mq3Y7mtmMSPB/0oMv5Ka5yM37 AH8bAirXxfeqwK18IeHyt9kZJes8HeCq3+VhHBD1pPJFx4Y/RjBWcavm9 t/Vyx54PtXfyNOy2MrBtTYUlNpKRhtOWMnHpDFZZKXB+dVOu0/PzlE0g3 oOwJdi/rSOqFNH4+f1L9mmfwKge3s0d9zXtu5QEPCakEO5/r59+0Ix2ly yerEXTPgqJEif+Tsoo0lpzv+5LZXKjZRhgWDNKspTJxiKzx+2EcLGy5B0 l+NEifF8/07+0b+DvLIWZM764PdG4kmjUtNWK5Okn0Ksl+66aw94/9yOH g==; X-IronPort-AV: E=McAfee;i="6400,9594,10401"; a="285026339" X-IronPort-AV: E=Sophos;i="5.92,255,1650956400"; d="scan'208";a="285026339" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2022 06:59:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,255,1650956400"; d="scan'208";a="736344608" Received: from silpixa00400885.ir.intel.com ([10.243.22.168]) by fmsmga001.fm.intel.com with ESMTP; 08 Jul 2022 06:59:16 -0700 From: Fan Zhang To: dev@dpdk.org Cc: maxime.coquelin@redhat.com, Fan Zhang , david.marchand@redhat.com Subject: [PATCH v2] vhost/crypto: fix out of bound access Date: Fri, 8 Jul 2022 13:59:14 +0000 Message-Id: <20220708135914.137368-1-roy.fan.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220708134923.136101-1-roy.fan.zhang@intel.com> References: <20220708134923.136101-1-roy.fan.zhang@intel.com> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Coverity issue: 379211 Fixes: 4414bb67010d ("vhost/crypto: fix build with GCC 12") Cc: david.marchand@redhat.com Signed-off-by: Fan Zhang --- v2: fix format-warning lib/vhost/vhost_crypto.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/vhost/vhost_crypto.c b/lib/vhost/vhost_crypto.c index 54946f46d9..bf899d2a50 100644 --- a/lib/vhost/vhost_crypto.c +++ b/lib/vhost/vhost_crypto.c @@ -574,12 +574,11 @@ copy_data_from_desc(void *dst, struct vhost_crypto_data_req *vc_req, remain = RTE_MIN(desc->len, size); addr = desc->addr; - do { - uint64_t len; - void *src; - len = remain; - src = IOVA_TO_VVA(void *, vc_req, addr, &len, VHOST_ACCESS_RO); + while (remain) { + uint64_t len = remain; + void *src = IOVA_TO_VVA(void *, vc_req, addr, &len, VHOST_ACCESS_RO); + if (unlikely(src == NULL || len == 0)) return 0; @@ -588,7 +587,7 @@ copy_data_from_desc(void *dst, struct vhost_crypto_data_req *vc_req, /* cast is needed for 32-bit architecture */ dst = RTE_PTR_ADD(dst, (size_t)len); addr += len; - } while (unlikely(remain != 0)); + } return RTE_MIN(desc->len, size); }