ipv4: free net->ipv4.sysctl_local_reserved_ports after unregister_net_sysctl_table()
Subsystems (2)
PATCH 1/1 ipv4: free net->ipv4.sysctl_local_reserved_ports after unregister_net_sysctl_table()
ipv4_sysctl_exit_net() is currently freeing net->ipv4.sysctl_local_reserved_ports too soon.
Only after unregister_net_sysctl_table() we can be sure no threads can possibly use the sysctls, including /proc/sys/net/ipv4/ip_local_reserved_ports.
--- net/ipv4/sysctl_net_ipv4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/sysctl_net_ipv4.c +1 -1
@@ -1705,10 +1705,10 @@ static __net_exit void ipv4_sysctl_exit_net(struct net *net) {const struct ctl_table *table; -kfree (net->ipv4.sysctl_local_reserved_ports); table = net->ipv4.ipv4_hdr->ctl_table_arg;unregister_net_sysctl_table (net->ipv4.ipv4_hdr);kfree (table); +kfree (net->ipv4.sysctl_local_reserved_ports); }static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
Signature · 1 line
2.54.0.669.g59709faab0-goog
Quoted 11 lines · Eric Dumazet
ipv4_sysctl_exit_net()is currently freeingnet->ipv4.sysctl_local_reserved_portstoo soon.Only after
unregister_net_sysctl_table()we can be sure no threads can possibly use the sysctls, including/proc/sys/net/ipv4/ip_local_reserved_ports.Fixes 122ff243f5f1 ("ipv4: make ip_local_reserved_ports per netns")Reported-by Ji'an Zhou <[email protected]>Signed-off-by Eric Dumazet <[email protected]>Cc Cong Wang <[email protected]>
Thanks!
Quoted 20 lines · Eric Dumazet
ipv4_sysctl_exit_net()is currently freeingnet->ipv4.sysctl_local_reserved_portstoo soon.Only after
unregister_net_sysctl_table()we can be sure no threads can possibly use the sysctls, including/proc/sys/net/ipv4/ip_local_reserved_ports.Fixes 122ff243f5f1 ("ipv4: make ip_local_reserved_ports per netns")Reported-by Ji'an Zhou <[email protected]>Signed-off-by Eric Dumazet <[email protected]>Cc Cong Wang <[email protected]>--- net/ipv4/sysctl_net_ipv4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/sysctl_net_ipv4.c +0
-0@@ -1705,10 +1705,10 @@ static __net_exit void ipv4_sysctl_exit_net(struct net *net) {
net/ipv4/sysctl_net_ipv4.c static __net_exit void ipv4_sysctl_exit_net(struct net *net) · line 1714
Quoted 10 lines
net/ipv4/sysctl_net_ipv4.c +1
-1const struct ctl_table *table; -kfree (net->ipv4.sysctl_local_reserved_ports); table = net->ipv4.ipv4_hdr->ctl_table_arg;unregister_net_sysctl_table (net->ipv4.ipv4_hdr);kfree (table); +kfree (net->ipv4.sysctl_local_reserved_ports); }static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
If there are still processes in the namespace, the netns refcnt cannot become 0,
so I think it should be: first open /proc/sys/net/ipv4/ip_local_reserved_ports, then pass
the fd to another process outside the netns? Maybe SCM_RIGHTS is used?
Quoted 38 lines · Jiayuan Chen
Quoted 20 lines · Eric Dumazet
ipv4_sysctl_exit_net()is currently freeingnet->ipv4.sysctl_local_reserved_portstoo soon.Only after
unregister_net_sysctl_table()we can be sure no threads can possibly use the sysctls, including/proc/sys/net/ipv4/ip_local_reserved_ports.Fixes 122ff243f5f1 ("ipv4: make ip_local_reserved_ports per netns")Reported-by Ji'an Zhou <[email protected]>Signed-off-by Eric Dumazet <[email protected]>Cc Cong Wang <[email protected]>--- net/ipv4/sysctl_net_ipv4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/sysctl_net_ipv4.c +0
-0@@ -1705,10 +1705,10 @@ static __net_exit void ipv4_sysctl_exit_net(struct net *net) {net/ipv4/sysctl_net_ipv4.c static __net_exit void ipv4_sysctl_exit_net(struct net *net) · line 1714
Quoted 10 lines
net/ipv4/sysctl_net_ipv4.c +1
-1const struct ctl_table *table; -kfree (net->ipv4.sysctl_local_reserved_ports); table = net->ipv4.ipv4_hdr->ctl_table_arg;unregister_net_sysctl_table (net->ipv4.ipv4_hdr);kfree (table); +kfree (net->ipv4.sysctl_local_reserved_ports); }static __net_initdata struct pernet_operations ipv4_sysctl_ops = {Reviewed-by Jiayuan Chen <[email protected]>
Quoted 7 lines
If there are still processes in the namespace, the netns refcnt cannot become 0,
so I think it should be: first open
/proc/sys/net/ipv4/ip_local_reserved_ports, then passthe fd to another process outside the netns? Maybe
SCM_RIGHTSis used?
We will not share the repro publicly, for obvious reasons :)
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 Thu, 21 May 2026 12:21:47 +0000 you wrote:
ipv4_sysctl_exit_net()is currently freeingnet->ipv4.sysctl_local_reserved_portstoo soon.Only after
unregister_net_sysctl_table()we can be sure no threads can possibly use the sysctls, including/proc/sys/net/ipv4/ip_local_reserved_ports.
Quoted 6 lines
Fixes 122ff243f5f1 ("ipv4: make ip_local_reserved_ports per netns")Reported-by Ji'an Zhou <[email protected]>Signed-off-by Eric Dumazet <[email protected]>Cc Cong Wang <[email protected]>[...]
Here is the summary with links:
- [net] ipv4: free net->ipv4.sysctl_local_reserved_ports after unregister_net_sysctl_table()
https://git.kernel.org/netdev/net/c/87a1e0fe7776
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html