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 2D067A04A4 for ; Wed, 2 Mar 2022 08:41:19 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 02EAA40141; Wed, 2 Mar 2022 08:41:19 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id 5868540141 for ; Wed, 2 Mar 2022 08:41:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646206877; x=1677742877; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AV/fcq1Kish9XEOE8VaezuYDeUBWsg/zPARvq2mUqXY=; b=aAE1KWNOqI0eUl6sUIXQusAr/E66KwQ3JRdploQqqLD8cudko947+0Pt MyxI2ULHyQQ9cQL8syMH4d949g6z/sK2/HTeD0DIs/Um5nJcLiGNFampl sEF4Rz3FNBbNpQ8MBraMXJFHqy+oUsv9LJGVhn/l5IWog8HLcrQ9bkBTE 26B9zlpyDtehZGcialYj0j2tCjrIQmxAoWqZYJL+IZ02HnIKcK+bhY3RM 152mux6j7Vs0SMRZBuYxhdGdx5o9R9/Ul7mHJo4j//MFyfhU1DvfeAnuA Vh9T4T/iOGWLrvYhE5iLkb6hOJyHiQZlzXkGBycoQztVcA9ZxS8gxbIcT w==; X-IronPort-AV: E=McAfee;i="6200,9189,10273"; a="316547246" X-IronPort-AV: E=Sophos;i="5.90,148,1643702400"; d="scan'208";a="316547246" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2022 23:41:15 -0800 X-IronPort-AV: E=Sophos;i="5.90,148,1643702400"; d="scan'208";a="510901515" Received: from unknown (HELO localhost.localdomain) ([10.239.251.3]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2022 23:41:13 -0800 From: wenxuanx.wu@intel.com To: aman.deep.singh@intel.com, yuying.zhang@intel.com, xiaoyun.li@intel.com Cc: dpdk@stable.org, wenxuan wu , stable@dpdk.org Subject: [PATCH v3] app/testpmd: fix heap-free-before-use when quit Date: Wed, 2 Mar 2022 15:20:48 +0800 Message-Id: <20220302072048.242482-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 --- 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