net: mvneta: fix potential double-frees in mvneta_txq_sw_deinit()
Subsystems (3)
PATCH 1/1 net: mvneta: fix potential double-frees in mvneta_txq_sw_deinit()
Reported on the Turris forum, mvneta provokes kernel warnings in the architecture DMA mapping code when mvneta_setup_txqs() fails to allocate memory. This happens because when mvneta_cleanup_txqs() is called in the mvneta_stop() path, we leave pointers in the structure that have been freed.
Then on mvneta_open(), we call mvneta_setup_txqs(), which starts allocating memory. On memory allocation failure, mvneta_cleanup_txqs() will walk all the queues freeing any non-NULL pointers - which includes pointers that were previously freed in mvneta_stop().
Fix this by setting these pointers to NULL to prevent double-freeing of the same memory.
--- drivers/net/ethernet/marvell/mvneta.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/marvell/mvneta.c +2 -0
@@ -3549,6 +3549,8 @@ static void mvneta_txq_sw_deinit(struct mvneta_port *pp,netdev_tx_reset_queue (nq); + txq->buf =NULL ; + txq->tso_hdrs =NULL ; txq->descs =NULL ; txq->last_desc =0 ; txq->next_desc_to_proc =0 ;
Signature · 1 line
2.30.2
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 6 lines · On Wed, 29 Mar 2023 13:11:17 +0100 you wrote:
Reported on the Turris forum, mvneta provokes kernel warnings in the architecture DMA mapping code when
mvneta_setup_txqs()fails to allocate memory. This happens because whenmvneta_cleanup_txqs()is called in themvneta_stop()path, we leave pointers in the structure that have been freed.
Quoted 6 lines
Then on
mvneta_open(), we callmvneta_setup_txqs(), which starts allocating memory. On memory allocation failure,mvneta_cleanup_txqs()will walk all the queues freeing any non-NULL pointers - which includes pointers that were previously freed inmvneta_stop().[...]
Here is the summary with links:
- [net] net: mvneta: fix potential double-frees in mvneta_txq_sw_deinit()
https://git.kernel.org/netdev/net/c/2960a2d33b02
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html