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 3F394A0093; Mon, 18 May 2020 07:40:43 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 01AA91D509; Mon, 18 May 2020 07:40:42 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 51BB81D453; Mon, 18 May 2020 07:40:39 +0200 (CEST) IronPort-SDR: inmM+ik6QDTIcaYT/c+0zDsOmwVqf8VHAINUReEcYch6lHzrT/8Cexmad1n77i49X0AvfJZdtW p6mxaDPZISHQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2020 22:40:38 -0700 IronPort-SDR: JJiGCZachI6S9rMqhFpOxvhJBpSnPcKBFZkDYRTvLTGdF2Cd34sasnpO6wLGYDH24YnaiF5x7p NCR114wRIzfA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,406,1583222400"; d="scan'208";a="465453426" Received: from yexl-server.sh.intel.com (HELO localhost) ([10.67.116.183]) by fmsmga005.fm.intel.com with ESMTP; 17 May 2020 22:40:36 -0700 Date: Mon, 18 May 2020 13:32:10 +0800 From: Ye Xiaolong To: "Zhao1, Wei" Cc: "Guo, Jia" , "dev@dpdk.org" , "stable@dpdk.org" , "Xing, Beilei" Message-ID: <20200518053209.GC93932@intel.com> References: <20200512151915.105152-1-wei.zhao1@intel.com> <20200515072806.GC1064@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Subject: Re: [dpdk-dev] [PATCH] net/i40e: fix the security 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" Hi, Wei On 05/18, Zhao1, Wei wrote: >HI, Xiaolong & guojia > >> -----Original Message----- >> From: Ye, Xiaolong >> Sent: Friday, May 15, 2020 3:28 PM >> To: Guo, Jia >> Cc: Zhao1, Wei ; dev@dpdk.org; stable@dpdk.org; >> Xing, Beilei >> Subject: Re: [dpdk-dev] [PATCH] net/i40e: fix the security risk of wild pointer >> operation >> >> On 05/15, Jeff Guo wrote: >> >hi, zhaowei >> > >> >On 5/12/2020 11:19 PM, Wei Zhao wrote: >> >> In i40e PMD code of function i40e_res_pool_free(), if valid_entry is >> >> freed by "rte_free(valid_entry);" in the following code: >> >> >> >> if (prev != NULL) { >> >> ........................ >> >> >> >> if (insert == 1) { >> >> LIST_REMOVE(valid_entry, next); >> >> rte_free(valid_entry); >> >> } else { >> >> rte_free(valid_entry); >> >> insert = 1; >> >> } >> >> } >> >> >> >> then the following code for pool update may still use the wild >> >> pointer >> >> "valid_entry": >> >> >> >> " pool->num_free += valid_entry->len; >> >> pool->num_alloc -= valid_entry>len; " >> >> it seems to be a security bug, we should avoid this risk. >> >> >> >> Cc: stable@dpdk.org >> >> Fixes: 4861cde46116 ("i40e: new poll mode driver") >> >> >> >> Signed-off-by: Wei Zhao >> >> --- >> >> drivers/net/i40e/i40e_ethdev.c | 6 +++--- >> >> 1 file changed, 3 insertions(+), 3 deletions(-) >> >> >> >> diff --git a/drivers/net/i40e/i40e_ethdev.c >> >> b/drivers/net/i40e/i40e_ethdev.c index 749d85f54..7f8ea5309 100644 >> >> --- a/drivers/net/i40e/i40e_ethdev.c >> >> +++ b/drivers/net/i40e/i40e_ethdev.c >> >> @@ -4973,6 +4973,9 @@ i40e_res_pool_free(struct i40e_res_pool_info >> *pool, >> >> } >> >> insert = 0; >> >> +pool->num_free += valid_entry->len; >> >> +pool->num_alloc -= valid_entry->len; >> >> + >> > >> > >> >Shouldn't the pool count update after the pool->free_list updated by >> >"LIST_INSERT_HEAD(&pool->free_list, valid_entry, next)"? >> > >> >If so, you could use a variable to restore valid_entry->len at the >> >begin and use it update pool count and other place. >> >> Either way works from function point of view, but I do agree with Jeff that uses >> local variable to store the valid_entry->len at the beginning, and then updates >> the pool->num_free/num_alloc at the end. >> >> Also I think it needs to set valid_entry to NULL after free it, it can avoid wild >> pointer case like this, if there is dereference of this pointer after setting it to >> NULL, program would crash directly and we can solve it early. >> >> Thanks, >> Xiaolong > >We must update it after find the proper one in the pool->free_list at once, if we use a local pointer to store it, >The proper entry may has been freed in the following code, and merge with other free resource prev or next. I think Jia's point is to store the valid_entry->len to a local var, not use a local pointer to store valid_entry. And please set valid_entry to NULL after free in the new version. Thanks, Xiaolong > > >> >> > >> > >> >> /* Try to merge with next one*/ >> >> if (next != NULL) { >> >> /* Merge with next one */ >> >> @@ -5010,9 +5013,6 @@ 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; >> >> - >> >> return 0; >> >> }