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 E11AE45A48; Sat, 28 Sep 2024 00:14:16 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E0FBC406B6; Sat, 28 Sep 2024 00:13:40 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by mails.dpdk.org (Postfix) with ESMTP id 56F2F4025D for ; Fri, 27 Sep 2024 15:23:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1727443418; x=1758979418; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=/h49M1GqMAADNZKVWJv3+rp8SqtMcxtMhEfflAYepmk=; b=YrhOU7W7l/UuwDW7LmP3WIhzswNeqWrORR7dAGNJWoeRxVTWNwHxc6QU Y0++dM2EuaAZF7GyoFWC46+eUympZYF4C61SKkRoFGtfuU4hDlTI8lcS9 EscTDLnESQLmEOJo6FHuLj3UJma8EGD6zNS7y95DlrKXDW/J72L/UEXZU 2ioGLJb2W5W8X4tB+jfTsNXvEVJKD0D4um5HF5B7XtSh/dSpUhs8XC/5f KiJ/C/Z/Jo1BHLUI8U+5XOCwzgTUmtsm2ivGxWK0EMKBiq/rXeWrUdTAJ 8yGdQQBAyQGlY8WIVR82Oi8S2EGWlguewlU/DS/jNBtkX/jsUwUKyCUzz g==; X-CSE-ConnectionGUID: qKoDO/HaTDe86uT1I6XxwQ== X-CSE-MsgGUID: TmWOXIw0S0eF0eNjd8Rbug== X-IronPort-AV: E=McAfee;i="6700,10204,11207"; a="37724062" X-IronPort-AV: E=Sophos;i="6.11,158,1725346800"; d="scan'208";a="37724062" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Sep 2024 06:23:36 -0700 X-CSE-ConnectionGUID: emeMbP6VTXipZOgYwVBk9A== X-CSE-MsgGUID: hODLSFEjRl6W+V5ggfX1Xg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,158,1725346800"; d="scan'208";a="72615286" Received: from silpixa00401183.ir.intel.com ([10.55.128.236]) by orviesa009.jf.intel.com with ESMTP; 27 Sep 2024 06:23:35 -0700 From: Niall Meade To: Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko , Roman Zhukov Cc: dev@dpdk.org, Niall Meade Subject: [PATCH v2 1/1] ethdev: fix int overflow in descriptor count logic Date: Fri, 27 Sep 2024 13:23:29 +0000 Message-Id: <20240927132329.296038-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: Sat, 28 Sep 2024 00:13:29 +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. 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 --- v2: * add example of issue to commit message --- .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.