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 A015445DB9 for ; Wed, 27 Nov 2024 18:21:20 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9C40A402DE; Wed, 27 Nov 2024 18:21:20 +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 554B4402DE for ; Wed, 27 Nov 2024 18:21:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732728078; 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=M7JJLUdqwd0CiRhqfVJU6LU87Ubd7UTuevtIt697V+Q=; b=JU5wEDxzPod6LQtcKr/zNiQ8ml/z4KKOlR7nz/s+x/4i6map/TzqpPD9bcazwmy2IE0ned d7eD7YYZELAey3/CT0jdoIbbSTsqFArcQMYDqh17KJgDf2nK/XYo6JqbJaYqD6uv2tUnbd Z8IDTzzEVapZRsuvbzOiq2jNB0Et7I0= Received: from mx-prod-mc-04.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-164-T78GywAAOuytnSiIlcnH0g-1; Wed, 27 Nov 2024 12:21:16 -0500 X-MC-Unique: T78GywAAOuytnSiIlcnH0g-1 X-Mimecast-MFC-AGG-ID: T78GywAAOuytnSiIlcnH0g 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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6A3E519560AF; Wed, 27 Nov 2024 17:21:15 +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 012F1300019E; Wed, 27 Nov 2024 17:21:13 +0000 (UTC) From: Kevin Traynor To: Niall Meade Cc: Ferruh Yigit , dpdk stable Subject: patch 'ethdev: fix overflow in descriptor count' has been queued to stable release 21.11.9 Date: Wed, 27 Nov 2024 17:17:55 +0000 Message-ID: <20241127171916.690404-48-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: -8txzlHLDUiDgWB0Eddbi9oCRq2wJxVfJQG3dpv-5u0_1732728075 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/9064f0c3785e1915461a732e9b3c907939ba6254 Thanks. Kevin --- >From 9064f0c3785e1915461a732e9b3c907939ba6254 Mon Sep 17 00:00:00 2001 From: Niall Meade Date: Mon, 30 Sep 2024 13:40:02 +0000 Subject: [PATCH] ethdev: fix overflow in descriptor count [ upstream commit 30efe60d3a37896567b660229ef6a04c5526f6db ] Addressed a specific overflow issue in the eth_dev_adjust_nb_desc() function where the uint16_t variable nb_desc would overflow when its value was greater than (2^16 - nb_align). This overflow caused nb_desc to incorrectly wrap around between 0 and nb_align-1, leading to the function setting nb_desc to nb_min instead of the expected nb_max. To give an example, let nb_desc=UINT16_MAX, nb_align=32, nb_max=4096 and nb_min=64. RTE_ALIGN_CEIL(nb_desc, nb_align) calls RTE_ALIGN_FLOOR(nb_desc + nb_align - 1, nb_align). This results in an overflow of nb_desc, leading to nb_desc being set to 30 and then 0 when the macros return. As a result of this, nb_desc is then set to nb_min later on. The resolution involves upcasting nb_desc to a uint32_t before the RTE_ALIGN_CEIL macro is applied. This change ensures that the subsequent call to RTE_ALIGN_FLOOR(nb_desc + (nb_align - 1), nb_align) does not result in an overflow, as it would when nb_desc is a uint16_t. By using a uint32_t for these operations, the correct behavior is maintained without the risk of overflow. Fixes: 0f67fc3baeb9 ("ethdev: add function to adjust number of descriptors") Signed-off-by: Niall Meade Reviewed-by: Ferruh Yigit --- .mailmap | 1 + lib/ethdev/rte_ethdev.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.mailmap b/.mailmap index 5d6a7701d7..296e6528b6 100644 --- a/.mailmap +++ b/.mailmap @@ -989,4 +989,5 @@ Nemanja Marjanovic Netanel Belgazal Netanel Gonen +Niall Meade Niall Power Nick Connolly diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index b246f7836a..1b2e1750c9 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -5858,11 +5858,17 @@ eth_dev_adjust_nb_desc(uint16_t *nb_desc, const struct rte_eth_desc_lim *desc_lim) { + /* Upcast to uint32 to avoid potential overflow with RTE_ALIGN_CEIL(). */ + uint32_t nb_desc_32 = (uint32_t)*nb_desc; + if (desc_lim->nb_align != 0) - *nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align); + nb_desc_32 = RTE_ALIGN_CEIL(nb_desc_32, desc_lim->nb_align); if (desc_lim->nb_max != 0) - *nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max); + nb_desc_32 = RTE_MIN(nb_desc_32, desc_lim->nb_max); - *nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min); + nb_desc_32 = RTE_MAX(nb_desc_32, desc_lim->nb_min); + + /* Assign clipped u32 back to u16. */ + *nb_desc = (uint16_t)nb_desc_32; } -- 2.47.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2024-11-27 17:17:39.788159964 +0000 +++ 0048-ethdev-fix-overflow-in-descriptor-count.patch 2024-11-27 17:17:38.222269357 +0000 @@ -1 +1 @@ -From 30efe60d3a37896567b660229ef6a04c5526f6db Mon Sep 17 00:00:00 2001 +From 9064f0c3785e1915461a732e9b3c907939ba6254 Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 30efe60d3a37896567b660229ef6a04c5526f6db ] + @@ -27 +28,0 @@ -Cc: stable@dpdk.org @@ -37 +38 @@ -index d49838320e..6e72362ebc 100644 +index 5d6a7701d7..296e6528b6 100644 @@ -40 +41 @@ -@@ -1071,4 +1071,5 @@ Nemanja Marjanovic +@@ -989,4 +989,5 @@ Nemanja Marjanovic @@ -45 +46 @@ - Nicholas Pratte + Nick Connolly @@ -47 +48 @@ -index a1f7efa913..84ee7588fc 100644 +index b246f7836a..1b2e1750c9 100644 @@ -50 +51 @@ -@@ -6668,11 +6668,17 @@ eth_dev_adjust_nb_desc(uint16_t *nb_desc, +@@ -5858,11 +5858,17 @@ eth_dev_adjust_nb_desc(uint16_t *nb_desc,