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 603D5A04A4 for ; Wed, 2 Mar 2022 09:57:14 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4C4DF40141; Wed, 2 Mar 2022 09:57:14 +0100 (CET) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mails.dpdk.org (Postfix) with ESMTP id 7F14D40141 for ; Wed, 2 Mar 2022 09:57:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646211432; x=1677747432; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=u7jFWzbEpG14bq+I8vu38UcGP3vIys7UB+QYKaDSxek=; b=mJHRjhgX4bPnJ0Er3jALHZaHF465xMAH7ChjE6pklYWbnrW0uO0I06Tc IjnV2bapLUf3ZqOZbfbyIQgiYTE2A1LQ4QVij8jzoOftgjmj9q8O77ya1 L+hLDPW5rLI66ZRJkFJucsZNU7tD84DrzdbjkGmH43Wy2xLgvEF54p1Fh E8v8j2B3kSMitdanT3SOGxSm/OH64vp4YrSxjG8vH6aGVwj1WgX/l4e2J QX17rMSiOJhstyTpO7DButuH4BkdN4pT/y1CIy85+65jWRWRVWGrLkBCc 8ILoqjMM5v2l2Ti6hTADZTY9ELom57hVLkgJT1Wb4m2FXVEAfHwAYLYIt Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10273"; a="250926234" X-IronPort-AV: E=Sophos;i="5.90,148,1643702400"; d="scan'208";a="250926234" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2022 00:54:54 -0800 X-IronPort-AV: E=Sophos;i="5.90,148,1643702400"; d="scan'208";a="551157262" Received: from unknown (HELO localhost.localdomain) ([10.239.251.3]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2022 00:54:52 -0800 From: wenxuanx.wu@intel.com To: aman.deep.singh@intel.com, yuying.zhang@intel.com, xiaoyun.li@intel.com Cc: wenxuan wu , stable@dpdk.org Subject: [PATCH v3] app/testpmd: fix heap-free-before-use when quit Date: Wed, 2 Mar 2022 16:34:26 +0800 Message-Id: <20220302083426.257951-1-wenxuanx.wu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220223113251.723692-3-wenxuanx.wu@intel.com> References: <20220223113251.723692-3-wenxuanx.wu@intel.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 From: wenxuan wu Change func logic is_bonding_slave and set_port_slave_flag to avoid this error. Port->slave_flag with dev_flag check to ensure slave_flag is securely set. Remove eth_dev_info_get in func is_bonding_slave, which would lead to a heap-free-before-use error the reason is that vf was still accessing a freed pf resource. Fixes: 0a0821bcf312 ("app/testpmd: remove most uses of internal ethdev array") Cc: stable@dpdk.org Signed-off-by: Wenxuan Wu --- ...d-fix-heap-free-before-use-when-quit.patch | 87 +++++++++++++++++++ app/test-pmd/testpmd.c | 31 +++---- 2 files changed, 101 insertions(+), 17 deletions(-) create mode 100644 0001-app-testpmd-fix-heap-free-before-use-when-quit.patch diff --git a/0001-app-testpmd-fix-heap-free-before-use-when-quit.patch b/0001-app-testpmd-fix-heap-free-before-use-when-quit.patch new file mode 100644 index 0000000000..70d7fc8342 --- /dev/null +++ b/0001-app-testpmd-fix-heap-free-before-use-when-quit.patch @@ -0,0 +1,87 @@ +From 78fdeab26f9f01bdee1ca5648c1314acb5a4e6fe Mon Sep 17 00:00:00 2001 +From: wenxuan wu +Date: Tue, 1 Mar 2022 14:07:37 +0800 +Subject: [DPDK] app/testpmd: fix heap-free-before-use when quit + +Change func logic is_bonding_slave and set_port_slave_flag to avoid this +error.Port->slave_flag with dev_flag check to ensure slave_flag is securely +set. + +Remove eth_dev_info_get in func is_bonding_slave, which would lead to +a heap-free-before-use error the reason is that vf was still accessing a +freed pf resource. + +Fixes: 0a0821bcf312 ("app/testpmd: remove most uses of internal ethdev array") +Cc: stable@dpdk.org + +Signed-off-by: Wenxuan Wu +--- + app/test-pmd/testpmd.c | 33 ++++++++++++++++----------------- + 1 file changed, 16 insertions(+), 17 deletions(-) + +diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c +index e1da961311..dcba11f7a6 100644 +--- a/app/test-pmd/testpmd.c ++++ b/app/test-pmd/testpmd.c +@@ -3805,15 +3805,23 @@ init_port_config(void) + } + } + +-void set_port_slave_flag(portid_t slave_pid) ++void ++set_port_slave_flag(portid_t slave_pid) + { + struct rte_port *port; +- ++ struct rte_eth_dev_info dev_info; ++ int ret; + port = &ports[slave_pid]; +- port->slave_flag = 1; ++ ret = eth_dev_info_get_print_err(slave_pid, &dev_info); ++ if (ret != 0) ++ return; ++ ++ if (*dev_info.dev_flags & RTE_ETH_DEV_BONDED_SLAVE) ++ port->slave_flag = 1; + } + +-void clear_port_slave_flag(portid_t slave_pid) ++void ++clear_port_slave_flag(portid_t slave_pid) + { + struct rte_port *port; + +@@ -3821,26 +3829,17 @@ void clear_port_slave_flag(portid_t slave_pid) + port->slave_flag = 0; + } + +-uint8_t port_is_bonding_slave(portid_t slave_pid) ++uint8_t ++port_is_bonding_slave(portid_t slave_pid) + { + struct rte_port *port; +- struct rte_eth_dev_info dev_info; +- int ret; +- + port = &ports[slave_pid]; +- ret = eth_dev_info_get_print_err(slave_pid, &dev_info); +- if (ret != 0) { +- TESTPMD_LOG(ERR, +- "Failed to get device info for port id %d," +- "cannot determine if the port is a bonded slave", +- slave_pid); +- return 0; +- } +- if ((*dev_info.dev_flags & RTE_ETH_DEV_BONDED_SLAVE) || (port->slave_flag == 1)) ++ if (port->slave_flag == 1) + return 1; + return 0; + } + ++ + const uint16_t vlan_tags[] = { + 0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, +-- +2.25.1 + diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index e1da961311..6f7ad974b6 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -3805,15 +3805,22 @@ init_port_config(void) } } -void set_port_slave_flag(portid_t slave_pid) +void +set_port_slave_flag(portid_t slave_pid) { struct rte_port *port; - + struct rte_eth_dev_info dev_info; + int ret; port = &ports[slave_pid]; - port->slave_flag = 1; + ret = eth_dev_info_get_print_err(slave_pid, &dev_info); + if (ret != 0) + return; + if (*dev_info.dev_flags & RTE_ETH_DEV_BONDED_SLAVE) + port->slave_flag = 1; } -void clear_port_slave_flag(portid_t slave_pid) +void +clear_port_slave_flag(portid_t slave_pid) { struct rte_port *port; @@ -3821,22 +3828,12 @@ void clear_port_slave_flag(portid_t slave_pid) port->slave_flag = 0; } -uint8_t port_is_bonding_slave(portid_t slave_pid) +uint8_t +port_is_bonding_slave(portid_t slave_pid) { struct rte_port *port; - struct rte_eth_dev_info dev_info; - int ret; - port = &ports[slave_pid]; - ret = eth_dev_info_get_print_err(slave_pid, &dev_info); - if (ret != 0) { - TESTPMD_LOG(ERR, - "Failed to get device info for port id %d," - "cannot determine if the port is a bonded slave", - slave_pid); - return 0; - } - if ((*dev_info.dev_flags & RTE_ETH_DEV_BONDED_SLAVE) || (port->slave_flag == 1)) + if (port->slave_flag == 1) return 1; return 0; } -- 2.25.1