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 23630A034F for ; Tue, 1 Mar 2022 08:49:19 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0F860407FF; Tue, 1 Mar 2022 08:49:19 +0100 (CET) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mails.dpdk.org (Postfix) with ESMTP id 4D112407FF for ; Tue, 1 Mar 2022 08:49: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=1646120957; x=1677656957; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AV/fcq1Kish9XEOE8VaezuYDeUBWsg/zPARvq2mUqXY=; b=CE83HqCcnkkq+lZWv7RtyUhYFSAkQr/lwJ3Zu4KQ6g12fpN2doz3H8N5 I2QJTGdLvcMgNNvnZOjEYPNGT/UKO29YKRGgJnGB7dAbSpIMJ+h6oXrlv mwcmXd6LLhfLXhKswEzKSjIioPkCyYad2637PLehrs62UuACDChRacDdq Vy9rAd/FWM0RWKJUAxicVsb6plDHpcHf15TqpSUtak4e9EZMp8H0u+upY QFPep3UxSb3qLyHoL9OjL7rn4AMUDsU5JYqC8GR90jit2GzYD0XfCURm6 w6MVEtrtxzssh6/Z11OcSeC/d6KrIGy3uAFAUttpIJ3z92O+yZ3MXB6iU Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10272"; a="339512775" X-IronPort-AV: E=Sophos;i="5.90,145,1643702400"; d="scan'208";a="339512775" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2022 23:49:16 -0800 X-IronPort-AV: E=Sophos;i="5.90,145,1643702400"; d="scan'208";a="641170158" Received: from unknown (HELO localhost.localdomain) ([10.239.251.3]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2022 23:49:14 -0800 From: wenxuanx.wu@intel.com To: yuying.zhang@intel.com, xiaoyun.li@intel.com, aman.deep.singh@intel.com Cc: dpdk@stable.org, wenxuan wu , stable@dpdk.org Subject: [PATCH v3] app/testpmd: fix heap-free-before-use when quit Date: Tue, 1 Mar 2022 15:28:56 +0800 Message-Id: <20220301072856.182932-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