net/i40e: fix the security risk of wild pointer operation
PATCH 1/1 net/i40e: fix the security risk of wild pointer operation
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.
--- drivers/net/i40e/i40e_ethdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/i40e/i40e_ethdev.c +3 -3
@@ -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; +/* 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 ; }
Signature · 1 line
2.17.1
Can any one view for this patch?
Thanks!
Quoted 67 lines
-----Original Message-----
From: Zhao1, Wei <[email protected]>
Sent: Tuesday, May 12, 2020 11:19 PM
To: [email protected]
Cc: [email protected]; Xing, Beilei <[email protected]>; Zhao1, Wei <[email protected]>
Subject: [PATCH] net/i40e: fix the security risk of wild pointer operationIn i40e PMD code of function
i40e_res_pool_free(), ifvalid_entryis 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.Fixes 4861cde46116 ("i40e: new poll mode driver")Signed-off-by Wei Zhao <[email protected]>--- drivers/net/i40e/i40e_ethdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/net/i40e/i40e_ethdev.c +3
-0@@ -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; +/* Try to merge with next one*/ if (next !=NULL ) {drivers/net/i40e/i40e_ethdev.c +0
-4/* 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 ; } --2.17.1
hi, zhaowei
Quoted 36 lines · Wei Zhao
In i40e PMD code of function
i40e_res_pool_free(), ifvalid_entryis 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.Fixes 4861cde46116 ("i40e: new poll mode driver")Signed-off-by Wei Zhao <[email protected]>--- drivers/net/i40e/i40e_ethdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/net/i40e/i40e_ethdev.c +0
-0
drivers/net/i40e/i40e_ethdev.c i40e_res_pool_free(struct i40e_res_pool_info *pool, · line 4978
Quoted 6 lines
drivers/net/i40e/i40e_ethdev.c +3
-0@@ -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.
Quoted 13 lines
drivers/net/i40e/i40e_ethdev.c +0
-3/* 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 ; }
Quoted 49 lines · Jeff Guo
hi, zhaowei
Quoted 36 lines · Wei Zhao
In i40e PMD code of function
i40e_res_pool_free(), ifvalid_entryis 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.Fixes 4861cde46116 ("i40e: new poll mode driver")Signed-off-by Wei Zhao <[email protected]>--- drivers/net/i40e/i40e_ethdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/net/i40e/i40e_ethdev.c +0
-0drivers/net/i40e/i40e_ethdev.c i40e_res_pool_free(struct i40e_res_pool_info *pool, · line 4977
Quoted 5 lines
drivers/net/i40e/i40e_ethdev.c +3
-0@@ -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_listupdated by "LIST_INSERT_HEAD(&pool->free_list, valid_entry, next)"?
Quoted 2 lines
If so, you could use a variable to restore
valid_entry->lenat 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
Quoted 13 lines
Quoted 13 lines
drivers/net/i40e/i40e_ethdev.c +0
-3/* 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 ; }
HI, Xiaolong & guojia
Quoted 67 lines
-----Original Message-----
From: Ye, Xiaolong <[email protected]>
Sent: Friday, May 15, 2020 3:28 PM
To: Guo, Jia <[email protected]>
Cc: Zhao1, Wei <[email protected]>; [email protected]; [email protected]; Xing, Beilei <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] net/i40e: fix the security risk of wild pointer operationQuoted 34 lines · Jeff Guo
hi, zhaowei
Quoted 31 lines · Wei Zhao
In i40e PMD code of function
i40e_res_pool_free(), ifvalid_entryis 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.
Fixes 4861cde46116 ("i40e: new poll mode driver")Signed-off-by Wei Zhao <[email protected]>--- drivers/net/i40e/i40e_ethdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)Quoted 5 lines
drivers/net/i40e/i40e_ethdev.c i40e_res_pool_free(struct i40e_res_pool_info
Quoted 5 lines
(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.cindex749d85f54..7f8ea5309100644drivers/net/i40e/i40e_ethdev.c +0
-0@@ -4973,6 +4973,9 @@ i40e_res_pool_free(struct i40e_res_pool_info*pool,
Quoted 10 lines
drivers/net/i40e/i40e_ethdev.c i40e_res_pool_free(struct i40e_res_pool_info *pool, · line 4978
Quoted 5 lines
drivers/net/i40e/i40e_ethdev.c +3
-0} insert =0 ; + pool->num_free += valid_entry->len; + pool->num_alloc -= valid_entry->len; +Shouldn't the pool count update after the
pool->free_listupdated by "LIST_INSERT_HEAD(&pool->free_list, valid_entry, next)"?Quoted 2 lines
If so, you could use a variable to restore
valid_entry->lenat 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->lenat the beginning, and then updates the pool->num_free/num_alloc at the end.
Quoted 6 lines
Also I think it needs to set
valid_entryto 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.
Quoted 15 lines
Quoted 7 lines
drivers/net/i40e/i40e_ethdev.c i40e_res_pool_free(struct i40e_res_pool_info
Quoted 7 lines
drivers/net/i40e/i40e_ethdev.c +0
-0/* 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,
Quoted 7 lines
Quoted 7 lines
drivers/net/i40e/i40e_ethdev.c +0
-3LIST_INSERT_HEAD (&pool->free_list, valid_entry, next); } - pool->num_free += valid_entry->len; - pool->num_alloc -= valid_entry->len; -return 0 ; }
Hi, Wei
Quoted 73 lines · Wei
HI, Xiaolong & guojia
Quoted 71 lines
-----Original Message-----
From: Ye, Xiaolong <[email protected]>
Sent: Friday, May 15, 2020 3:28 PM
To: Guo, Jia <[email protected]>
Cc: Zhao1, Wei <[email protected]>; [email protected]; [email protected]; Xing, Beilei <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] net/i40e: fix the security risk of wild pointer operationQuoted 34 lines · Jeff Guo
hi, zhaowei
Quoted 31 lines · Wei Zhao
In i40e PMD code of function
i40e_res_pool_free(), ifvalid_entryis 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.
Fixes 4861cde46116 ("i40e: new poll mode driver")Signed-off-by Wei Zhao <[email protected]>--- drivers/net/i40e/i40e_ethdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)Quoted 5 lines
drivers/net/i40e/i40e_ethdev.c i40e_res_pool_free(struct i40e_res_pool_info
Quoted 5 lines
(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.cindex749d85f54..7f8ea5309100644drivers/net/i40e/i40e_ethdev.c +0
-0@@ -4973,6 +4973,9 @@ i40e_res_pool_free(struct i40e_res_pool_info*pool,
Quoted 10 lines
drivers/net/i40e/i40e_ethdev.c i40e_res_pool_free(struct i40e_res_pool_info *pool, · line 4978
Quoted 5 lines
drivers/net/i40e/i40e_ethdev.c +3
-0} insert =0 ; +pool->num_free += valid_entry->len; +pool->num_alloc -= valid_entry->len; +Shouldn't the pool count update after the
pool->free_listupdated by "LIST_INSERT_HEAD(&pool->free_list, valid_entry, next)"?Quoted 2 lines
If so, you could use a variable to restore
valid_entry->lenat 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->lenat the beginning, and then updates the pool->num_free/num_alloc at the end.Also I think it needs to set
valid_entryto 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.
Quoted 5 lines
Quoted 2 lines
Thanks,
XiaolongWe must update it after find the proper one in the
pool->free_listat 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
Quoted 17 lines
Quoted 17 lines
Quoted 9 lines
drivers/net/i40e/i40e_ethdev.c i40e_res_pool_free(struct i40e_res_pool_info
Quoted 9 lines
drivers/net/i40e/i40e_ethdev.c +0
-0/* 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,
Quoted 7 lines
Quoted 7 lines
drivers/net/i40e/i40e_ethdev.c +0
-3LIST_INSERT_HEAD (&pool->free_list, valid_entry, next); } -pool->num_free += valid_entry->len; -pool->num_alloc -= valid_entry->len; -return 0 ; }
PATCH v2 1/1 net/i40e: fix the core dump risk of wild pointer operation
In reply to Wei ZhaoIn 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.
---
v2:
update commit log
--- drivers/net/i40e/i40e_ethdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/i40e/i40e_ethdev.c +3 -3
@@ -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; +/* 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 ; }
Signature · 1 line
2.17.1
PATCH v3 1/1 net/i40e: fix the core dump risk of wild pointer operation
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.
---
v2:
update commit log
v3:
set free pointer to NULL
--- drivers/net/i40e/i40e_ethdev.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/i40e/i40e_ethdev.c +6 -2
@@ -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 ; }
Signature · 1 line
2.19.1
PATCH v4 1/1 net/i40e: fix the core dump risk of wild pointer operation
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.
---
v2:
update commit log
v3:
set free pointer to NULL
v4:
change code style
--- drivers/net/i40e/i40e_ethdev.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/net/i40e/i40e_ethdev.c +10 -6
@@ -4935,6 +4935,7 @@ i40e_res_pool_free(struct i40e_res_pool_info *pool, {struct pool_entry *entry, *next, *prev, *valid_entry =NULL ;uint32_t pool_offset; +uint16_t len;int insert;if (pool ==NULL ) {
@@ -4973,12 +4974,13 @@ 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 */ -if (valid_entry->base + valid_entry->len == next->base) { +if (valid_entry->base + len == next->base) { next->base = valid_entry->base; - next->len += valid_entry->len; + next->len += len;rte_free (valid_entry); valid_entry = next; insert =1 ;
@@ -4987,14 +4989,16 @@ i40e_res_pool_free(struct i40e_res_pool_info *pool,if (prev !=NULL ) {/* Merge with previous one */ -if (prev->base + prev->len == valid_entry->base) { - prev->len += valid_entry->len; +if (prev->base + len == valid_entry->base) { + prev->len += len;/* If it merge with next one, remove next node */ 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 ; }
Signature · 1 line
2.19.1
PATCH v5 1/1 net/i40e: fix the core dump risk of wild pointer operation
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.
---
v2:
update commit log
v3:
set free pointer to NULL
v4:
change code style
v5:
fix an issue in v4
--- drivers/net/i40e/i40e_ethdev.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/net/i40e/i40e_ethdev.c +9 -5
@@ -4935,6 +4935,7 @@ i40e_res_pool_free(struct i40e_res_pool_info *pool, {struct pool_entry *entry, *next, *prev, *valid_entry =NULL ;uint32_t pool_offset; +uint16_t len;int insert;if (pool ==NULL ) {
@@ -4973,12 +4974,13 @@ 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 */ -if (valid_entry->base + valid_entry->len == next->base) { +if (valid_entry->base + len == next->base) { next->base = valid_entry->base; - next->len += valid_entry->len; + next->len += len;rte_free (valid_entry); valid_entry = next; insert =1 ;
@@ -4988,13 +4990,15 @@ i40e_res_pool_free(struct i40e_res_pool_info *pool,if (prev !=NULL ) {/* Merge with previous one */ if (prev->base + prev->len == valid_entry->base) { - prev->len += valid_entry->len; + prev->len += len;/* If it merge with next one, remove next node */ 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 ; }
Signature · 1 line
2.19.1
Re: [dpdk-dev] [PATCH v5] net/i40e: fix the core dump risk of wild pointer operation
Quoted 74 lines · Wei Zhao
In i40e PMD code of function
i40e_res_pool_free(), ifvalid_entryis 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.Fixes 4861cde46116 ("i40e: new poll mode driver")Signed-off-by Wei Zhao <[email protected]>---
v2:
update commit logv3:
set free pointer to NULLv4:
change code stylev5:
fix an issue in v4--- drivers/net/i40e/i40e_ethdev.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)drivers/net/i40e/i40e_ethdev.c +7
-3@@ -4935,6 +4935,7 @@ i40e_res_pool_free(struct i40e_res_pool_info *pool, {struct pool_entry *entry, *next, *prev, *valid_entry =NULL ;uint32_t pool_offset; +uint16_t len;int insert;if (pool ==NULL ) {@@ -4973,12 +4974,13 @@ 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 */ -if (valid_entry->base + valid_entry->len == next->base) { +if (valid_entry->base + len == next->base) { next->base = valid_entry->base; - next->len += valid_entry->len; + next->len += len;rte_free (valid_entry); valid_entry = next; insert =1 ;@@ -4988,13 +4990,15 @@ i40e_res_pool_free(struct i40e_res_pool_info *pool,if (prev !=NULL ) {/* Merge with previous one */ if (prev->base + prev->len == valid_entry->base) { - prev->len += valid_entry->len; + prev->len += len;/* If it merge with next one, remove next node */ 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 ; } }
drivers/net/i40e/i40e_ethdev.c i40e_res_pool_free(struct i40e_res_pool_info *pool, · line 5021
Quoted 10 lines
drivers/net/i40e/i40e_ethdev.c +2
-2@@ -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 ; }
Re: [dpdk-dev] [PATCH v5] net/i40e: fix the core dump risk of wild pointer operation
In reply to Wei ZhaoQuoted 87 lines · Wei Zhao
In i40e PMD code of function
i40e_res_pool_free(), ifvalid_entryis 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.Fixes 4861cde46116 ("i40e: new poll mode driver")Signed-off-by Wei Zhao <[email protected]>---
v2:
update commit logv3:
set free pointer to NULLv4:
change code stylev5:
fix an issue in v4
---drivers/net/i40e/i40e_ethdev.c| 14 +++++++++-----1 file changed, 9 insertions(+), 5 deletions(-)drivers/net/i40e/i40e_ethdev.c +9
-5@@ -4935,6 +4935,7 @@ i40e_res_pool_free(struct i40e_res_pool_info *pool, {struct pool_entry *entry, *next, *prev, *valid_entry =NULL ;uint32_t pool_offset; +uint16_t len;int insert;if (pool ==NULL ) {@@ -4973,12 +4974,13 @@ 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 */ -if (valid_entry->base + valid_entry->len == next->base) { +if (valid_entry->base + len == next->base) { next->base = valid_entry->base; - next->len += valid_entry->len; + next->len += len;rte_free (valid_entry); valid_entry = next; insert =1 ;@@ -4988,13 +4990,15 @@ i40e_res_pool_free(struct i40e_res_pool_info *pool,if (prev !=NULL ) {/* Merge with previous one */ if (prev->base + prev->len == valid_entry->base) { - prev->len += valid_entry->len; + prev->len += len;/* If it merge with next one, remove next node */ 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 ; }Signature · 1 line
2.19.1
Applied to dpdk-next-net-intel, Thanks.