Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2 0/7] ipv6: fix sysctl error handling and missing notifications
@ 2026-06-20 16:18 Fernando Fernandez Mancera
  2026-06-20 16:18 ` [PATCH net v2 1/7] ipv6: fix error handling in disable_ipv6 sysctl Fernando Fernandez Mancera
                   ` (6 more replies)
  0 siblings, 7 replies; 11+ messages in thread
From: Fernando Fernandez Mancera @ 2026-06-20 16:18 UTC (permalink / raw)
  To: netdev
  Cc: nicolas.dichtel, stephen, brian.haley, horms, pabeni, kuba,
	edumazet, davem, idosch, dsahern, 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_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.

Changes:
  v2: 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 (7):
  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
  ipv6: reset position for force_forwarding sysctl restart

 net/ipv6/addrconf.c | 48 +++++++++++++++++++++++++++++----------------
 1 file changed, 31 insertions(+), 17 deletions(-)

-- 
2.54.0


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

* [PATCH net v2 1/7] ipv6: fix error handling in disable_ipv6 sysctl
  2026-06-20 16:18 [PATCH net v2 0/7] ipv6: fix sysctl error handling and missing notifications Fernando Fernandez Mancera
@ 2026-06-20 16:18 ` Fernando Fernandez Mancera
  2026-06-20 16:18 ` [PATCH net v2 2/7] ipv6: fix error handling in ignore_routes_with_linkdown sysctl Fernando Fernandez Mancera
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Fernando Fernandez Mancera @ 2026-06-20 16:18 UTC (permalink / raw)
  To: netdev
  Cc: nicolas.dichtel, stephen, brian.haley, horms, pabeni, kuba,
	edumazet, davem, idosch, dsahern, Fernando Fernandez Mancera

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.

Fixes: 56d417b12e57 ("IPv6: Add 'autoconf' and 'disable_ipv6' module parameters")
Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
---
 net/ipv6/addrconf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 1f21ccb55caa..c901b444a995 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -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);
-- 
2.54.0


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

