net: ngbe: fix memory leak in ngbe_probe() error path
Subsystems (3)
PATCH v2 1/1 net: ngbe: fix memory leak in ngbe_probe() error path
When ngbe_sw_init() is called, memory is allocated for wx->rss_key in wx_init_rss_key(). However, in ngbe_probe() function, the subsequent error paths after ngbe_sw_init() don't free the rss_key. Fix that by freeing it in error path along with wx->mac_table.
Also change the label to which execution jumps when ngbe_sw_init() fails, because otherwise, it could lead to a double free for rss_key, when the mac_table allocation fails in wx_sw_init().
---
v1 -> v2:
- Add fixes tag, as suggested by Markus and Jakub.
- Also set the branch target as net instead of net-next as it is a fix
v1 link: https://lore.kernel.org/all/[email protected]
drivers/net/ethernet/wangxun/ngbe/ngbe_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/wangxun/ngbe/ngbe_main.c +2 -1
@@ -625,7 +625,7 @@ static int ngbe_probe(struct pci_dev *pdev,/* setup the private structure */ err =ngbe_sw_init (wx);if (err) - goto err_free_mac_table; + goto err_pci_release_regions;/* check if flash load is done after hw power up */ err =wx_check_flash_load (wx,NGBE_SPI_ILDR_STATUS_PERST );
@@ -719,6 +719,7 @@ static int ngbe_probe(struct pci_dev *pdev, err_clear_interrupt_scheme:wx_clear_interrupt_scheme (wx); err_free_mac_table: +kfree (wx->rss_key);kfree (wx->mac_table); err_pci_release_regions: pci_release_selected_regions(pdev,
Signature · 1 line
2.47.2
Quoted 11 lines · On Sat, 12 Apr 2025 21:19:24 +0530 Abdun Nihaal <[email protected]> wrote:
When
ngbe_sw_init()is called, memory is allocated forwx->rss_keyinwx_init_rss_key(). However, inngbe_probe()function, the subsequent error paths afterngbe_sw_init()don't free therss_key. Fix that by freeing it in error path along withwx->mac_table.Also change the label to which execution jumps when
ngbe_sw_init()fails, because otherwise, it could lead to a double free forrss_key, when themac_tableallocation fails inwx_sw_init().Fixes 02338c484ab6 ("net: ngbe: Initialize sw info and register netdev")Signed-off-by Abdun Nihaal <[email protected]>
legit!
Thank you!
Signature · 3 lines
Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Quoted 43 lines · Abdun Nihaal
When
ngbe_sw_init()is called, memory is allocated forwx->rss_keyinwx_init_rss_key(). However, inngbe_probe()function, the subsequent error paths afterngbe_sw_init()don't free therss_key. Fix that by freeing it in error path along withwx->mac_table.Also change the label to which execution jumps when
ngbe_sw_init()fails, because otherwise, it could lead to a double free forrss_key, when themac_tableallocation fails inwx_sw_init().Fixes 02338c484ab6 ("net: ngbe: Initialize sw info and register netdev")Signed-off-by Abdun Nihaal <[email protected]>---
v1 -> v2:
- Add fixes tag, as suggested by Markus and Jakub.
- Also set the branch target as net instead of net-next as it is a fixv1 link: https://lore.kernel.org/all/[email protected]
drivers/net/ethernet/wangxun/ngbe/ngbe_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/net/ethernet/wangxun/ngbe/ngbe_main.c +2
-2@@ -625,7 +625,7 @@ static int ngbe_probe(struct pci_dev *pdev,/* setup the private structure */ err =ngbe_sw_init (wx);if (err) - goto err_free_mac_table; + goto err_pci_release_regions;/* check if flash load is done after hw power up */ err =wx_check_flash_load (wx,NGBE_SPI_ILDR_STATUS_PERST );@@ -719,6 +719,7 @@ static int ngbe_probe(struct pci_dev *pdev, err_clear_interrupt_scheme:wx_clear_interrupt_scheme (wx); err_free_mac_table: +kfree (wx->rss_key);kfree (wx->mac_table); err_pci_release_regions: pci_release_selected_regions(pdev, --
Quoted 2 lines
2.47.2
Thanks Abdun,
I think this release bug is also present in txgbe driver.
Quoted 1 line · Jiawen Wu
I think this release bug is also present in txgbe driver.
Thanks for the info. I just sent a patch to fix that here :
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Regards,
Nihaal
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 10 lines · On Sat, 12 Apr 2025 21:19:24 +0530 you wrote:
When
ngbe_sw_init()is called, memory is allocated forwx->rss_keyinwx_init_rss_key(). However, inngbe_probe()function, the subsequent error paths afterngbe_sw_init()don't free therss_key. Fix that by freeing it in error path along withwx->mac_table.Also change the label to which execution jumps when
ngbe_sw_init()fails, because otherwise, it could lead to a double free forrss_key, when themac_tableallocation fails inwx_sw_init().[...]
Here is the summary with links:
- [v2,net] net: ngbe: fix memory leak in ngbe_probe() error path
https://git.kernel.org/netdev/net/c/88fa80021b77
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html