Skip to contentSkip to conversation

net/i40e: fix the security risk of wild pointer operation

PATCH Superseded Wei Zhao 3 participants 12 messages May 12, 2020 – May 19, 2020 Network drivers

lore
Share & tools
lore

Wei Zhao

author
#0 lore raw

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.

Fixes 4861cde46116 ("i40e: new poll mode driver")
---
 drivers/net/i40e/i40e_ethdev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/i40e/i40e_ethdev.c +3 -3
index 749d85f54..7f8ea5309 100644
@@ -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
author
#1 lore raw

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 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.

Fixes 4861cde46116 ("i40e: new poll mode driver")
---
 drivers/net/i40e/i40e_ethdev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/i40e/i40e_ethdev.c +3 -0
index 749d85f54..7f8ea5309 100644
@@ -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

#2 lore raw
In reply to Wei Zhao

hi, zhaowei

Quoted 36 lines · Wei Zhao

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.

Fixes 4861cde46116 ("i40e: new poll mode driver")
---
  drivers/net/i40e/i40e_ethdev.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/i40e/i40e_ethdev.c +0 -0
index 749d85f54..7f8ea5309 100644

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;
  }
 
#3 lore raw
Quoted 49 lines · Jeff Guo

hi, zhaowei

Quoted 36 lines · Wei Zhao

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.

Fixes 4861cde46116 ("i40e: new poll mode driver")
---
  drivers/net/i40e/i40e_ethdev.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/i40e/i40e_ethdev.c +0 -0
index 749d85f54..7f8ea5309 100644

drivers/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_list updated by "LIST_INSERT_HEAD(&pool->free_list, valid_entry, next)"?

Quoted 2 lines

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

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;
  }
author
#4 lore raw

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 operation

Quoted 34 lines · Jeff Guo

hi, zhaowei

Quoted 31 lines · Wei Zhao

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.

Fixes 4861cde46116 ("i40e: new poll mode driver")
---
  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.c index 749d85f54..7f8ea5309 100644

drivers/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_list updated by "LIST_INSERT_HEAD(&pool->free_list, valid_entry, next)"?

Quoted 2 lines

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.

Quoted 6 lines

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.

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 -3
  			LIST_INSERT_HEAD(&pool->free_list, valid_entry, next);
  	}
-	pool->num_free += valid_entry->len;
-	pool->num_alloc -= valid_entry->len;
-
  	return 0;
  }
#5 lore raw

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 operation

Quoted 34 lines · Jeff Guo

hi, zhaowei

Quoted 31 lines · Wei Zhao

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.

Fixes 4861cde46116 ("i40e: new poll mode driver")
---
  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.c index 749d85f54..7f8ea5309 100644

drivers/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_list updated by "LIST_INSERT_HEAD(&pool->free_list, valid_entry, next)"?

Quoted 2 lines

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.

Quoted 5 lines
Quoted 2 lines

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

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 -3
  LIST_INSERT_HEAD(&pool->free_list, valid_entry, next);
  }
-pool->num_free += valid_entry->len;
-pool->num_alloc -= valid_entry->len;
-
  return 0;
  }
author
#6 lore raw

PATCH v2 1/1 net/i40e: fix the core dump risk of wild pointer operation

In reply to Wei Zhao

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.

Fixes 4861cde46116 ("i40e: new poll mode driver")

---

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
index 91dcd0ebf..09c2efef8 100644
@@ -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
author
#7 lore raw

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.

Fixes 4861cde46116 ("i40e: new poll mode driver")

---

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
index 749d85f54..c9601d683 100644
@@ -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
author
#8 lore raw

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.

Fixes 4861cde46116 ("i40e: new poll mode driver")

---

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
index 749d85f54..679d59e5d 100644
@@ -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
author
#9 lore raw

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.

Fixes 4861cde46116 ("i40e: new poll mode driver")

---

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
index 749d85f54..00bb05179 100644
@@ -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
Reviewed-by on v5 1/1
#10 lore raw

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(), 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.

Fixes 4861cde46116 ("i40e: new poll mode driver")

---

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 +7 -3
index 749d85f54..00bb05179 100644
@@ -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;
  }
Reviewed-by on v5 1/1 Applied
#11 lore raw

Re: [dpdk-dev] [PATCH v5] net/i40e: fix the core dump risk of wild pointer operation

In reply to Wei Zhao
Quoted 87 lines · Wei Zhao

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.

Fixes 4861cde46116 ("i40e: new poll mode driver")

---

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
index 749d85f54..00bb05179 100644
@@ -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.