The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] ipv6: keep fib6 node serials from going backwards
@ 2026-12-04 11:28 Ralf Lici
  2026-12-04 11:28 ` [PATCH net-next 1/2] ipv6: stamp the default route node with a fresh serial on link failure Ralf Lici
  2026-12-04 11:28 ` [PATCH net-next 2/2] ipv6: allocate the flush serial under each table's lock Ralf Lici
  0 siblings, 2 replies; 3+ messages in thread
From: Ralf Lici @ 2026-12-04 11:28 UTC (permalink / raw)
  To: netdev
  Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
	linux-kernel, Antonio Quartulli

Hi,

Two writers can give a fib6 node a serial older than the one it had,
or one that fib6_new_sernum never allocates: ip6_link_failure writes -1
into the node of a default route, and fib6_flush_trees allocates its
serial before walking the tables, so it can overwrite a newer serial
stamped by a concurrent route change.

Validating dsts by comparing serials by age, as Ido suggested [1],
needs node serials to only move forward, so both writers have to be
fixed before the respin of "ipv6: tie dst validation to the lookup that
returned the dst" [2].

Patch 1 stamps the default route node with a fresh serial on link
failure, and patch 2 allocates the flush serial under each table's
lock.

[1] https://lore.kernel.org/netdev/20261203153447.GA3201592@shredder/
[2] https://lore.kernel.org/netdev/cover.1795537128.git.ralf@mandelbit.com/

Thanks,

Ralf Lici
Mandelbit Srl

---
Changes since v5 of "ipv6: tie dst validation to the lookup that returned the dst" [2]
- Send 1/4 separately, without the Fixes tag. (Ido)
- Add the fib6_flush_trees fix. (Ido)

Ralf Lici (2):
  ipv6: stamp the default route node with a fresh serial on link failure
  ipv6: allocate the flush serial under each table's lock

 net/ipv6/ip6_fib.c | 13 ++++++++-----
 net/ipv6/route.c   | 18 ++++++++++--------
 2 files changed, 18 insertions(+), 13 deletions(-)


base-commit: 8a3d0368f58e34e34d402718c7655811902a6bd4
-- 
2.56.1


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

* [PATCH net-next 1/2] ipv6: stamp the default route node with a fresh serial on link failure
  2026-12-04 11:28 [PATCH net-next 0/2] ipv6: keep fib6 node serials from going backwards Ralf Lici
@ 2026-12-04 11:28 ` Ralf Lici
  2026-12-04 11:28 ` [PATCH net-next 2/2] ipv6: allocate the flush serial under each table's lock Ralf Lici
  1 sibling, 0 replies; 3+ messages in thread
From: Ralf Lici @ 2026-12-04 11:28 UTC (permalink / raw)
  To: netdev
  Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
	linux-kernel, Antonio Quartulli

ip6_link_failure invalidates the cached dsts of an RTF_DEFAULT route by
writing -1 into the node's fn_sernum. Once the node already holds -1,
another link failure leaves the serial unchanged, so dsts cached with
that cookie can survive subsequent failures. The assignment also leaves
net->ipv6.fib6_sernum unchanged, and -1 is outside the range that
fib6_new_sernum allocates from, so the serial cannot be ordered against
the namespace generation.

Use fib6_update_sernum under tb6_lock to allocate and stamp a fresh
serial instead.

Advancing the namespace generation also invalidates unrelated dsts using
nexthop objects, which are validated against that generation. This
happens once per ip6_link_failure call: once per queued skb when the
neighbour of the default router fails, and once per packet on the
tunnel transmit error paths that call dst_link_failure, some of which a
remote host can trigger with ICMP errors. These are error paths and add
no cost to the fast path.

This is a preparation for validating dsts by comparing serials by age,
which needs every node serial to come from fib6_new_sernum.

