patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] ring: fix use after free in ring release
@ 2023-04-17 13:11 Yunjian Wang
  2023-04-18 23:53 ` Honnappa Nagarahalli
  2023-04-20  6:43 ` [dpdk-dev] [PATCH v2] " Yunjian Wang
  0 siblings, 2 replies; 16+ messages in thread
From: Yunjian Wang @ 2023-04-17 13:11 UTC (permalink / raw)
  To: dev
  Cc: honnappa.nagarahalli, konstantin.v.ananyev, luyicai,
	Yunjian Wang, stable

When using the ring to find out tailq entry, however it had been
freed by rte_memzone_free function. This change prevents that
from happening.

Fixes: 4e32101f9b01 ("ring: support freeing")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 lib/ring/rte_ring.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/lib/ring/rte_ring.c b/lib/ring/rte_ring.c
index 8ed455043d..17d2d7f8a8 100644
--- a/lib/ring/rte_ring.c
+++ b/lib/ring/rte_ring.c
@@ -333,11 +333,6 @@ rte_ring_free(struct rte_ring *r)
 		return;
 	}
 
-	if (rte_memzone_free(r->memzone) != 0) {
-		RTE_LOG(ERR, RING, "Cannot free memory\n");
-		return;
-	}
-
 	ring_list = RTE_TAILQ_CAST(rte_ring_tailq.head, rte_ring_list);
 	rte_mcfg_tailq_write_lock();
 
@@ -349,7 +344,7 @@ rte_ring_free(struct rte_ring *r)
 
 	if (te == NULL) {
 		rte_mcfg_tailq_write_unlock();
-		return;
+		goto free_memzone;
 	}
 
 	TAILQ_REMOVE(ring_list, te, next);
@@ -357,6 +352,10 @@ rte_ring_free(struct rte_ring *r)
 	rte_mcfg_tailq_write_unlock();
 
 	rte_free(te);
+
+free_memzone:
+	if (rte_memzone_free(r->memzone) != 0)
+		RTE_LOG(ERR, RING, "Cannot free memory\n");
 }
 
 /* dump the status of the ring on the console */
-- 
2.33.0


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-05-23 10:16 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-17 13:11 [dpdk-dev] [PATCH] ring: fix use after free in ring release Yunjian Wang
2023-04-18 23:53 ` Honnappa Nagarahalli
2023-04-19  7:08   ` wangyunjian
2023-04-19 21:44     ` Honnappa Nagarahalli
2023-04-20  6:48       ` wangyunjian
2023-04-20  6:43 ` [dpdk-dev] [PATCH v2] " Yunjian Wang
2023-04-20 16:56   ` Honnappa Nagarahalli
2023-05-01 12:32   ` Konstantin Ananyev
2023-05-01 19:06     ` Honnappa Nagarahalli
2023-05-02 23:06       ` Konstantin Ananyev
2023-05-03  5:44         ` Honnappa Nagarahalli
2023-05-03 22:32           ` Konstantin Ananyev
2023-05-03 23:45             ` Honnappa Nagarahalli
2023-05-05  1:26               ` wangyunjian
2023-05-05  6:48   ` [dpdk-dev] [PATCH v3] " Yunjian Wang
2023-05-23 10:16     ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).