* [PATCH net v2 2/7] ipv6: fix error handling in ignore_routes_with_linkdown sysctl
  2026-06-20 16:18 [PATCH net v2 0/7] ipv6: fix sysctl error handling and missing notifications Fernando Fernandez Mancera
  2026-06-20 16:18 ` [PATCH net v2 1/7] ipv6: fix error handling in disable_ipv6 sysctl Fernando Fernandez Mancera
@ 2026-06-20 16:18 ` Fernando Fernandez Mancera
  2026-06-20 16:18 ` [PATCH net v2 3/7] ipv6: fix error handling in forwarding sysctl Fernando Fernandez Mancera
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Fernando Fernandez Mancera @ 2026-06-20 16:18 UTC (permalink / raw)
  To: netdev
  Cc: nicolas.dichtel, stephen, brian.haley, horms, pabeni, kuba,
	edumazet, davem, idosch, dsahern, Fernando Fernandez Mancera

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

Fixes: 35103d11173b ("net: ipv6 sysctl option to ignore routes when nexthop link is down")
Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
---
 net/ipv6/addrconf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index c901b444a995..70058d971205 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -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);
-- 
2.54.0


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

* [PATCH net v2 3/7] ipv6: fix error handling in forwarding sysctl
  2026-06-20 16:18 [PATCH net v2 0/7] ipv6: fix sysctl error handling and missing notifications Fernando Fernandez Mancera
  2026-06-20 16:18 ` [PATCH net v2 1/7] ipv6: fix error handling in disable_ipv6 sysctl Fernando Fernandez Mancera
  2026-06-20 16:18 ` [PATCH net v2 2/7] ipv6: fix error handling in ignore_routes_with_linkdown sysctl Fernando Fernandez Mancera
@ 2026-06-20 16:18 ` Fernando Fernandez Mancera
  2026-06-20 16:18 ` [PATCH net v2 4/7] ipv6: fix error handling in disable_policy sysctl Fernando Fernandez Mancera
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Fernando Fernandez Mancera @ 2026-06-20 16:18 UTC (permalink / raw)
  To: netdev
  Cc: nicolas.dichtel, stephen, brian.haley, horms, pabeni, kuba,
	edumazet, davem, idosch, dsahern, Fernando Fernandez Mancera

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.

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.

Fixes: b325fddb7f86 ("ipv6: Fix sysctl unregistration deadlock")
Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
---
 net/ipv6/addrconf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 70058d971205..d23a89b07eed 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -913,7 +913,7 @@ static int addrconf_fixup_forwarding(const struct ctl_table *table, int *p, int
 
 	if (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);
-- 
2.54.0


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

* [PATCH net v2 4/7] ipv6: fix error handling in disable_policy sysctl
  2026-06-20 16:18 [PATCH net v2 0/7] ipv6: fix sysctl error handling and missing notifications Fernando Fernandez Mancera
                   ` (2 preceding siblings ...)
  2026-06-20 16:18 ` [PATCH net v2 3/7] ipv6: fix error handling in forwarding sysctl Fernando Fernandez Mancera
@ 2026-06-20 16:18 ` Fernando Fernandez Mancera
  2026-06-20 16:18 ` [PATCH net v2 5/7] ipv6: reset value and position for proxy_ndp sysctl restart Fernando Fernandez Mancera
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Fernando Fernandez Mancera @ 2026-06-20 16:18 UTC (permalink / raw)
  To: netdev
  Cc: nicolas.dichtel, stephen, brian.haley, horms, pabeni, kuba,
	edumazet, davem, idosch, dsahern, Fernando Fernandez Mancera

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

Fixes: df789fe75206 ("ipv6: Provide ipv6 version of "disable_policy" sysctl")
Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
---
 net/ipv6/addrconf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index d23a89b07eed..5d96cbf76134 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -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);
-- 
2.54.0


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

* [PATCH net v2 5/7] ipv6: reset value and position for proxy_ndp sysctl restart
  2026-06-20 16:18 [PATCH net v2 0/7] ipv6: fix sysctl error handling and missing notifications Fernando Fernandez Mancera
                   ` (3 preceding siblings ...)
  2026-06-20 16:18 ` [PATCH net v2 4/7] ipv6: fix error handling in disable_policy sysctl Fernando Fernandez Mancera
@ 2026-06-20 16:18 ` Fernando Fernandez Mancera
  2026-06-22 11:48   ` Nicolas Dichtel
  2026-06-20 16:18 ` [PATCH net v2 6/7] ipv6: fix missing notification for ignore_routes_with_linkdown Fernando Fernandez Mancera
  2026-06-20 16:18 ` [PATCH net v2 7/7] ipv6: reset position for force_forwarding sysctl restart Fernando Fernandez Mancera
  6 siblings, 1 reply; 11+ messages in thread
From: Fernando Fernandez Mancera @ 2026-06-20 16:18 UTC (permalink / raw)
  To: netdev
  Cc: nicolas.dichtel, stephen, brian.haley, horms, pabeni, kuba,
	edumazet, davem, idosch, dsahern, Fernando Fernandez Mancera

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

Fixes: c92d5491a6d9 ("netconf: add support for IPv6 proxy_ndp")
Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
---
 net/ipv6/addrconf.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 5d96cbf76134..82b6f603faa0 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -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;
 }
-- 
2.54.0


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

* [PATCH net v2 6/7] ipv6: fix missing notification for ignore_routes_with_linkdown
  2026-06-20 16:18 [PATCH net v2 0/7] ipv6: fix sysctl error handling and missing notifications Fernando Fernandez Mancera
                   ` (4 preceding siblings ...)
  2026-06-20 16:18 ` [PATCH net v2 5/7] ipv6: reset value and position for proxy_ndp sysctl restart Fernando Fernandez Mancera
@ 2026-06-20 16:18 ` Fernando Fernandez Mancera
  2026-06-20 16:18 ` [PATCH net v2 7/7] ipv6: reset position for force_forwarding sysctl restart Fernando Fernandez Mancera
  6 siblings, 0 replies; 11+ messages in thread
From: Fernando Fernandez Mancera @ 2026-06-20 16:18 UTC (permalink / raw)
  To: netdev
  Cc: nicolas.dichtel, stephen, brian.haley, horms, pabeni, kuba,
	edumazet, davem, idosch, dsahern, Fernando Fernandez Mancera

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

Fixes: 35103d11173b ("net: ipv6 sysctl option to ignore routes when nexthop link is down")
Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
---
 net/ipv6/addrconf.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 82b6f603faa0..cbe681de3818 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -955,11 +955,7 @@ static int addrconf_fixup_linkdown(const struct ctl_table *table, int *p, int ne
 						     NETCONFA_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 ne
 						     NETCONFA_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
-- 
2.54.0


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

* [PATCH net v2 7/7] ipv6: reset position for force_forwarding sysctl restart
  2026-06-20 16:18 [PATCH net v2 0/7] ipv6: fix sysctl error handling and missing notifications Fernando Fernandez Mancera
                   ` (5 preceding siblings ...)
  2026-06-20 16:18 ` [PATCH net v2 6/7] ipv6: fix missing notification for ignore_routes_with_linkdown Fernando Fernandez Mancera
@ 2026-06-20 16:18 ` Fernando Fernandez Mancera
  2026-06-22 11:42   ` Ido Schimmel
  6 siblings, 1 reply; 11+ messages in thread
From: Fernando Fernandez Mancera @ 2026-06-20 16:18 UTC (permalink / raw)
  To: netdev
  Cc: nicolas.dichtel, stephen, brian.haley, horms, pabeni, kuba,
	edumazet, davem, idosch, dsahern, Fernando Fernandez Mancera

When handling proxy_ndp, if rtnl_net_trylock() fails, the operation is
retried but the position pointer was already advanced meaning that the
restarted sysctl will read from an incorrect offset.

Fix this by restoring the original position pointer before restarting
the syscall.

In addition, remove the redundant position pointer restoration at the
end of the function.

Fixes: f24987ef6959 ("ipv6: add `force_forwarding` sysctl to enable per-interface forwarding")
Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
---
 net/ipv6/addrconf.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index cbe681de3818..8c0741e9dfcc 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -6825,8 +6825,10 @@ static int addrconf_sysctl_force_forwarding(const struct ctl_table *ctl, int wri
 	ret = proc_douintvec_minmax(&tmp_ctl, write, buffer, lenp, ppos);
 
 	if (write && old_val != new_val) {
-		if (!rtnl_net_trylock(net))
+		if (!rtnl_net_trylock(net)) {
+			*ppos = pos;
 			return restart_syscall();
+		}
 
 		WRITE_ONCE(*valp, new_val);
 
@@ -6851,8 +6853,6 @@ static int addrconf_sysctl_force_forwarding(const struct ctl_table *ctl, int wri
 		rtnl_net_unlock(net);
 	}
 
-	if (ret)
-		*ppos = pos;
 	return ret;
 }
 
-- 
2.54.0


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

* Re: [PATCH net v2 7/7] ipv6: reset position for force_forwarding sysctl restart
  2026-06-20 16:18 ` [PATCH net v2 7/7] ipv6: reset position for force_forwarding sysctl restart Fernando Fernandez Mancera
