Skip to contentSkip to conversation

net/smc: fix a memory leak in smc_sysctl_net_exit()

PATCH Applied Eric Dumazet 3 participants 3 messages Mar 25, 2022 – Mar 28, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/smc: fix a memory leak in smc_sysctl_net_exit()

From: Eric Dumazet <[email protected]>

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")
Cc Tony Lu <[email protected]>
Cc Dust Li <[email protected]>
---
 net/smc/smc_sysctl.c | 5 +++++
 1 file changed, 5 insertions(+)
net/smc/smc_sysctl.c +5 -0
index bae19419e7553222d74c2ae178fd5a2b6116679b..cf3ab1334c009a1a0539b2c228c4503ae391d89b 100644
@@ -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);
 }
Signature · 1 line
2.35.1.1021.g381101b075-goog
#1 lore raw
This patch was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <[email protected]>:

Quoted 6 lines · On Fri, 25 Mar 2022 09:50:21 -0700 you wrote:

From: Eric Dumazet <[email protected]>

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

Quoted 7 lines
Fixes 462791bbfa35 ("net/smc: add sysctl interface for SMC")
Cc Tony Lu <[email protected]>
Cc Dust Li <[email protected]>

[...]

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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
reviewer
#2 lore raw
In reply to Eric Dumazet
Quoted 20 lines · Eric Dumazet

From: Eric Dumazet <[email protected]>

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")
Cc Tony Lu <[email protected]>
Cc Dust Li <[email protected]>
---
 net/smc/smc_sysctl.c | 5 +++++
 1 file changed, 5 insertions(+)
net/smc/smc_sysctl.c +0 -0
index bae19419e7553222d74c2ae178fd5a2b6116679b..cf3ab1334c009a1a0539b2c228c4503ae391d89b 100644

net/smc/smc_sysctl.c int __net_init smc_sysctl_net_init(struct net *net) · line 70

Quoted 10 lines
net/smc/smc_sysctl.c +5 -0
@@ -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