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 96598A04A4 for ; Wed, 2 Mar 2022 08:29:26 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8323340141; Wed, 2 Mar 2022 08:29:26 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mails.dpdk.org (Postfix) with ESMTP id 9E61840141 for ; Wed, 2 Mar 2022 08:29:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646206165; x=1677742165; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=AV/fcq1Kish9XEOE8VaezuYDeUBWsg/zPARvq2mUqXY=; b=TjudqbqlkSCt+WnpBVvESC9v+O7rTLbSzJVIDTccXXWDj4etFzEo5BwY beO3waRUjnaQ3Eo4jZbZx8yupcUhDllQKAGsmPKNhEcnWuhmGHK6cG0DH 57FEjIkXbaTHk94lpVpD7cR8IlbwTDd6Ml9ety2u7QVlO//TLtjv79PCa XF1cMs5zifNpDJ0X6uFO4Er466oPmggq3BhO31xYVOctkk/65y6kN9Tx/ 0OQluVqF2NpNavfmwpP67Ukrowk7WHmyyKUPd7uCpC0TIkQDGvO2/3pOb KzuHCX6x/4ld+ukDCTlelqP+GRbDrvQ6GpG+A/rYVjqZCR6bO6Rihk92B w==; X-IronPort-AV: E=McAfee;i="6200,9189,10273"; a="252160981" X-IronPort-AV: E=Sophos;i="5.90,148,1643702400"; d="scan'208";a="252160981" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2022 23:29:23 -0800 X-IronPort-AV: E=Sophos;i="5.90,148,1643702400"; d="scan'208";a="709401256" Received: from unknown (HELO localhost.localdomain) ([10.239.251.3]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2022 23:29:21 -0800 From: wenxuanx.wu@intel.com To: build_sh@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 15:08:56 +0800 Message-Id: <20220302070856.241054-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 --- 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