@ 2026-06-22 11:42   ` Ido Schimmel
  2026-06-22 12:19     ` Fernando Fernandez Mancera
  0 siblings, 1 reply; 11+ messages in thread
From: Ido Schimmel @ 2026-06-22 11:42 UTC (permalink / raw)
  To: Fernando Fernandez Mancera
  Cc: netdev, nicolas.dichtel, stephen, brian.haley, horms, pabeni,
	kuba, edumazet, davem, dsahern

On Sat, Jun 20, 2026 at 06:18:50PM +0200, Fernando Fernandez Mancera wrote:
> When handling proxy_ndp, if rtnl_net_trylock() fails, the operation is

s/proxy_ndp/force_forwarding/

> retried but the position pointer was already advanced meaning that the
> restarted sysctl will read from an incorrect offset.
> 
> Fix this by restoring the original position pointer before restarting
> the syscall.
> 
> In addition, remove the redundant position pointer restoration at the
> end of the function.
> 
> Fixes: f24987ef6959 ("ipv6: add `force_forwarding` sysctl to enable per-interface forwarding")
> Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
> ---
>  net/ipv6/addrconf.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
> index cbe681de3818..8c0741e9dfcc 100644
> --- a/net/ipv6/addrconf.c
> +++ b/net/ipv6/addrconf.c
> @@ -6825,8 +6825,10 @@ static int addrconf_sysctl_force_forwarding(const struct ctl_table *ctl, int wri
>  	ret = proc_douintvec_minmax(&tmp_ctl, write, buffer, lenp, ppos);
>  
>  	if (write && old_val != new_val) {
> -		if (!rtnl_net_trylock(net))
> +		if (!rtnl_net_trylock(net)) {
> +			*ppos = pos;
>  			return restart_syscall();
> +		}

Are you sure that this is needed?

AFAICT, the position pointer is only advanced if the return value is
positive. From new_sync_write():

kiocb.ki_pos = (ppos ? *ppos : 0);
[...]
ret = filp->f_op->write_iter(&kiocb, &iter);
[...]
if (ret > 0 && ppos)
        *ppos = kiocb.ki_pos;

And restart_syscall() returns '-ERESTARTNOINTR'.

>  
>  		WRITE_ONCE(*valp, new_val);
>  
> @@ -6851,8 +6853,6 @@ static int addrconf_sysctl_force_forwarding(const struct ctl_table *ctl, int wri
>  		rtnl_net_unlock(net);
>  	}
>  
> -	if (ret)
> -		*ppos = pos;
>  	return ret;
>  }
>  
> -- 
> 2.54.0
> 

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

* Re: [PATCH net v2 5/7] ipv6: reset value and position for proxy_ndp sysctl restart
  2026-06-20 16:18 ` [PATCH net v2 5/7] ipv6: reset value and position for proxy_ndp sysctl restart Fernando Fernandez Mancera
@ 2026-06-22 11:48   ` Nicolas Dichtel
  0 siblings, 0 replies; 11+ messages in thread
From: Nicolas Dichtel @ 2026-06-22 11:48 UTC (permalink / raw)
  To: Fernando Fernandez Mancera, netdev
  Cc: stephen, brian.haley, horms, pabeni, kuba, edumazet, davem,
	idosch, dsahern

Le 20/06/2026 à 18:18, Fernando Fernandez Mancera a écrit :
> When 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.
> 
> Fixes: c92d5491a6d9 ("netconf: add support for IPv6 proxy_ndp")
> Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>

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

* Re: [PATCH net v2 7/7] ipv6: reset position for force_forwarding sysctl restart
  2026-06-22 11:42   ` Ido Schimmel
@ 2026-06-22 12:19     ` Fernando Fernandez Mancera
  0 siblings, 0 replies; 11+ messages in thread
From: Fernando Fernandez Mancera @ 2026-06-22 12:19 UTC (permalink / raw)
  To: Ido Schimmel
  Cc: netdev, nicolas.dichtel, stephen, brian.haley, horms, pabeni,
	kuba, edumazet, davem, dsahern

On 6/22/26 1:42 PM, Ido Schimmel wrote:
> On Sat, Jun 20, 2026 at 06:18:50PM +0200, Fernando Fernandez Mancera wrote:
>> When handling proxy_ndp, if rtnl_net_trylock() fails, the operation is
> 
> s/proxy_ndp/force_forwarding/
> 
>> retried but the position pointer was already advanced meaning that the
>> restarted sysctl will read from an incorrect offset.
>>
>> Fix this by restoring the original position pointer before restarting
>> the syscall.
>>
>> In addition, remove the redundant position pointer restoration at the
>> end of the function.
>>
>> Fixes: f24987ef6959 ("ipv6: add `force_forwarding` sysctl to enable per-interface forwarding")
>> Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
>> ---
>>   net/ipv6/addrconf.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
>> index cbe681de3818..8c0741e9dfcc 100644
>> --- a/net/ipv6/addrconf.c
>> +++ b/net/ipv6/addrconf.c
>> @@ -6825,8 +6825,10 @@ static int addrconf_sysctl_force_forwarding(const struct ctl_table *ctl, int wri
>>   	ret = proc_douintvec_minmax(&tmp_ctl, write, buffer, lenp, ppos);
>>   
>>   	if (write && old_val != new_val) {
>> -		if (!rtnl_net_trylock(net))
>> +		if (!rtnl_net_trylock(net)) {
>> +			*ppos = pos;
>>   			return restart_syscall();
>> +		}
> 
> Are you sure that this is needed?
> 
> AFAICT, the position pointer is only advanced if the return value is
> positive. From new_sync_write():
> 
> kiocb.ki_pos = (ppos ? *ppos : 0);
> [...]
> ret = filp->f_op->write_iter(&kiocb, &iter);
> [...]
> if (ret > 0 && ppos)
>          *ppos = kiocb.ki_pos;
> 
> And restart_syscall() returns '-ERESTARTNOINTR'.
> 

Hm, I think you are right. I was not aware of this check, thanks for 
pointing it out. That means we can get rid of position pointer reset 
from the rest of the code.. the are plenty of sysctl following this 
pattern. I will prepare a batch for net-next.

I am sending a v3 dropping this patch.

Thank you Ido!

>>   
>>   		WRITE_ONCE(*valp, new_val);
>>   
>> @@ -6851,8 +6853,6 @@ static int addrconf_sysctl_force_forwarding(const struct ctl_table *ctl, int wri
>>   		rtnl_net_unlock(net);
>>   	}
>>   
>> -	if (ret)
>> -		*ppos = pos;
>>   	return ret;
>>   }
>>   
>> -- 
>> 2.54.0
>>


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

end of thread, other threads:[~2026-06-22 12:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-20 16:18 [PATCH net v2 0/7] ipv6: fix sysctl error handling and missing notifications Fernando Fernandez Mancera
2026-06-20 16:18 ` [PATCH net v2 1/7] ipv6: fix error handling in disable_ipv6 sysctl Fernando Fernandez Mancera
2026-06-20 16:18 ` [PATCH net v2 2/7] ipv6: fix error handling in ignore_routes_with_linkdown sysctl Fernando Fernandez Mancera
2026-06-20 16:18 ` [PATCH net v2 3/7] ipv6: fix error handling in forwarding sysctl Fernando Fernandez Mancera
2026-06-20 16:18 ` [PATCH net v2 4/7] ipv6: fix error handling in disable_policy sysctl Fernando Fernandez Mancera
2026-06-20 16:18 ` [PATCH net v2 5/7] ipv6: reset value and position for proxy_ndp sysctl restart Fernando Fernandez Mancera
2026-06-22 11:48   ` Nicolas Dichtel
2026-06-20 16:18 ` [PATCH net v2 6/7] ipv6: fix missing notification for ignore_routes_with_linkdown Fernando Fernandez Mancera
2026-06-20 16:18 ` [PATCH net v2 7/7] ipv6: reset position for force_forwarding sysctl restart Fernando Fernandez Mancera
2026-06-22 11:42   ` Ido Schimmel
2026-06-22 12:19     ` Fernando Fernandez Mancera

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox