From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A863D458CD; Mon, 2 Sep 2024 11:57:34 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C206F40DCE; Mon, 2 Sep 2024 11:55:43 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) by mails.dpdk.org (Postfix) with ESMTP id 4E0AB40676 for ; Mon, 2 Sep 2024 11:55:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725270922; x=1756806922; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jHQCmMrEj45SAi36wHGTfncgBeciOebHAvBatxdGJI0=; b=jUEOOUSQl26mMWCqKHJvvTbwPuOK6E2yocmPKrQxc/eX0a7uGWkUIUNT hjufF9oTrFSI/271Mv6GPrn5U4L3+xiixJ6AnWAQvTt5Ci3BJRVRi9x3b AU/I9y0YIvzMTGAc+ZFkEeYvnh6VwuOlJnXaxXaZ4/x/lrEPH9NjnrkMh yBSFZFVR8oFGtA4wMsatwk9KIDWAsDhJ4Jr4tUcR+4qS0EGuEd6np14p4 eLYUlrPoK9aZfUpkStr/XM7bU+qOIjYJNSc3dqs7IeC7d2bYnzS0JV2OD QJ9vmgsE/lSptD/L+CMabvfJtKUsmJzmgV4gwMoyQ/jVI7k2TtaI6P+gI A==; X-CSE-ConnectionGUID: b2gXFbTbRxGb0mnP2gs4Tw== X-CSE-MsgGUID: 2KjpNl/KT+Oiq4a6VPgCyQ== X-IronPort-AV: E=McAfee;i="6700,10204,11182"; a="26747249" X-IronPort-AV: E=Sophos;i="6.10,195,1719903600"; d="scan'208";a="26747249" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2024 02:55:21 -0700 X-CSE-ConnectionGUID: qLbSuggETAabXTFLU41F3A== X-CSE-MsgGUID: VTPb74wlT5W2e9nL9hVQqQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,195,1719903600"; d="scan'208";a="64597986" Received: from silpixa00401119.ir.intel.com ([10.55.129.167]) by fmviesa009.fm.intel.com with ESMTP; 02 Sep 2024 02:55:20 -0700 From: Anatoly Burakov To: dev@dpdk.org Cc: bruce.richardson@intel.com Subject: [PATCH v1 23/30] net/i40e/base: check loop bounds Date: Mon, 2 Sep 2024 10:54:35 +0100 Message-ID: X-Mailer: git-send-email 2.43.5 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 From: Barbara Skobiej An unchecked value used as a loop bound. Add verification if value of 'next_to_clean' variable is greater than 2^10 (next_to_clean is 10 bits). Also, refactored loop so that it reads the head value only once, and also checks if head is invalid. Signed-off-by: Barbara Skobiej Signed-off-by: Anatoly Burakov --- drivers/net/i40e/base/i40e_adminq.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/net/i40e/base/i40e_adminq.c b/drivers/net/i40e/base/i40e_adminq.c index b670250180..350288269b 100644 --- a/drivers/net/i40e/base/i40e_adminq.c +++ b/drivers/net/i40e/base/i40e_adminq.c @@ -745,12 +745,26 @@ u16 i40e_clean_asq(struct i40e_hw *hw) u16 ntc = asq->next_to_clean; struct i40e_aq_desc desc_cb; struct i40e_aq_desc *desc; + u32 head = 0; + + if (ntc >= (1 << 10)) + goto clean_asq_exit; desc = I40E_ADMINQ_DESC(*asq, ntc); details = I40E_ADMINQ_DETAILS(*asq, ntc); - while (rd32(hw, hw->aq.asq.head) != ntc) { + while (true) { + head = rd32(hw, hw->aq.asq.head); + + if (head >= asq->count) { + i40e_debug(hw, I40E_DEBUG_AQ_COMMAND, "Read head value is improper\n"); + return 0; + } + + if (head == ntc) + break; + i40e_debug(hw, I40E_DEBUG_AQ_COMMAND, - "ntc %d head %d.\n", ntc, rd32(hw, hw->aq.asq.head)); + "ntc %d head %d.\n", ntc, head); if (details->callback) { I40E_ADMINQ_CALLBACK cb_func = @@ -770,6 +784,7 @@ u16 i40e_clean_asq(struct i40e_hw *hw) asq->next_to_clean = ntc; +clean_asq_exit: return I40E_DESC_UNUSED(asq); } -- 2.43.5