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 4A1D045BB6 for ; Wed, 23 Oct 2024 23:20:25 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 435C640261; Wed, 23 Oct 2024 23:20:25 +0200 (CEST) Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by mails.dpdk.org (Postfix) with ESMTP id 1609D4330A for ; Wed, 23 Oct 2024 23:20:24 +0200 (CEST) Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-37d3ecad390so984041f8f.1 for ; Wed, 23 Oct 2024 14:20:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729718424; x=1730323224; 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=kBaMplcix8C+lfyeMR9x9yFKFf8YslSwoXiwFXQXQb0=; b=Wy2DfASVPoRV167V2YkmkNFs8fwM+2oaRue8ZcUyY5TqhGyCXGwicx4Z2CZbCQd6kZ QlonpMs4zwa+NXZ1F2Trb3ZFcn6SMckYjKMu9BOKRAKe5T8gdftk7wbWsMAhyRYtSrQw D0yjS7d+ututb80mV8NPWt4KwZUffBUzpnFs03CvVlSqe0b4iLiXcMpXmX7s40QBDhiS KTNLoq4AimBJn+W1ksf4tRVE3IZxSBZOOWZBQgPSlnzs6U/1c9X4pS8tiUa09ftQstTr uCqVB5jQE5A+9DrMUtzozY3EXVPisiLcQuNO5CucTRKTTSFdMNm1gBZNyqbPvQTFNqVZ WScQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729718424; x=1730323224; 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=kBaMplcix8C+lfyeMR9x9yFKFf8YslSwoXiwFXQXQb0=; b=bmwsN5tA6zko7gMV16pnEJUbCkZcluiGW4fpUc7CeOtidpx/Pmz9VnPExJ3nA4XY/S aP198hp3DPhcI8Mptl1rE5NTsfRy5b8OXcyMl6D7IbhwGupSER55IPonlwrDg0HqYstS 1WdgMEyF4ukPYWyt85DfSwKQTpdnf/YtU46oI84VrNeoGr2UbaCScPleT4pEX4Y7uFld 5q16F+4LNv1bMHV8/meQzp3mzhd90QpWps61rNuneg/kTSZmtlGk7kwUV6CmyEQCRl34 +xXRD3YtqmmCb2b+a//G8e1NAoAw2ADUeZHN/RReMlc7RsVuTgAkrjVhmmh0s024902J 7afA== X-Forwarded-Encrypted: i=1; AJvYcCX1Dn+hIfZLcvm6obkJf1hIXajqdvPasy0Ksuc2cricfAaDfh8FFYUbtCjZGbnyqaghTpM3j8U=@dpdk.org X-Gm-Message-State: AOJu0Ywe2e9o8hFWU3RisR7AmkX6IttK+ufs5bCRdlvEZJqqLB61xRWN 0gGCMtmgIFUUEvVLZVvSzS3wfObQSXmcKja1BP2paxHsgl3Lo5BXoi0QGf9Y X-Google-Smtp-Source: AGHT+IFVjC7j0QtvkY8GpfIGKQ9J8PJAMkxKieHK9HjSZPryiFq0gDqD8OM86tAGDI7K0Uu0JpIQ7Q== X-Received: by 2002:adf:e88d:0:b0:37d:47eb:b586 with SMTP id ffacd0b85a97d-37ef12592e5mr5685708f8f.4.1729718423468; Wed, 23 Oct 2024 14:20:23 -0700 (PDT) Received: from localhost ([2a01:4b00:d036:ae00:21cd:def0:a01d:d2aa]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43186c50a49sm26762185e9.48.2024.10.23.14.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 14:20:22 -0700 (PDT) From: luca.boccassi@gmail.com To: Niall Meade Cc: Ferruh Yigit , dpdk stable Subject: patch 'ethdev: fix overflow in descriptor count' has been queued to stable release 22.11.7 Date: Wed, 23 Oct 2024 22:16:35 +0100 Message-ID: <20241023211704.1216956-55-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/a905d9d63ec9bb6540978f1906c3d7f591c78586 Thanks. Luca Boccassi --- >From a905d9d63ec9bb6540978f1906c3d7f591c78586 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 8c7b38fb35..dd1c6a6a87 100644 --- a/.mailmap +++ b/.mailmap @@ -989,6 +989,7 @@ Nelson Escobar Nemanja Marjanovic Netanel Belgazal Netanel Gonen +Niall Meade Niall Power Nick Connolly Nick Nunley diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index e1f18fd8a4..e85dc3d8b2 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -5739,13 +5739,19 @@ static void 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; } int -- 2.45.2 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2024-10-23 22:16:42.606290111 +0100 +++ 0055-ethdev-fix-overflow-in-descriptor-count.patch 2024-10-23 22:16:40.515943363 +0100 @@ -1 +1 @@ -From 30efe60d3a37896567b660229ef6a04c5526f6db Mon Sep 17 00:00:00 2001 +From a905d9d63ec9bb6540978f1906c3d7f591c78586 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 8c7b38fb35..dd1c6a6a87 100644 @@ -40 +41 @@ -@@ -1070,6 +1070,7 @@ Nelson Escobar +@@ -989,6 +989,7 @@ Nelson Escobar @@ -46 +46,0 @@ - Nicholas Pratte @@ -47,0 +48 @@ + Nick Nunley @@ -49 +50 @@ -index a1f7efa913..84ee7588fc 100644 +index e1f18fd8a4..e85dc3d8b2 100644 @@ -52 +53 @@ -@@ -6667,13 +6667,19 @@ static void +@@ -5739,13 +5739,19 @@ static void