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 4FAD745BB6 for ; Wed, 23 Oct 2024 23:19:23 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 49DD040261; Wed, 23 Oct 2024 23:19:23 +0200 (CEST) Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by mails.dpdk.org (Postfix) with ESMTP id 7F8AD40261 for ; Wed, 23 Oct 2024 23:19:21 +0200 (CEST) Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4315e9e9642so2159905e9.0 for ; Wed, 23 Oct 2024 14:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729718361; x=1730323161; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rAeZVyS1Y3bkCtT7NaFPJGu8/LaQknmW7HaqCdUrj7w=; b=CGlPaQkVurnxANbGeFHWZjyh8Ck2mnUt4t5a4Wl1hbjoj+nGbP6PwTfLx29GmPy6VE TyPLK6TxvUTX9vsG+zL06L4ZpoDwMkz64OCCartt5KrSA8yn47iJTRaVVAdof+Ha7xvW BJPLoiYuUXM8US53y08Bd9oKh6wMJGF79fjwmhL+JZ5hx83U2wOsD5UBx50rWr2voj9m Rdvf989t+UGReQg8wwU/hppnP/T1JVWBnoI2iPyV9qRiSp3iokG/trHYM8E0VtWv1M6b lavrjmBDkf0KhPUmqAtubT4v+Sdv9oh6A2iKx9zgBJwsrwiZbNRtEYFhZl8BlYWqVD9j 7HQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729718361; x=1730323161; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rAeZVyS1Y3bkCtT7NaFPJGu8/LaQknmW7HaqCdUrj7w=; b=XxETyqoZ2qlk1kZWyZ1WD3S1uGs8pgbLHwAmh3F8Im1OlDfnSuWimuob1ntCD1bTub fiaIMWKQDeDHNUC4mz+Rq4Gyu49U4u4F8v8Y3EXBq9Z4gz8iAQWL9NvDB5HfknSe0R+z NxnV5U0yr8CutwbusBz5OkZNOMYvr51VnJWs4wE+T/9ZoyjV0ZCZG0S9sJKC/nKWevH2 cnrzYs4Qp5kdiut0bcdbT5nFQj8AEL0J6PqfNQSgHhfhO+ORxN+xLc8P75CYvo3yLPwj RSzUQZNzCNrRNzDXgvVgqo+brGo0jTJm01egaV1x2t73sTRFJ5wbHI+UdnBdKV08m5G+ ouAQ== X-Forwarded-Encrypted: i=1; AJvYcCVW3AXfeiaxF5HT9LzQZWNB3yXdggmV6MP4/Tc/78uOFJ/fNZnN9bvMTAXcAKPgS/SgXCrvAjo=@dpdk.org X-Gm-Message-State: AOJu0Yy+3dWnfUbzqYLO9z7Wxqg2dOh2GEGJT7V5rIJOwRZNx3eP4/JU 90fm74sQ0u8tKsX+Te7MNlhn5lo8G1e7NiasJD3ExrMxDF7uZ+fdfZ0sZg== X-Google-Smtp-Source: AGHT+IGfWhRN0DZf2DVsFWZMDm8rZWcZ6Ts8I93H8q30DDw+iOzyJIBUNsb5T03hqL56AEtoZPzqiw== X-Received: by 2002:a05:600c:4708:b0:431:55af:a22f with SMTP id 5b1f17b1804b1-4318413f05amr35885305e9.13.1729718360909; Wed, 23 Oct 2024 14:19:20 -0700 (PDT) Received: from localhost ([2a01:4b00:d036:ae00:21cd:def0:a01d:d2aa]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43186bde1b5sm26757265e9.12.2024.10.23.14.19.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 14:19:19 -0700 (PDT) From: luca.boccassi@gmail.com 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 22.11.7 Date: Wed, 23 Oct 2024 22:16:16 +0100 Message-ID: <20241023211704.1216956-36-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241023211704.1216956-1-luca.boccassi@gmail.com> References: <20241023211704.1216956-1-luca.boccassi@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 22.11.7 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 10/25/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/bluca/dpdk-stable This queued commit can be viewed at: https://github.com/bluca/dpdk-stable/commit/822d0a9391325d4d7ea7ce9c7e776807c3928d2e Thanks. Luca Boccassi --- >From 822d0a9391325d4d7ea7ce9c7e776807c3928d2e 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 6da52f4d58..47ead01255 100644 --- a/drivers/net/ice/base/ice_nvm.c +++ b/drivers/net/ice/base/ice_nvm.c @@ -471,6 +471,8 @@ enum ice_status ice_read_sr_word(struct ice_hw *hw, u16 offset, u16 *data) return status; } +#define check_add_overflow __builtin_add_overflow + /** * ice_get_pfa_module_tlv - Reads sub module TLV from NVM PFA * @hw: pointer to hardware structure @@ -487,8 +489,7 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, u16 module_type) { 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); if (status != ICE_SUCCESS) { @@ -500,11 +501,23 @@ 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 + + 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; @@ -521,10 +534,6 @@ 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 TLV length.\n"); 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) { *module_tlv = (u16)next_tlv; @@ -533,10 +542,13 @@ 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 */ return ICE_ERR_DOES_NOT_EXIST; -- 2.45.2 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2024-10-23 22:16:41.891229585 +0100 +++ 0036-net-ice-base-fix-iteration-of-TLVs-in-Preserved-Fiel.patch 2024-10-23 22:16:40.475941807 +0100 @@ -1 +1 @@ -From dcb760bf0f951b404bce33a1dd14906154b58c75 Mon Sep 17 00:00:00 2001 +From 822d0a9391325d4d7ea7ce9c7e776807c3928d2e 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 6da52f4d58..47ead01255 100644 @@ -39 +40 @@ -@@ -469,6 +469,8 @@ int ice_read_sr_word(struct ice_hw *hw, u16 offset, u16 *data) +@@ -471,6 +471,8 @@ enum ice_status ice_read_sr_word(struct ice_hw *hw, u16 offset, u16 *data) @@ -48,2 +49 @@ -@@ -484,8 +486,7 @@ int - ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, +@@ -487,8 +489,7 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, @@ -51,0 +52 @@ + enum ice_status status; @@ -55 +55,0 @@ - int status; @@ -58 +58,2 @@ -@@ -498,11 +499,23 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, + if (status != ICE_SUCCESS) { +@@ -500,11 +501,23 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, @@ -84 +85 @@ -@@ -519,10 +532,6 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, +@@ -521,10 +534,6 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, @@ -95 +96 @@ -@@ -531,10 +540,13 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, +@@ -533,10 +542,13 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len,