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 9B1BC45A01; Mon, 23 Sep 2024 17:57:00 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2D2ED402BD; Mon, 23 Sep 2024 17:57:00 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by mails.dpdk.org (Postfix) with ESMTP id 87A9040274 for ; Mon, 23 Sep 2024 11:26:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1727083593; x=1758619593; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=6bkMalD1t2PkdHniCcte6lT1pMlaIZO9MZUALVKCsD4=; b=ERtt/HtNHfNWM8gxSo/soI88Op/43AA07e8LUDQoyTOWvY4RvyoHgCdx aWGXgLd4BEuGC45+dq12ZJ8bjMdy4Ptyc6LhmckrMgJemwSD8NH3tdhpN Rm3QvzZGIleoe1HAWeadxulV08i6CXBXP/vAHEW4t+4PvdfoxsZdIBUMT MO56ihefZ0otJj92oEGe9nu8pVONz0SfRp74uClHHi7vsBtZ28XjhWwls GUqPOkvZr6hU5ckPZousQG0Bj9cakgjueF5bY/F/97bhpApl5ULxH3s9L 8X46EPqG9R3DwTilUo9uWBPp/Q2BHiCYlO6Nx4+TlhZPwsY3K2KsLKzfS g==; X-CSE-ConnectionGUID: da8JUxr3RKW8xwODdZHPgg== X-CSE-MsgGUID: uiwOHjYiTGKbWsmSZuW/lQ== X-IronPort-AV: E=McAfee;i="6700,10204,11202"; a="29910129" X-IronPort-AV: E=Sophos;i="6.10,251,1719903600"; d="scan'208";a="29910129" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2024 02:26:32 -0700 X-CSE-ConnectionGUID: +udZN8MeRcm01auQGx7reA== X-CSE-MsgGUID: F5fHx871Rb+FMYys+VkFMA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,251,1719903600"; d="scan'208";a="71008852" Received: from silpixa00401183.ir.intel.com ([10.55.128.236]) by fmviesa009.fm.intel.com with ESMTP; 23 Sep 2024 02:26:31 -0700 From: Niall Meade To: Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko , Roman Zhukov Cc: dev@dpdk.org, Niall Meade Subject: [PATCH v1] ethdev: fix int overflow in descriptor count logic Date: Mon, 23 Sep 2024 09:26:01 +0000 Message-Id: <20240923092601.728817-1-niall.meade@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Organization: Intel Research and Development Ireland Ltd - Co. Reg. #308263 - Collinstown Industrial Park, Leixlip, County Kildare, Ireland Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailman-Approved-At: Mon, 23 Sep 2024 17:56:59 +0200 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 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. 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 --- .mailmap | 1 + lib/ethdev/rte_ethdev.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.mailmap b/.mailmap index 4a508bafad..c1941e78bb 100644 --- a/.mailmap +++ b/.mailmap @@ -1053,6 +1053,7 @@ Nelson Escobar Nemanja Marjanovic Netanel Belgazal Netanel Gonen +Niall Meade Niall Power Nicholas Pratte Nick Connolly diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index f1c658f49e..f978283edf 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -6577,13 +6577,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 = *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_32 = RTE_MAX(nb_desc_32, desc_lim->nb_min); - *nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min); + /* Assign clipped u32 back to u16. */ + *nb_desc = nb_desc_32; } int -- 2.34.1 -------------------------------------------------------------- Intel Research and Development Ireland Limited Registered in Ireland Registered Office: Collinstown Industrial Park, Leixlip, County Kildare Registered Number: 308263 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.