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 2B4A5A04A4 for ; Wed, 2 Mar 2022 09:24:54 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1BFE140141; Wed, 2 Mar 2022 09:24:54 +0100 (CET) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id 05F8040141 for ; Wed, 2 Mar 2022 09:24:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646209492; x=1677745492; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=u7jFWzbEpG14bq+I8vu38UcGP3vIys7UB+QYKaDSxek=; b=EJrDFN438R8uULgn9DxS2uWUcrzF3QKbSXUaxC1Ujw+XPbsu/X1CeZ8H iaGuJJ3Z3z63vBHneeoE5E6TE9tkaOvQ8n7XifEwGvPCUiDfCD+4JZoNd FfcRBa10HKPPbEkV4EcOMCOta4wg2fu7cLwjTXIaS1LZKOSmA7NP0KzAR noFc7L0U//W1EM1gpyhMtpYdYXPqpSnSRR+j5hXjVyZZXrKggAuPd5YgN 55iQ6UhyCU3ylS6IjHdf5Ug656nxNyRIzSDSUUF9lStluglBdfjyqjm+2 QRe/v3JiZK7wsnak2tWJCX/eS/YxA5kAF+j+pvVNWnECcnvmfCagKB9I9 w==; X-IronPort-AV: E=McAfee;i="6200,9189,10273"; a="240755760" X-IronPort-AV: E=Sophos;i="5.90,148,1643702400"; d="scan'208";a="240755760" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2022 00:24:51 -0800 X-IronPort-AV: E=Sophos;i="5.90,148,1643702400"; d="scan'208";a="535291555" Received: from unknown (HELO localhost.localdomain) ([10.239.251.3]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2022 00:24:49 -0800 From: wenxuanx.wu@intel.com To: build_sh@intel.com Cc: wenxuan wu , stable@dpdk.org Subject: [DPDK] app/testpmd: fix heap-free-before-use when quit Date: Wed, 2 Mar 2022 16:04:26 +0800 Message-Id: <20220302080426.255200-1-wenxuanx.wu@intel.com> X-Mailer: git-send-email 2.25.1 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