ipv6: fix error handling in disable_ipv6 sysctl
Subsystems (3)
v3 cover ipv6: fix error handling in disable_ipv6 sysctl
While working on a different IPv6 patch series I have spotted multiple minor bugs around sysctl error handling and notifications. In general, they are not serious issues.
In addition, there is one more issue in forwarding sysctl as it does not check for CAP_NET_ADMIN for the namespace. I am keeping that patch out of this series and I am aiming it at the net-next tree once it re-opens.
During v3, Ido's pointed out that it is unnecessary to reset the position pointer when the return value is negative as at new_sync_write() the ppos is only advanced when ret return value is positive. That means we can get rid of that operation in ipv4/ipv6 sysctls. That is going to be sent to net-next too.
Changes:
v3: Patch 7: dropped from the series based on Ido's feedback
v2: https://lore.kernel.org/netdev/[email protected]/
Patch 3: fix return code of addrconf_fixup_forwarding() Patch 5: acquire lock before calling proc_dointvec()
Patch 7: new on this revision of the series
Fernando Fernandez Mancera (6):
ipv6: fix error handling in disable_ipv6 sysctl
ipv6: fix error handling in ignore_routes_with_linkdown sysctl
ipv6: fix error handling in forwarding sysctl
ipv6: fix error handling in disable_policy sysctl
ipv6: fix state corruption during proxy_ndp sysctl restart
ipv6: fix missing notification for ignore_routes_with_linkdown
net/ipv6/addrconf.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-)
Signature · 1 line
2.54.0
PATCH v3 1/6 ipv6: fix error handling in disable_ipv6 sysctl
When writing to the disable_ipv6 sysctl, if proc_dointvec() fails to parse the input, it returns a negative error code. The current implementation is overwriting that error for write operations.
This results in a silent failure, it returns a successful write although the configuration was not modified at all. When modifying the "all" variant it can also modify the configuration of existing interfaces to the wrong value.
Fix this by checking the return value of proc_dointvec() and returning early on failure.
--- net/ipv6/addrconf.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv6/addrconf.c +2 -0
@@ -6467,6 +6467,8 @@ static int addrconf_sysctl_disable(const struct ctl_table *ctl, int write, lctl.data = &val; ret =proc_dointvec (&lctl, write, buffer, lenp, ppos); +if (ret) +return ret;if (write) ret =addrconf_disable_ipv6 (ctl, valp, val);
Signature · 1 line
2.54.0
PATCH v3 2/6 ipv6: fix error handling in ignore_routes_with_linkdown sysctl
In reply to Fernando Fernandez ManceraWhen writing to the ignore_routes_with_linkdown sysctl, if proc_dointvec() fails to parse the input, it returns a negative error code. The current implementation is overwriting that error for write operations.
This results in a silent failure, it returns a successful write although the configuration was not modified at all. When modifying the "all" variant it can also modify the configuration of existing interfaces to the wrong value.
Fix this by checking the return value of proc_dointvec() and returning early on failure.
--- net/ipv6/addrconf.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv6/addrconf.c +2 -0
@@ -6671,6 +6671,8 @@ int addrconf_sysctl_ignore_routes_with_linkdown(const struct ctl_table *ctl, lctl.data = &val; ret =proc_dointvec (&lctl, write, buffer, lenp, ppos); +if (ret) +return ret;if (write) ret =addrconf_fixup_linkdown (ctl, valp, val);
Signature · 1 line
2.54.0
PATCH v3 3/6 ipv6: fix error handling in forwarding sysctl
In reply to Fernando Fernandez ManceraWhen writing to the forwarding sysctl, if proc_dointvec() fails to parse the input, it returns a negative error code. The current implementation is overwriting that error for write operations.
This results in a silent failure, it returns a successful write although the configuration was not modified at all. When modifying the "all" variant it can also modify the configuration of existing interfaces to the wrong value.
Fix this by checking the return value of proc_dointvec() and returning early on failure. In addition, adjust return code of addrconf_fixup_forwarding() for successful operation.
--- net/ipv6/addrconf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/ipv6/addrconf.c +3 -1
@@ -913,7 +913,7 @@ static int addrconf_fixup_forwarding(const struct ctl_table *table, int *p, intif (newf)rt6_purge_dflt_routers (net); -return 1 ; +return 0 ; }static void addrconf_linkdown_change (struct net *net,__s32 newf)
@@ -6370,6 +6370,8 @@ static int addrconf_sysctl_forward(const struct ctl_table *ctl, int write, lctl.data = &val; ret =proc_dointvec (&lctl, write, buffer, lenp, ppos); +if (ret) +return ret;if (write) ret =addrconf_fixup_forwarding (ctl, valp, val);
Signature · 1 line
2.54.0
PATCH v3 4/6 ipv6: fix error handling in disable_policy sysctl
In reply to Fernando Fernandez ManceraWhen writing to the disable_policy sysctl, if proc_dointvec() fails to parse the input, it returns a negative error code. The current implementation is resetting the position argument even if an error occurred during proc_dointvec() and not only during sysctl restart.
Fix this by checking the return value of proc_dointvec() and returning early on failure.
--- net/ipv6/addrconf.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv6/addrconf.c +2 -0
@@ -6769,6 +6769,8 @@ static int addrconf_sysctl_disable_policy(const struct ctl_table *ctl, int write lctl = *ctl; lctl.data = &val; ret =proc_dointvec (&lctl, write, buffer, lenp, ppos); +if (ret) +return ret;if (write && (*valp != val)) ret =addrconf_disable_policy (ctl, valp, val);
Signature · 1 line
2.54.0
PATCH v3 5/6 ipv6: fix state corruption during proxy_ndp sysctl restart
In reply to Fernando Fernandez ManceraWhen handling proxy_ndp, if rtnl_net_trylock() fails, the operation is retried but as the value was already modified by the initial proc_dointvec() call, the restarted syscall will read the newly modified value as the 'old' state.
Fix this by taking the RTNL lock before parsing the input value if the operation is a write.
--- net/ipv6/addrconf.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
net/ipv6/addrconf.c +7 -7
@@ -6482,20 +6482,19 @@ static int addrconf_sysctl_disable(const struct ctl_table *ctl, int write,static int addrconf_sysctl_proxy_ndp (const struct ctl_table *ctl,int write,void *buffer,size_t *lenp,loff_t *ppos) { +struct net *net = ctl->extra2;int *valp = ctl->data; -int ret;int old, new; +int ret; + +if (write && !rtnl_net_trylock (net)) +return restart_syscall (); old = *valp; ret =proc_dointvec (ctl, write, buffer, lenp, ppos); new = *valp;if (write && old != new) { -struct net *net = ctl->extra2; - -if (!rtnl_net_trylock (net)) -return restart_syscall (); -if (valp == &net->ipv6.devconf_dflt->proxy_ndp) { inet6_netconf_notify_devconf(net, RTM_NEWNETCONF, NETCONFA_PROXY_NEIGH,
@@ -6514,8 +6513,9 @@ static int addrconf_sysctl_proxy_ndp(const struct ctl_table *ctl, int write, idev->dev->ifindex, &idev->cnf); } -rtnl_net_unlock (net); } +if (write) +rtnl_net_unlock (net);return ret; }
Signature · 1 line
2.54.0
PATCH v3 6/6 ipv6: fix missing notification for ignore_routes_with_linkdown
In reply to Fernando Fernandez ManceraWhen changing the ignore_routes_with_linkdown sysctl for a specific interface, the RTM_NEWNETCONF netlink notification was not being emitted to userspace. Fix this by emitting the notification when needed.
In addition, fix bogus return value for successful "all" and specific interface write operation leading to a wrong reset of the position pointer.
--- net/ipv6/addrconf.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
net/ipv6/addrconf.c +12 -6
@@ -955,11 +955,7 @@ static int addrconf_fixup_linkdown(const struct ctl_table *table, int *p, int neNETCONFA_IGNORE_ROUTES_WITH_LINKDOWN ,NETCONFA_IFINDEX_DEFAULT , net->ipv6.devconf_dflt); -rtnl_net_unlock (net); -return 0 ; - } - -if (p == &net->ipv6.devconf_all->ignore_routes_with_linkdown) { + }else if (p == &net->ipv6.devconf_all->ignore_routes_with_linkdown) {WRITE_ONCE (net->ipv6.devconf_dflt->ignore_routes_with_linkdown, newf);addrconf_linkdown_change (net, newf);if ((!newf) ^ (!old))
@@ -968,11 +964,21 @@ static int addrconf_fixup_linkdown(const struct ctl_table *table, int *p, int neNETCONFA_IGNORE_ROUTES_WITH_LINKDOWN ,NETCONFA_IFINDEX_ALL , net->ipv6.devconf_all); + }else { +if (!newf ^ !old) { +struct inet6_dev *idev = table->extra1; + +inet6_netconf_notify_devconf (net, +RTM_NEWNETCONF , +NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN , + idev->dev->ifindex, + &idev->cnf); + } }rtnl_net_unlock (net); -return 1 ; +return 0 ; }#endif
Signature · 1 line
2.54.0
Quoted 3 lines · Fernando Fernandez Mancera
While working on a different IPv6 patch series I have spotted multiple minor bugs around sysctl error handling and notifications. In general, they are not serious issues.
For the series:
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Mon, 22 Jun 2026 15:08:51 +0200 you wrote:
While working on a different IPv6 patch series I have spotted multiple minor bugs around sysctl error handling and notifications. In general, they are not serious issues.
In addition, there is one more issue in forwarding sysctl as it does not check for
CAP_NET_ADMINfor the namespace. I am keeping that patch out of this series and I am aiming it at the net-next tree once it re-opens.[...]
Here is the summary with links:
- [net,v3,1/6] ipv6: fix error handling in disable_ipv6 sysctl
https://git.kernel.org/netdev/net/c/c779441e5070 - [net,v3,2/6] ipv6: fix error handling in ignore_routes_with_linkdown sysctl https://git.kernel.org/netdev/net/c/cf4f2b14401f - [net,v3,3/6] ipv6: fix error handling in forwarding sysctl https://git.kernel.org/netdev/net/c/058b9b19f963 - [net,v3,4/6] ipv6: fix error handling in disable_policy sysctl https://git.kernel.org/netdev/net/c/3e0e51c0ee1d - [net,v3,5/6] ipv6: fix state corruption during proxy_ndp sysctl restart https://git.kernel.org/netdev/net/c/6a1b50e585f0 - [net,v3,6/6] ipv6: fix missing notification for ignore_routes_with_linkdown https://git.kernel.org/netdev/net/c/17dc3b245de4
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html