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 037A54584B; Thu, 22 Aug 2024 21:48:46 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 54B4D42F97; Thu, 22 Aug 2024 21:48:24 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by mails.dpdk.org (Postfix) with ESMTP id 1D3B442F7E for ; Thu, 22 Aug 2024 21:48:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724356102; x=1755892102; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vMA047NQAw8nCTmvhb2VtOcpilkawQnq2VTMGzChbSQ=; b=awM2C1SQh4kS/S0c9j545nMAvApT6ZHXkEOVRiiypYNZGP9ZuzXN+xHv 088P/WwurSP24nXi6o9zhn3V/39sw6Xcvt5enFN39D1C4/rQLpV3c3NP/ JbvhZ7UoZOAPgHqX9QOgyVf9ZCFQJdz0EsClXXouRnMw4WaA+S0omujLZ qh56n48m7b5UR8qOzmBAMZufnKrCmSzdgdF04Ty9B8Be5U2Q9Jx9iUHLg NcfxOWrrESYe40eGdIIpSSA6GTiGPxHnwis5EYUv3zLrANex1DXZek2DO YASrIEW0cvIPfV5PcIfgXMEjPpY6XuZGCH/DoK3aWmbcQU5dppN7N6wv0 Q==; X-CSE-ConnectionGUID: DEky+wX7Tp639mO4md1Q2A== X-CSE-MsgGUID: 6q0GjPrgSBCa3vUZRhyFxA== X-IronPort-AV: E=McAfee;i="6700,10204,11172"; a="22979672" X-IronPort-AV: E=Sophos;i="6.10,168,1719903600"; d="scan'208";a="22979672" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2024 12:48:22 -0700 X-CSE-ConnectionGUID: 7VZdUS4dSZ6HQVW7NY9VgA== X-CSE-MsgGUID: laO8OIbIQaeTHoUcs3t2bg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,168,1719903600"; d="scan'208";a="92301402" Received: from unknown (HELO npf-hyd-clx-03..) ([10.145.170.182]) by orviesa002.jf.intel.com with ESMTP; 22 Aug 2024 12:48:20 -0700 From: Soumyadeep Hore To: bruce.richardson@intel.com, ian.stokes@intel.com, aman.deep.singh@intel.com Cc: dev@dpdk.org, shaiq.wani@intel.com Subject: [PATCH v2 04/12] net/ice: avoid reading past end of PFA Date: Thu, 22 Aug 2024 18:53:38 +0000 Message-ID: <20240822185346.221885-5-soumyadeep.hore@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240822185346.221885-1-soumyadeep.hore@intel.com> References: <20240822095612.216214-1-soumyadeep.hore@intel.com> <20240822185346.221885-1-soumyadeep.hore@intel.com> 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 The ice_get_pfa_module_tlv() function iterates over the Preserved Fields Area to read data from the Shadow RAM, including the Part Board Assembly data, among others. If the specific TLV being requested is not found in the current NVM, the code will read past the end of the PFA, misinterpreting the last word of the PFA and the word just after the PFA as another TLV. This typically results in one extra iteration before the length check of the while loop is triggered. Signed-off-by: Soumyadeep Hore --- drivers/net/ice/base/ice_nvm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/ice/base/ice_nvm.c b/drivers/net/ice/base/ice_nvm.c index 5e982de4b5..0124cef04c 100644 --- a/drivers/net/ice/base/ice_nvm.c +++ b/drivers/net/ice/base/ice_nvm.c @@ -498,11 +498,16 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, ice_debug(hw, ICE_DBG_INIT, "Failed to read PFA length.\n"); return status; } - /* Starting with first TLV after PFA length, iterate through the list + /* The Preserved Fields Area contains a sequence of TLVs which define + * its contents. The PFA length includes all of the TLVs, plus its + * initial length word itself, *and* one final word at the end of all + * of the TLVs. + * + * Starting with first TLV after PFA length, iterate through the list * of TLVs to find the requested one. */ next_tlv = pfa_ptr + 1; - while (next_tlv < ((u32)pfa_ptr + pfa_len)) { + while (next_tlv < ((u32)pfa_ptr + pfa_len - 1)) { u16 tlv_sub_module_type; u16 tlv_len; -- 2.43.0