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 4BF0A45DB9 for ; Wed, 27 Nov 2024 18:20:40 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 43EAD402E1; Wed, 27 Nov 2024 18:20:40 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 2199F402E1 for ; Wed, 27 Nov 2024 18:20:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732728038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eM8XvJr6Yq6Fz/NwEslJ1EbPuuRf3iV0MhL4plMzuTw=; b=UX0+atvYvzpxqGM6+6xoHPQxhPFRkAB0gAdHNifTXTa/gbm0JIDeQqvmOz8O85pUNpVVpZ Svhi7ogUr7Jc7vvs57BzODQminqscO/PLoPTtf4xlqYahbofCsmbIM2LudiVtulY9njegh yaWpxBcX6pMoCLT7REaat9n7pPlrnXQ= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-614-nn7bpjDHPvuQoKGntN6X2Q-1; Wed, 27 Nov 2024 12:20:37 -0500 X-MC-Unique: nn7bpjDHPvuQoKGntN6X2Q-1 X-Mimecast-MFC-AGG-ID: nn7bpjDHPvuQoKGntN6X2Q Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 33E741955F07; Wed, 27 Nov 2024 17:20:36 +0000 (UTC) Received: from rh.redhat.com (unknown [10.39.192.52]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1E212300019E; Wed, 27 Nov 2024 17:20:32 +0000 (UTC) From: Kevin Traynor To: Fabio Pricoco Cc: Jacob Keller , Soumyadeep Hore , Bruce Richardson , dpdk stable Subject: patch 'net/ice/base: fix iteration of TLVs in Preserved Fields Area' has been queued to stable release 21.11.9 Date: Wed, 27 Nov 2024 17:17:37 +0000 Message-ID: <20241127171916.690404-30-ktraynor@redhat.com> In-Reply-To: <20241127171916.690404-1-ktraynor@redhat.com> References: <20241127171916.690404-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: cdHFFehpTmr2LKreCLHbX9tSgDvlxLOj1t8vDHrGrsw_1732728036 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Hi, FYI, your patch has been queued to stable release 21.11.9 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 12/02/24. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/kevintraynor/dpdk-stable This queued commit can be viewed at: https://github.com/kevintraynor/dpdk-stable/commit/ebbecb19ccdb0df88227e69b2a83ae2ee79a2d19 Thanks. Kevin --- >From ebbecb19ccdb0df88227e69b2a83ae2ee79a2d19 Mon Sep 17 00:00:00 2001 From: Fabio Pricoco Date: Fri, 23 Aug 2024 09:56:42 +0000 Subject: [PATCH] net/ice/base: fix iteration of TLVs in Preserved Fields Area [ upstream commit dcb760bf0f951b404bce33a1dd14906154b58c75 ] 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. Correct the logic for determining the maximum PFA offset to include the extra last word. Additionally, make the driver robust against overflows by using check_add_overflow. This ensures that even if the NVM provides bogus data, the driver will not overflow, and will instead log a useful warning message. The check for whether the TLV length exceeds the PFA length is also removed, in favor of relying on the overflow warning instead. Fixes: 5d0b7b5fc491 ("net/ice/base: add read PBA module function") Signed-off-by: Fabio Pricoco Signed-off-by: Jacob Keller Signed-off-by: Soumyadeep Hore Acked-by: Bruce Richardson --- drivers/net/ice/base/ice_nvm.c | 36 ++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/drivers/net/ice/base/ice_nvm.c b/drivers/net/ice/base/ice_nvm.c index 48e0d418e2..c5a3eddebf 100644 --- a/drivers/net/ice/base/ice_nvm.c +++ b/drivers/net/ice/base/ice_nvm.c @@ -427,4 +427,6 @@ enum ice_status ice_read_sr_word(struct ice_hw *hw, u16 offset, u16 *data) } +#define check_add_overflow __builtin_add_overflow + /** * ice_get_pfa_module_tlv - Reads sub module TLV from NVM PFA @@ -443,6 +445,5 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, { enum ice_status status; - u16 pfa_len, pfa_ptr; - u32 next_tlv; + u16 pfa_len, pfa_ptr, next_tlv, max_tlv; status = ice_read_sr_word(hw, ICE_SR_PFA_PTR, &pfa_ptr); @@ -456,9 +457,21 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, return status; } - /* Starting with first TLV after PFA length, iterate through the list + + if (check_add_overflow(pfa_ptr, (u16)(pfa_len - 1), &max_tlv)) { + ice_debug(hw, ICE_DBG_INIT, "PFA starts at offset %u. PFA length of %u caused 16-bit arithmetic overflow.\n", + pfa_ptr, pfa_len); + return ICE_ERR_INVAL_SIZE; + } + + /* 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 < max_tlv) { u16 tlv_sub_module_type; u16 tlv_len; @@ -477,8 +490,4 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, break; } - if (tlv_len > pfa_len) { - ice_debug(hw, ICE_DBG_INIT, "Invalid TLV length.\n"); - return ICE_ERR_INVAL_SIZE; - } if (tlv_sub_module_type == module_type) { if (tlv_len) { @@ -489,8 +498,11 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, return ICE_ERR_INVAL_SIZE; } - /* Check next TLV, i.e. current TLV pointer + length + 2 words - * (for current TLV's type and length) - */ - next_tlv = next_tlv + tlv_len + 2; + + if (check_add_overflow(next_tlv, (u16)2, &next_tlv) || + check_add_overflow(next_tlv, tlv_len, &next_tlv)) { + ice_debug(hw, ICE_DBG_INIT, "TLV of type %u and length 0x%04x caused 16-bit arithmetic overflow. The PFA starts at 0x%04x and has length of 0x%04x\n", + tlv_sub_module_type, tlv_len, pfa_ptr, pfa_len); + return ICE_ERR_INVAL_SIZE; + } } /* Module does not exist */ -- 2.47.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2024-11-27 17:17:39.241595793 +0000 +++ 0030-net-ice-base-fix-iteration-of-TLVs-in-Preserved-Fiel.patch 2024-11-27 17:17:38.186269171 +0000 @@ -1 +1 @@ -From dcb760bf0f951b404bce33a1dd14906154b58c75 Mon Sep 17 00:00:00 2001 +From ebbecb19ccdb0df88227e69b2a83ae2ee79a2d19 Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit dcb760bf0f951b404bce33a1dd14906154b58c75 ] + @@ -25 +26,0 @@ -Cc: stable@dpdk.org @@ -36 +37 @@ -index 5e982de4b5..56c6c96a95 100644 +index 48e0d418e2..c5a3eddebf 100644 @@ -39 +40 @@ -@@ -470,4 +470,6 @@ int ice_read_sr_word(struct ice_hw *hw, u16 offset, u16 *data) +@@ -427,4 +427,6 @@ enum ice_status ice_read_sr_word(struct ice_hw *hw, u16 offset, u16 *data) @@ -46,2 +47 @@ -@@ -485,6 +487,5 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, - u16 module_type) +@@ -443,6 +445,5 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, @@ -48,0 +49 @@ + enum ice_status status; @@ -52 +52,0 @@ - int status; @@ -54 +54,2 @@ -@@ -499,9 +500,21 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, + status = ice_read_sr_word(hw, ICE_SR_PFA_PTR, &pfa_ptr); +@@ -456,9 +457,21 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, @@ -78 +79 @@ -@@ -520,8 +533,4 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, +@@ -477,8 +490,4 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, @@ -87 +88 @@ -@@ -532,8 +541,11 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, +@@ -489,8 +498,11 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len,