Signed-off-by: Ralf Lici <ralf@mandelbit.com>
---
 net/ipv6/route.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index d3c77941d2cf..b641df277483 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1532,9 +1532,11 @@ static struct rt6_info *rt6_make_pcpu_route(struct net *net,
  */
 static DEFINE_SPINLOCK(rt6_exception_lock);
 
-/* Exceptions are accounted to the netns their dst was allocated in.
- * Unlike dev_net(dst->dev), it does not change when the device moves to
- * another netns or when dst_dev_put() points the dst to blackhole_netdev.
+/* Return the netns the dst was allocated in, which owns the fib6 table of
+ * its route. Exceptions are accounted to it, and ip6_link_failure advances
+ * its generation. Unlike dev_net(dst->dev), it does not change when the
+ * device moves to another netns or when dst_dev_put() points the dst to
+ * blackhole_netdev.
  */
 static struct net *rt6_exception_net(const struct rt6_info *rt)
 {
@@ -2874,13 +2876,13 @@ static void ip6_link_failure(struct sk_buff *skb)
 			rt6_remove_exception_rt(rt);
 		} else {
 			struct fib6_info *from;
-			struct fib6_node *fn;
 
 			from = rcu_dereference(rt->from);
-			if (from) {
-				fn = rcu_dereference(from->fib6_node);
-				if (fn && (rt->rt6i_flags & RTF_DEFAULT))
-					WRITE_ONCE(fn->fn_sernum, -1);
+			if (from && from->fib6_table &&
+			    (rt->rt6i_flags & RTF_DEFAULT)) {
+				spin_lock_bh(&from->fib6_table->tb6_lock);
+				fib6_update_sernum(rt6_exception_net(rt), from);
+				spin_unlock_bh(&from->fib6_table->tb6_lock);
 			}
 		}
 		rcu_read_unlock();
-- 
2.56.1


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

* [PATCH net-next 2/2] ipv6: allocate the flush serial under each table's lock
  2026-12-04 11:28 [PATCH net-next 0/2] ipv6: keep fib6 node serials from going backwards Ralf Lici
  2026-12-04 11:28 ` [PATCH net-next 1/2] ipv6: stamp the default route node with a fresh serial on link failure Ralf Lici
@ 2026-12-04 11:28 ` Ralf Lici
  1 sibling, 0 replies; 3+ messages in thread
From: Ralf Lici @ 2026-12-04 11:28 UTC (permalink / raw)
  To: netdev
  Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
	linux-kernel, Antonio Quartulli

fib6_flush_trees allocates one serial and then walks the tables with
__fib6_clean_all, which takes each table's tb6_lock in turn. A route
change in a table the walk has not reached yet stamps its nodes with a
newer serial, which the walk then overwrites with the older one, so the
node's serial goes backwards.

Allocate a fresh serial for each table once its tb6_lock is held, so
that no writer can stamp a newer serial in that table before the walk
does.

This is a preparation for validating dsts by comparing serials by age,
which needs node serials never to go backwards.

Signed-off-by: Ralf Lici <ralf@mandelbit.com>
---
 net/ipv6/ip6_fib.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index c2ed54d39f9d..7a31490890d3 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -139,6 +139,8 @@ static int fib6_new_sernum(struct net *net)
 
 enum {
 	FIB6_NO_SERNUM_CHANGE = 0,
+	/* A fresh serial for each table, allocated under its tb6_lock */
+	FIB6_NEW_SERNUM = -1,
 };
 
 void fib6_update_sernum(struct net *net, struct fib6_info *f6i)
@@ -2337,6 +2339,7 @@ static void __fib6_clean_all(struct net *net,
 {
 	struct fib6_table *table;
 	struct hlist_head *head;
+	int table_sn = sernum;
 	unsigned int h;
 
 	rcu_read_lock();
@@ -2344,8 +2347,10 @@ static void __fib6_clean_all(struct net *net,
 		head = &net->ipv6.fib_table_hash[h];
 		hlist_for_each_entry_rcu(table, head, tb6_hlist) {
 			spin_lock_bh(&table->tb6_lock);
-			fib6_clean_tree(net, &table->tb6_root,
-					func, sernum, arg, skip_notify);
+			if (sernum == FIB6_NEW_SERNUM)
+				table_sn = fib6_new_sernum(net);
+			fib6_clean_tree(net, &table->tb6_root, func,
+					table_sn, arg, skip_notify);
 			spin_unlock_bh(&table->tb6_lock);
 		}
 	}
@@ -2367,9 +2372,7 @@ void fib6_clean_all_skip_notify(struct net *net,
 
 static void fib6_flush_trees(struct net *net)
 {
-	int new_sernum = fib6_new_sernum(net);
-
-	__fib6_clean_all(net, NULL, new_sernum, NULL, false);
+	__fib6_clean_all(net, NULL, FIB6_NEW_SERNUM, NULL, false);
 }
 
 /*
-- 
2.56.1


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

end of thread, other threads:[~2026-12-04 11:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 11:28 [PATCH net-next 0/2] ipv6: keep fib6 node serials from going backwards Ralf Lici
2026-12-04 11:28 ` [PATCH net-next 1/2] ipv6: stamp the default route node with a fresh serial on link failure Ralf Lici
2026-12-04 11:28 ` [PATCH net-next 2/2] ipv6: allocate the flush serial under each table's lock Ralf Lici

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