Skip to contentSkip to conversation

net/cxgbe: fix use-after-free in control queue teardown

PATCH David Marchand 2 participants 2 messages Sep 2 – Sep 25 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 11 lines · B T Dhanush

t4_free_sge_resources() frees ctrl Tx queue and firmware event queue DMA memzones using adapter->eth_dev, read at teardown time. This runs only once, when the last port on the adapter closes.

rte_eth_dev_close() frees a port's eth_dev->data right after that port's own dev_close() returns, regardless of other ports' state. If port 0 is not the last port closed, adapter->eth_dev->data is already freed by the time t4_free_sge_resources() runs, causing a NULL pointer dereference in rte_eth_dma_zone_free() and a crash on exit.

Quoted 5 lines

Fix by not dereferencing eth_dev at teardown. Store the port_id used for each queue's memzone name at allocation time instead, and free each memzone directly via rte_memzone_lookup()/rte_memzone_free().

Fixes 36c46e738120 ("ethdev: cleanup shared data with the last port")

This commit may have made the bug more visible but I doubt this is the reason for the reported issue.

Quoted 4 lines

I don't understand the issue for now.
Something looks wrong in the driver, and the description above.

The adapter object seems to embed shared resources across multiple eth_dev objects, is that correct?
If so, any function taking only a adapter pointer as input can only deal with the first port related.

This is probably the reported crash and then I would point at:

Fixes 6b78a629954c ("net/cxgbe: fix queue DMA ring leaks during port close").

Which releases only the first port DMA resources even for another port.

If those DMA resources are shared, the driver should not use rte_eth_dma_zone_reserve() and this driver should come with its own helper.

But otherwise, if each eth_dev object has its DMA resources (which seems more likely to me), then my suggestion is to pass a eth_dev object to the related functions.
And a followup cleanup would be to remove the back reference to the first eth_dev in the adapter object which I find really confusing and could be a source of bugs.

Signature · 1 line
David Marchand
#2 lore raw
Quoted 16 lines

I don't understand the issue for now.
Something looks wrong in the driver, and the description above.

The adapter object seems to embed shared resources across multiple eth_dev objects, is that correct?
If so, any function taking only a adapter pointer as input can only deal with the first port related.

This is probably the reported crash and then I would point at:

Fixes 6b78a629954c ("net/cxgbe: fix queue DMA ring leaks during port close").

Which releases only the first port DMA resources even for another port.

If those DMA resources are shared, the driver should not use rte_eth_dma_zone_reserve() and this driver should come with its own helper.

Quoted 6 lines

But otherwise, if each eth_dev object has its DMA resources (which seems more likely to me), then my suggestion is to pass a eth_dev object to the related functions.
And a followup cleanup would be to remove the back reference to the first eth_dev in the adapter object which I find really confusing and could be a source of bugs.

Thanks for your review, I am working on the v2 based on your suggestions.

________________________________
From: David Marchand <[email protected]>
Sent: Wednesday, September 2, 2026 5:25 PM
To: Dhanush BT. <[email protected]>
Cc: [email protected] <[email protected]>; Potnuri Bharat Teja <[email protected]>; [email protected] <[email protected]>
Subject: Re: [PATCH] net/cxgbe: fix use-after-free in control queue teardown

Quoted 11 lines · B T Dhanush

t4_free_sge_resources() frees ctrl Tx queue and firmware event queue DMA memzones using adapter->eth_dev, read at teardown time. This runs only once, when the last port on the adapter closes.

rte_eth_dev_close() frees a port's eth_dev->data right after that port's own dev_close() returns, regardless of other ports' state. If port 0 is not the last port closed, adapter->eth_dev->data is already freed by the time t4_free_sge_resources() runs, causing a NULL pointer dereference in rte_eth_dma_zone_free() and a crash on exit.

Quoted 5 lines

Fix by not dereferencing eth_dev at teardown. Store the port_id used for each queue's memzone name at allocation time instead, and free each memzone directly via rte_memzone_lookup()/rte_memzone_free().

Fixes 36c46e738120 ("ethdev: cleanup shared data with the last port")

This commit may have made the bug more visible but I doubt this is the reason for the reported issue.

Quoted 4 lines

I don't understand the issue for now.
Something looks wrong in the driver, and the description above.

The adapter object seems to embed shared resources across multiple eth_dev objects, is that correct?
If so, any function taking only a adapter pointer as input can only deal with the first port related.

This is probably the reported crash and then I would point at:

Fixes 6b78a629954c ("net/cxgbe: fix queue DMA ring leaks during port close").

Which releases only the first port DMA resources even for another port.

If those DMA resources are shared, the driver should not use rte_eth_dma_zone_reserve() and this driver should come with its own helper.

But otherwise, if each eth_dev object has its DMA resources (which seems more likely to me), then my suggestion is to pass a eth_dev object to the related functions.
And a followup cleanup would be to remove the back reference to the first eth_dev in the adapter object which I find really confusing and could be a source of bugs.

--
David Marchand