ipv6: fix sysctl error handling and missing notifications
Subsystems (3)
cover ipv6: fix sysctl error handling and missing notifications
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.
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: reset value and position for proxy_ndp sysctl restart
ipv6: fix missing notification for ignore_routes_with_linkdown
net/ipv6/addrconf.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-)
Signature · 1 line
2.54.0
PATCH 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
Re: [PATCH net 1/6] ipv6: fix error handling in disable_ipv6 sysctl
Le 18/06/2026 à 18:22, Fernando Fernandez Mancera a écrit :
Quoted 9 lines
When writing to the
disable_ipv6sysctl, ifproc_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.
Quoted 5 lines
Fix this by checking the return value of
proc_dointvec()and returning early on failure.Fixes 56d417b12e57 ("IPv6: Add 'autoconf' and 'disable_ipv6' module parameters")Signed-off-by Fernando Fernandez Mancera <[email protected]>
PATCH 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
Re: [PATCH net 2/6] ipv6: fix error handling in ignore_routes_with_linkdown sysctl
Le 18/06/2026 à 18:22, Fernando Fernandez Mancera a écrit :
Quoted 10 lines
When writing to the
ignore_routes_with_linkdownsysctl, ifproc_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.
Quoted 4 lines
Fix this by checking the return value of
proc_dointvec()and returning early on failure.Fixes 35103d11173b ("net: ipv6 sysctl option to ignore routes when nexthop link is down")
PATCH 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.
--- net/ipv6/addrconf.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv6/addrconf.c +2 -0
@@ -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
Re: [PATCH net 3/6] ipv6: fix error handling in forwarding sysctl
Le 18/06/2026 à 18:22, Fernando Fernandez Mancera a écrit :
Quoted 9 lines
When 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.
Quoted 4 lines
Fix this by checking the return value of
proc_dointvec()and returning early on failure.Fixes b325fddb7f86 ("ipv6: Fix sysctl unregistration deadlock")
The bug existed before the git era.
Maybe
Re: [PATCH net 3/6] ipv6: fix error handling in forwarding sysctl
Quoted 10 lines · Nicolas Dichtel
Le 18/06/2026 à 18:22, Fernando Fernandez Mancera a écrit :
Quoted 9 lines
When 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.
Quoted 9 lines
Quoted 4 lines
Fix this by checking the return value of
proc_dointvec()and returning early on failure.Fixes b325fddb7f86 ("ipv6: Fix sysctl unregistration deadlock")The bug existed before the git era.
MaybeFixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Hm, not really, AFAICS b325fddb7f86 is the first commit overwriting the return value from proc_dointvec(). See:
@@ -3983,7 +3986,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write, struct file * filp,
ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos);
if (write)
- addrconf_fixup_forwarding(ctl, valp, val);
+ ret = addrconf_fixup_forwarding(ctl, valp, val);
return ret;
}
Nicolas Dichtel
Reviewed-byRe: [PATCH net 3/6] ipv6: fix error handling in forwarding sysctl
Le 19/06/2026 à 12:28, Fernando Fernandez Mancera a écrit :
Quoted 26 lines · Nicolas Dichtel
Quoted 10 lines
Le 18/06/2026 à 18:22, Fernando Fernandez Mancera a écrit :
Quoted 9 lines
When 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.
Quoted 9 lines
Quoted 4 lines
Fix this by checking the return value of
proc_dointvec()and returning early on failure.Fixes b325fddb7f86 ("ipv6: Fix sysctl unregistration deadlock")The bug existed before the git era.
MaybeFixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Hm, not really, AFAICS
b325fddb7f86is the first commit overwriting the return value fromproc_dointvec(). See:
Review int addrconf_sysctl_forward(ctl_table *ctl, int write, · line 3992
Quoted 8 lines
(quoted diff) +1
-1@@ -3983,7 +3986,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write, struct file * filp, ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos); if (write) - addrconf_fixup_forwarding(ctl, valp, val); + ret = addrconf_fixup_forwarding(ctl, valp, val); return ret; }
Hmm, you're right.
PATCH 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
Re: [PATCH net 4/6] ipv6: fix error handling in disable_policy sysctl
Le 18/06/2026 à 18:22, Fernando Fernandez Mancera a écrit :
Quoted 10 lines
When writing to the
disable_policysysctl, ifproc_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 duringproc_dointvec()and not only during sysctl restart.Fix this by checking the return value of
proc_dointvec()and returning early on failure.Fixes df789fe75206 ("ipv6: Provide ipv6 version of "disable_policy" sysctl")Signed-off-by Fernando Fernandez Mancera <[email protected]>
PATCH 5/6 ipv6: reset value and position for 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 restoring the original value and position pointer before restarting the syscall.
--- net/ipv6/addrconf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/ipv6/addrconf.c +7 -2
@@ -6483,8 +6483,9 @@ static int addrconf_sysctl_proxy_ndp(const struct ctl_table *ctl, int write, void *buffer, size_t *lenp, loff_t *ppos) { int *valp = ctl->data; -int ret; +loff_t pos = *ppos;int old, new; +int ret; old = *valp; ret =proc_dointvec (ctl, write, buffer, lenp, ppos);
@@ -6493,8 +6494,12 @@ static int addrconf_sysctl_proxy_ndp(const struct ctl_table *ctl, int write,if (write && old != new) {struct net *net = ctl->extra2; -if (!rtnl_net_trylock (net)) +if (!rtnl_net_trylock (net)) { +/* Restore the original values before restarting */ + *valp = old; + *ppos = pos;return restart_syscall (); + }if (valp == &net->ipv6.devconf_dflt->proxy_ndp) { inet6_netconf_notify_devconf(net, RTM_NEWNETCONF,
Signature · 1 line
2.54.0
Re: [PATCH net 5/6] ipv6: reset value and position for proxy_ndp sysctl restart
Le 18/06/2026 à 18:22, Fernando Fernandez Mancera a écrit :
Quoted 7 lines
When handling
proxy_ndp, ifrtnl_net_trylock()fails, the operation is retried but as the value was already modified by the initialproc_dointvec()call, the restarted syscall will read the newly modified value as the 'old' state.Fix this by restoring the original value and position pointer before restarting the syscall.
Is it not better to call rtnl_net_trylock() at the beginning of the function? It avoids flapping the sysctl value.
Quoted 36 lines
Fixes c92d5491a6d9 ("netconf: add support for IPv6 proxy_ndp")Signed-off-by Fernando Fernandez Mancera <[email protected]>--- net/ipv6/addrconf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)net/ipv6/addrconf.c +7
-2@@ -6483,8 +6483,9 @@ static int addrconf_sysctl_proxy_ndp(const struct ctl_table *ctl, int write, void *buffer, size_t *lenp, loff_t *ppos) { int *valp = ctl->data; -int ret; +loff_t pos = *ppos;int old, new; +int ret; old = *valp; ret =proc_dointvec (ctl, write, buffer, lenp, ppos);@@ -6493,8 +6494,12 @@ static int addrconf_sysctl_proxy_ndp(const struct ctl_table *ctl, int write,if (write && old != new) {struct net *net = ctl->extra2; -if (!rtnl_net_trylock (net)) +if (!rtnl_net_trylock (net)) { +/* Restore the original values before restarting */ + *valp = old; + *ppos = pos;return restart_syscall (); + }if (valp == &net->ipv6.devconf_dflt->proxy_ndp) { inet6_netconf_notify_devconf(net, RTM_NEWNETCONF,
Re: [PATCH net 5/6] ipv6: reset value and position for proxy_ndp sysctl restart
Quoted 11 lines · Nicolas Dichtel
Le 18/06/2026 à 18:22, Fernando Fernandez Mancera a écrit :
Quoted 7 lines
When handling
proxy_ndp, ifrtnl_net_trylock()fails, the operation is retried but as the value was already modified by the initialproc_dointvec()call, the restarted syscall will read the newly modified value as the 'old' state.Fix this by restoring the original value and position pointer before restarting the syscall.
Is it not better to call
rtnl_net_trylock()at the beginning of the function? It avoids flapping the sysctl value.
IMHO it is not better if we want to reduce the time we are holding RTNL lock. I think the idea is that if the user introduces a invalid value, we don't need to take the lock at all.
That is the general pattern I see around the sysctl code (IPv4 and IPv6). Given the current efforts to reduce the usage of RTNL I think this approach would be better.
In any case, it is not a blocker for me so if we all agree that your suggestion is better I don't mind taking that path.
Thanks for all the reviews!
Quoted 38 lines
Quoted 36 lines
Fixes c92d5491a6d9 ("netconf: add support for IPv6 proxy_ndp")Signed-off-by Fernando Fernandez Mancera <[email protected]>--- net/ipv6/addrconf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)net/ipv6/addrconf.c +7
-2@@ -6483,8 +6483,9 @@ static int addrconf_sysctl_proxy_ndp(const struct ctl_table *ctl, int write, void *buffer, size_t *lenp, loff_t *ppos) { int *valp = ctl->data; -int ret; +loff_t pos = *ppos;int old, new; +int ret; old = *valp; ret =proc_dointvec (ctl, write, buffer, lenp, ppos);@@ -6493,8 +6494,12 @@ static int addrconf_sysctl_proxy_ndp(const struct ctl_table *ctl, int write,if (write && old != new) {struct net *net = ctl->extra2; -if (!rtnl_net_trylock (net)) +if (!rtnl_net_trylock (net)) { +/* Restore the original values before restarting */ + *valp = old; + *ppos = pos;return restart_syscall (); + }if (valp == &net->ipv6.devconf_dflt->proxy_ndp) { inet6_netconf_notify_devconf(net, RTM_NEWNETCONF,
PATCH 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
Re: [PATCH net 6/6] ipv6: fix missing notification for ignore_routes_with_linkdown
Le 18/06/2026 à 18:22, Fernando Fernandez Mancera a écrit :
Quoted 10 lines
When changing the
ignore_routes_with_linkdownsysctl for a specific interface, theRTM_NEWNETCONFnetlink 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.
Fixes 35103d11173b ("net: ipv6 sysctl option to ignore routes when nexthop link is down")Signed-off-by Fernando Fernandez Mancera <[email protected]>
Quoted 16 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.
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.Fernando Fernandez Mancera (6):
ipv6: fix error handling indisable_ipv6sysctl
ipv6: fix error handling inignore_routes_with_linkdownsysctl
ipv6: fix error handling in forwarding sysctl
ipv6: fix error handling indisable_policysysctl
ipv6: reset value and position forproxy_ndpsysctl restart
ipv6: fix missing notification forignore_routes_with_linkdown
Quoted 3 lines
net/ipv6/addrconf.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-)
So I have checked the feedback from sashiko.dev [1]. In general, it is real but I have doubts about this one. While it is real, I am not so sure we actually care about this scenario. In any case, this is a pattern around kernel code and it would require fixes everywhere (IPv4/IPv6/other places (?)).
The easier thing to do is what Nicolas suggested about taking the lock before parsing the value i.e before calling proc_dointvec().
I also do wonder if I should fix them in individual commits or together in the same commit as they have different fixes tag. Or maybe we can aim this last part to net-next. Thoughts?
Please, see the feedback attached below.
Thanks!
[1] https://sashiko.dev/#/patchset/20260618162225.4588-1-fmancera%40suse.de
Quoted 4 lines
net/ipv6/addrconf.c +0
-0
[ ... ]
net/ipv6/addrconf.c static int addrconf_sysctl_proxy_ndp(const struct ctl_table *ctl, int write, · line 6503
Quoted 12 lines
net/ipv6/addrconf.c +5
-1@@ -6493,8 +6494,12 @@ static int addrconf_sysctl_proxy_ndp(const struct ctl_table *ctl, int write,if (write && old != new) {struct net *net = ctl->extra2; -if (!rtnl_net_trylock (net)) +if (!rtnl_net_trylock (net)) { +/* Restore the original values before restarting */ + *valp = old; + *ppos = pos;return restart_syscall (); + }
Does this rollback introduce a race condition that can silently discard concurrent writes?
The sysctl core does not serialize concurrent writes to the same sysctl parameter, and proc_dointvec() modifies the global sysctl memory pointed to by ctl->data directly.
If Thread A and Thread B concurrently write to proxy_ndp, and Thread A fails to acquire the RTNL lock, setting *valp = old will unconditionally reset the global memory back to what Thread A observed before its write. This seems like it would clobber Thread B's concurrent update.
If Thread B successfully acquires the RTNL lock, it will evaluate its local old != new stack variables as true and emit a RTM_NEWNETCONF netlink notification. However, the notification will read the corrupted *valp memory, leaving the emitted event and internal sysctl state out of sync. Could this be avoided by duplicating the ctl_table, pointing the data field to a local stack variable, calling proc_dointvec() on the local variable, and only updating the global *valp after successfully acquiring the lock, similar to how it is handled in addrconf_sysctl_forward()?