* [PATCH net] net: stmmac: selftests: fix potential memleak in stmmac_test_arpoffload()
@ 2022-12-07 8:31 Zhang Changzhong
2022-12-07 9:12 ` Leon Romanovsky
2022-12-09 11:00 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 5+ messages in thread
From: Zhang Changzhong @ 2022-12-07 8:31 UTC (permalink / raw)
To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Maxime Coquelin
Cc: Zhang Changzhong, netdev, linux-kernel
The skb allocated by stmmac_test_get_arp_skb() hasn't been released in
some error handling case, which will lead to a memory leak. Fix this up
by adding kfree_skb() to release skb.
Compile tested only.
Fixes: 5e3fb0a6e2b3 ("net: stmmac: selftests: Implement the ARP Offload test")
Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index 49af7e7..687f43c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -1654,12 +1654,16 @@ static int stmmac_test_arpoffload(struct stmmac_priv *priv)
}
ret = stmmac_set_arp_offload(priv, priv->hw, true, ip_addr);
- if (ret)
+ if (ret) {
+ kfree_skb(skb);
goto cleanup;
+ }
ret = dev_set_promiscuity(priv->dev, 1);
- if (ret)
+ if (ret) {
+ kfree_skb(skb);
goto cleanup;
+ }
ret = dev_direct_xmit(skb, 0);
if (ret)
--
2.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH net] net: stmmac: selftests: fix potential memleak in stmmac_test_arpoffload() 2022-12-07 8:31 [PATCH net] net: stmmac: selftests: fix potential memleak in stmmac_test_arpoffload() Zhang Changzhong @ 2022-12-07 9:12 ` Leon Romanovsky 2022-12-07 10:07 ` Zhang Changzhong 2022-12-09 11:00 ` patchwork-bot+netdevbpf 1 sibling, 1 reply; 5+ messages in thread From: Leon Romanovsky @ 2022-12-07 9:12 UTC (permalink / raw) To: Zhang Changzhong Cc: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Maxime Coquelin, netdev, linux-kernel On Wed, Dec 07, 2022 at 04:31:59PM +0800, Zhang Changzhong wrote: > The skb allocated by stmmac_test_get_arp_skb() hasn't been released in > some error handling case, which will lead to a memory leak. Fix this up > by adding kfree_skb() to release skb. > > Compile tested only. > > Fixes: 5e3fb0a6e2b3 ("net: stmmac: selftests: Implement the ARP Offload test") > Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com> > --- > drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c > index 49af7e7..687f43c 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c > @@ -1654,12 +1654,16 @@ static int stmmac_test_arpoffload(struct stmmac_priv *priv) > } > > ret = stmmac_set_arp_offload(priv, priv->hw, true, ip_addr); > - if (ret) > + if (ret) { > + kfree_skb(skb); > goto cleanup; > + } > > ret = dev_set_promiscuity(priv->dev, 1); > - if (ret) > + if (ret) { > + kfree_skb(skb); > goto cleanup; > + } > > ret = dev_direct_xmit(skb, 0); > if (ret) You should release skb here too. So the better patch will be to write something like that: cleanup: stmmac_set_arp_offload(priv, priv->hw, false, 0x0); if (ret) kfree_skb(skb); Thanks > -- > 2.9.5 > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] net: stmmac: selftests: fix potential memleak in stmmac_test_arpoffload() 2022-12-07 9:12 ` Leon Romanovsky @ 2022-12-07 10:07 ` Zhang Changzhong 2022-12-08 8:29 ` Leon Romanovsky 0 siblings, 1 reply; 5+ messages in thread From: Zhang Changzhong @ 2022-12-07 10:07 UTC (permalink / raw) To: Leon Romanovsky Cc: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Maxime Coquelin, netdev, linux-kernel On 2022/12/7 17:12, Leon Romanovsky wrote: > On Wed, Dec 07, 2022 at 04:31:59PM +0800, Zhang Changzhong wrote: >> The skb allocated by stmmac_test_get_arp_skb() hasn't been released in >> some error handling case, which will lead to a memory leak. Fix this up >> by adding kfree_skb() to release skb. >> >> Compile tested only. >> >> Fixes: 5e3fb0a6e2b3 ("net: stmmac: selftests: Implement the ARP Offload test") >> Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com> >> --- >> drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 8 ++++++-- >> 1 file changed, 6 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c >> index 49af7e7..687f43c 100644 >> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c >> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c >> @@ -1654,12 +1654,16 @@ static int stmmac_test_arpoffload(struct stmmac_priv *priv) >> } >> >> ret = stmmac_set_arp_offload(priv, priv->hw, true, ip_addr); >> - if (ret) >> + if (ret) { >> + kfree_skb(skb); >> goto cleanup; >> + } >> >> ret = dev_set_promiscuity(priv->dev, 1); >> - if (ret) >> + if (ret) { >> + kfree_skb(skb); >> goto cleanup; >> + } >> >> ret = dev_direct_xmit(skb, 0); >> if (ret) > > You should release skb here too. So the better patch will be to write > something like that: > Hi Leon, Thanks for your review, but I don't think we need release skb here, because dev_direct_xmit() is responsible for freeing it. Regards, Changzhong > cleanup: > stmmac_set_arp_offload(priv, priv->hw, false, 0x0); > if (ret) > kfree_skb(skb); >> Thanks > >> -- >> 2.9.5 >> > . > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] net: stmmac: selftests: fix potential memleak in stmmac_test_arpoffload() 2022-12-07 10:07 ` Zhang Changzhong @ 2022-12-08 8:29 ` Leon Romanovsky 0 siblings, 0 replies; 5+ messages in thread From: Leon Romanovsky @ 2022-12-08 8:29 UTC (permalink / raw) To: Zhang Changzhong Cc: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Maxime Coquelin, netdev, linux-kernel On Wed, Dec 07, 2022 at 06:07:16PM +0800, Zhang Changzhong wrote: > On 2022/12/7 17:12, Leon Romanovsky wrote: > > On Wed, Dec 07, 2022 at 04:31:59PM +0800, Zhang Changzhong wrote: > >> The skb allocated by stmmac_test_get_arp_skb() hasn't been released in > >> some error handling case, which will lead to a memory leak. Fix this up > >> by adding kfree_skb() to release skb. > >> > >> Compile tested only. > >> > >> Fixes: 5e3fb0a6e2b3 ("net: stmmac: selftests: Implement the ARP Offload test") > >> Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com> > >> --- > >> drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 8 ++++++-- > >> 1 file changed, 6 insertions(+), 2 deletions(-) > >> > >> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c > >> index 49af7e7..687f43c 100644 > >> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c > >> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c > >> @@ -1654,12 +1654,16 @@ static int stmmac_test_arpoffload(struct stmmac_priv *priv) > >> } > >> > >> ret = stmmac_set_arp_offload(priv, priv->hw, true, ip_addr); > >> - if (ret) > >> + if (ret) { > >> + kfree_skb(skb); > >> goto cleanup; > >> + } > >> > >> ret = dev_set_promiscuity(priv->dev, 1); > >> - if (ret) > >> + if (ret) { > >> + kfree_skb(skb); > >> goto cleanup; > >> + } > >> > >> ret = dev_direct_xmit(skb, 0); > >> if (ret) > > > > You should release skb here too. So the better patch will be to write > > something like that: > > > > Hi Leon, > > Thanks for your review, but I don't think we need release skb here, > because dev_direct_xmit() is responsible for freeing it. Interesting, __dev_direct_xmit() releases skb too. Thanks for the clarification. > > Regards, > Changzhong > > > cleanup: > > stmmac_set_arp_offload(priv, priv->hw, false, 0x0); > > if (ret) > > kfree_skb(skb); > >> Thanks > > > >> -- > >> 2.9.5 > >> > > . > > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] net: stmmac: selftests: fix potential memleak in stmmac_test_arpoffload() 2022-12-07 8:31 [PATCH net] net: stmmac: selftests: fix potential memleak in stmmac_test_arpoffload() Zhang Changzhong 2022-12-07 9:12 ` Leon Romanovsky @ 2022-12-09 11:00 ` patchwork-bot+netdevbpf 1 sibling, 0 replies; 5+ messages in thread From: patchwork-bot+netdevbpf @ 2022-12-09 11:00 UTC (permalink / raw) To: Zhang Changzhong Cc: peppe.cavallaro, alexandre.torgue, joabreu, davem, edumazet, kuba, pabeni, mcoquelin.stm32, netdev, linux-kernel Hello: This patch was applied to netdev/net.git (master) by David S. Miller <davem@davemloft.net>: On Wed, 7 Dec 2022 16:31:59 +0800 you wrote: > The skb allocated by stmmac_test_get_arp_skb() hasn't been released in > some error handling case, which will lead to a memory leak. Fix this up > by adding kfree_skb() to release skb. > > Compile tested only. > > Fixes: 5e3fb0a6e2b3 ("net: stmmac: selftests: Implement the ARP Offload test") > Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com> > > [...] Here is the summary with links: - [net] net: stmmac: selftests: fix potential memleak in stmmac_test_arpoffload() https://git.kernel.org/netdev/net/c/f150b63f3fa5 You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-12-09 11:00 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-12-07 8:31 [PATCH net] net: stmmac: selftests: fix potential memleak in stmmac_test_arpoffload() Zhang Changzhong 2022-12-07 9:12 ` Leon Romanovsky 2022-12-07 10:07 ` Zhang Changzhong 2022-12-08 8:29 ` Leon Romanovsky 2022-12-09 11:00 ` patchwork-bot+netdevbpf
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).