Skip to contentSkip to conversation

net/nfb: fix use after free

PATCH In review Thomas Monjalon 3 participants 4 messages Oct 10, 2024 – Oct 11, 2024 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/nfb: fix use after free

With the annotations added to the allocation functions, more issues are detected at compilation time:

nfb_rx.c:133:28: error: pointer 'rxq' used after 'rte_free'

It is fixed by moving the assignment before freeing the parent pointer.

Fixes 80da7efbb4c4 ("eal: annotate allocation functions")
---
 drivers/net/nfb/nfb_rx.c | 2 +-
 drivers/net/nfb/nfb_tx.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/nfb/nfb_rx.c +1 -1
index f72afafe8f..462bc3b50d 100644
@@ -129,7 +129,7 @@ nfb_eth_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
 
 	if (rxq->queue != NULL) {
 		ndp_close_rx_queue(rxq->queue);
-		rte_free(rxq);
 		rxq->queue = NULL;
+		rte_free(rxq);
 	}
 }
drivers/net/nfb/nfb_tx.c +1 -1
index a1318a4205..cf99268c43 100644
@@ -108,7 +108,7 @@ nfb_eth_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
 
 	if (txq->queue != NULL) {
 		ndp_close_tx_queue(txq->queue);
-		rte_free(txq);
 		txq->queue = NULL;
+		rte_free(txq);
 	}
 }
Signature · 1 line
2.46.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Thomas Monjalon

With the annotations added to the allocation functions, more issues are detected at compilation time:

nfb_rx.c:133:28: error: pointer 'rxq' used after 'rte_free'

It is fixed by moving the assignment before freeing the parent pointer.

Fixes 80da7efbb4c4 ("eal: annotate allocation functions")
Signature · 1 line
David Marchand
author Applied
#2 lore raw

10/10/2024 19:17, David Marchand:

Quoted 10 lines · Thomas Monjalon
Quoted 9 lines

With the annotations added to the allocation functions, more issues are detected at compilation time:

nfb_rx.c:133:28: error: pointer 'rxq' used after 'rte_free'

It is fixed by moving the assignment before freeing the parent pointer.

Fixes 80da7efbb4c4 ("eal: annotate allocation functions")

The real cause is:

Fixes 6435f9a0ac22 ("net/nfb: add new netcope driver")
Quoted 2 lines
Quoted 1 line

Applied to fix compilation on the main branch.

#3 lore raw
In reply to David Marchand
Quoted 5 lines · David Marchand
Quoted 4 lines · Thomas Monjalon

With the annotations added to the allocation functions, more issues are detected at compilation time:

Quoted 10 lines
Quoted 7 lines

nfb_rx.c:133:28: error: pointer 'rxq' used after 'rte_free'

It is fixed by moving the assignment before freeing the parent pointer.

Fixes 80da7efbb4c4 ("eal: annotate allocation functions")