From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 66244A0093; Mon, 18 May 2020 09:06:52 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 66FBD1D549; Mon, 18 May 2020 09:06:47 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 2FEA21D548; Mon, 18 May 2020 09:06:45 +0200 (CEST) IronPort-SDR: g7GxzBJ+TGXXqGy8MkOIGWcNxc3pOuGCOdAIjA41sErA5k0T05NLoppAGZNva1iTqoRUn4/egO o8jnFu/t2ypg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2020 00:06:45 -0700 IronPort-SDR: 5gjMtXEgG2ZCF2UO2w9RlSFhHKnNqFyp5gbrH0mZQq8njCDMgpA3ZALaB4dC3Nq1bHVOx1w/tj y1Y8/mrU1KiA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,406,1583222400"; d="scan'208";a="465474997" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([172.16.182.123]) by fmsmga005.fm.intel.com with ESMTP; 18 May 2020 00:06:43 -0700 From: Wei Zhao To: dev@dpdk.org Cc: stable@dpdk.org, xiaolong.ye@intel.com, jia.guo@intel.com, Wei Zhao Date: Mon, 18 May 2020 14:43:24 +0800 Message-Id: <20200518064324.34859-1-wei.zhao1@intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20200518051032.33365-1-wei.zhao1@intel.com> References: <20200518051032.33365-1-wei.zhao1@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3] net/i40e: fix the core dump risk of wild pointer operation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" In i40e PMD code of function i40e_res_pool_free(), if valid_entry is freed by "rte_free(valid_entry);" in the code, then the following code for pool update may still use the wild pointer "valid_entry" for pool info update. It seems has the risk of core dump for using wild pointer operation, we should avoid this risk. Cc: stable@dpdk.org Fixes: 4861cde46116 ("i40e: new poll mode driver") Signed-off-by: Wei Zhao --- v2: update commit log v3: set free pointer to NULL --- drivers/net/i40e/i40e_ethdev.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c index 749d85f54..c9601d683 100644 --- a/drivers/net/i40e/i40e_ethdev.c +++ b/drivers/net/i40e/i40e_ethdev.c @@ -4936,6 +4936,7 @@ i40e_res_pool_free(struct i40e_res_pool_info *pool, struct pool_entry *entry, *next, *prev, *valid_entry = NULL; uint32_t pool_offset; int insert; + uint16_t len; if (pool == NULL) { PMD_DRV_LOG(ERR, "Invalid parameter"); @@ -4973,6 +4974,7 @@ i40e_res_pool_free(struct i40e_res_pool_info *pool, } insert = 0; + len = valid_entry->len; /* Try to merge with next one*/ if (next != NULL) { /* Merge with next one */ @@ -4993,8 +4995,10 @@ i40e_res_pool_free(struct i40e_res_pool_info *pool, if (insert == 1) { LIST_REMOVE(valid_entry, next); rte_free(valid_entry); + valid_entry = NULL; } else { rte_free(valid_entry); + valid_entry = NULL; insert = 1; } } @@ -5010,8 +5014,8 @@ i40e_res_pool_free(struct i40e_res_pool_info *pool, LIST_INSERT_HEAD(&pool->free_list, valid_entry, next); } - pool->num_free += valid_entry->len; - pool->num_alloc -= valid_entry->len; + pool->num_free += len; + pool->num_alloc -= len; return 0; } -- 2.19.1