netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net/smc: fix a memory leak in smc_sysctl_net_exit()
@ 2022-03-25 16:50 Eric Dumazet
  2022-03-26 21:20 ` patchwork-bot+netdevbpf
  2022-03-28  1:58 ` Tony Lu
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2022-03-25 16:50 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: netdev, Eric Dumazet, Eric Dumazet, syzbot, Tony Lu, Dust Li

From: Eric Dumazet <edumazet@google.com>

Recently added smc_sysctl_net_exit() forgot to free
the memory allocated from smc_sysctl_net_init()
for non initial network namespace.

Fixes: 462791bbfa35 ("net/smc: add sysctl interface for SMC")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Cc: Tony Lu <tonylu@linux.alibaba.com>
Cc: Dust Li <dust.li@linux.alibaba.com>
---
 net/smc/smc_sysctl.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net/smc/smc_sysctl.c b/net/smc/smc_sysctl.c
index bae19419e7553222d74c2ae178fd5a2b6116679b..cf3ab1334c009a1a0539b2c228c4503ae391d89b 100644
--- a/net/smc/smc_sysctl.c
+++ b/net/smc/smc_sysctl.c
@@ -61,5 +61,10 @@ int __net_init smc_sysctl_net_init(struct net *net)
 
 void __net_exit smc_sysctl_net_exit(struct net *net)
 {
+	struct ctl_table *table;
+
+	table = net->smc.smc_hdr->ctl_table_arg;
 	unregister_net_sysctl_table(net->smc.smc_hdr);
+	if (!net_eq(net, &init_net))
+		kfree(table);
 }
-- 
2.35.1.1021.g381101b075-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net/smc: fix a memory leak in smc_sysctl_net_exit()
  2022-03-25 16:50 [PATCH net] net/smc: fix a memory leak in smc_sysctl_net_exit() Eric Dumazet
@ 2022-03-26 21:20 ` patchwork-bot+netdevbpf
  2022-03-28  1:58 ` Tony Lu
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-03-26 21:20 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: davem, kuba, pabeni, netdev, edumazet, syzkaller, tonylu, dust.li

Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

On Fri, 25 Mar 2022 09:50:21 -0700 you wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> Recently added smc_sysctl_net_exit() forgot to free
> the memory allocated from smc_sysctl_net_init()
> for non initial network namespace.
> 
> Fixes: 462791bbfa35 ("net/smc: add sysctl interface for SMC")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Reported-by: syzbot <syzkaller@googlegroups.com>
> Cc: Tony Lu <tonylu@linux.alibaba.com>
> Cc: Dust Li <dust.li@linux.alibaba.com>
> 
> [...]

Here is the summary with links:
  - [net] net/smc: fix a memory leak in smc_sysctl_net_exit()
    https://git.kernel.org/netdev/net/c/5ae6acf1d00b

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] 3+ messages in thread

* Re: [PATCH net] net/smc: fix a memory leak in smc_sysctl_net_exit()
  2022-03-25 16:50 [PATCH net] net/smc: fix a memory leak in smc_sysctl_net_exit() Eric Dumazet
  2022-03-26 21:20 ` patchwork-bot+netdevbpf
@ 2022-03-28  1:58 ` Tony Lu
  1 sibling, 0 replies; 3+ messages in thread
From: Tony Lu @ 2022-03-28  1:58 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, netdev,
	Eric Dumazet, syzbot, Dust Li

On Fri, Mar 25, 2022 at 09:50:21AM -0700, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> Recently added smc_sysctl_net_exit() forgot to free
> the memory allocated from smc_sysctl_net_init()
> for non initial network namespace.
> 
> Fixes: 462791bbfa35 ("net/smc: add sysctl interface for SMC")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Reported-by: syzbot <syzkaller@googlegroups.com>
> Cc: Tony Lu <tonylu@linux.alibaba.com>
> Cc: Dust Li <dust.li@linux.alibaba.com>
> ---
>  net/smc/smc_sysctl.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/net/smc/smc_sysctl.c b/net/smc/smc_sysctl.c
> index bae19419e7553222d74c2ae178fd5a2b6116679b..cf3ab1334c009a1a0539b2c228c4503ae391d89b 100644
> --- a/net/smc/smc_sysctl.c
> +++ b/net/smc/smc_sysctl.c
> @@ -61,5 +61,10 @@ int __net_init smc_sysctl_net_init(struct net *net)
>  
>  void __net_exit smc_sysctl_net_exit(struct net *net)
>  {
> +	struct ctl_table *table;
> +
> +	table = net->smc.smc_hdr->ctl_table_arg;
>  	unregister_net_sysctl_table(net->smc.smc_hdr);
> +	if (!net_eq(net, &init_net))
> +		kfree(table);
>  }

Thanks a lot for fixing this issue, this is my fault.

Tony Lu

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-28  1:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-25 16:50 [PATCH net] net/smc: fix a memory leak in smc_sysctl_net_exit() Eric Dumazet
2022-03-26 21:20 ` patchwork-bot+netdevbpf
2022-03-28  1:58 ` Tony Lu

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).