ipv6: advance the serial after rebalancing in fib6_ifup and fib6_ifdown
Subsystems (3)
PATCH 1/1 ipv6: advance the serial after rebalancing in fib6_ifup and fib6_ifdown
fib6_ifup and fib6_ifdown update the node serial before calling rt6_multipath_rebalance. A lookup that runs between the two can select a nexthop using the old ECMP upper bounds and read the new serial as its cookie. The cached dst then passes dst_check although it was selected from the old state, until the next relevant change.
Update the serial after rt6_multipath_rebalance, so that it is published only after the routing state it describes. fib6_new_sernum allocates the serial with a fully ordered atomic_try_cmpxchg, which orders the rebalance before the serial update. The invalidation scope is unchanged:fib6_ifup still updates the node and its ancestors, fib6_ifdown only the node.
Validating dsts against the generation sampled before the lookup, as proposed in "ipv6: validate cached dsts against the netns route generation", relies on this order as well: a lookup that reads the new generation must also observe the routing change it describes.
Reported by Sashiko while reviewing an earlier version of this change.
---
Split out of v5 of "ipv6: tie dst validation to the lookup that returned the dst", which is withdrawn in favour of the series in the Link above:
https://lore.kernel.org/netdev/[email protected]/
net/ipv6/route.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/ipv6/route.c +3 -3
@@ -4911,8 +4911,8 @@ static int fib6_ifup(struct fib6_info *rt, void *p_arg)if (rt != net->ipv6.fib6_null_entry && !rt->nh && rt->fib6_nh->fib_nh_dev == arg->dev) { rt->fib6_nh->fib_nh_flags &= ~arg->nh_flags; -fib6_update_sernum_upto_root (net, rt);rt6_multipath_rebalance (rt); +fib6_update_sernum_upto_root (net, rt); }return 0 ;
@@ -5015,8 +5015,8 @@ static int fib6_ifdown(struct fib6_info *rt, void *p_arg) }rt6_multipath_nh_flags_set (rt, dev,RTNH_F_DEAD |RTNH_F_LINKDOWN ); -fib6_update_sernum (net, rt);rt6_multipath_rebalance (rt); +fib6_update_sernum (net, rt); }return -2 ;case NETDEV_CHANGE :
@@ -5024,8 +5024,8 @@ static int fib6_ifdown(struct fib6_info *rt, void *p_arg) rt->fib6_flags & (RTF_LOCAL | RTF_ANYCAST)) break; rt->fib6_nh->fib_nh_flags |=RTNH_F_LINKDOWN ; -fib6_update_sernum (net, rt);rt6_multipath_rebalance (rt); +fib6_update_sernum (net, rt);break ; }
base-commit: ef3e21c61baa74e39a49b75318bd4541562ec43f
Signature · 1 line
2.56.0
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Quoted 9 lines · On Thu, 26 Nov 2026 08:18:35 +0000, [email protected] wrote:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.
Quoted 10 lines
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
I've actually specified this in the commit message:
Reported by Sashiko while reviewing an earlier version of this change.
Signature · 2 lines
Ralf Lici Mandelbit Srl
Quoted 25 lines · Ralf Lici
fib6_ifupandfib6_ifdownupdate the node serial before callingrt6_multipath_rebalance. A lookup that runs between the two can select a nexthop using the old ECMP upper bounds and read the new serial as its cookie. The cached dst then passesdst_checkalthough it was selected from the old state, until the next relevant change.Update the serial after
rt6_multipath_rebalance, so that it is published only after the routing state it describes.fib6_new_sernumallocates the serial with a fully orderedatomic_try_cmpxchg, which orders the rebalance before the serial update. The invalidation scope is unchanged:fib6_ifupstill updates the node and its ancestors,fib6_ifdownonly the node.Validating dsts against the generation sampled before the lookup, as proposed in "ipv6: validate cached dsts against the netns route generation", relies on this order as well: a lookup that reads the new generation must also observe the routing change it describes.
Reported by Sashiko while reviewing an earlier version of this change.
Fixes d7dedee184e7 ("ipv6: Calculate hash thresholds for IPv6 nexthops")Fixes 4bc852006b62 ("ipv6: update route serial number on NETDEV_CHANGE")Signed-off-by Ralf Lici <[email protected]>Reviewed-by Xia Yan <[email protected]>
Quoted 9 lines
---
Split out of v5 of "ipv6: tie dst validation to the lookup that returned the dst", which is withdrawn in favour of the series in the Link above:
https://lore.kernel.org/netdev/[email protected]/net/ipv6/route.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] Moving fib6_update_sernum()/fib6_update_sernum_upto_root() after rt6_multipath_rebalance() in fib6_ifup() and fib6_ifdown() makes…
--
ipv6: advance the serial after rebalancing in fib6_ifup and fib6_ifdown
This patch moves the fn_sernum update in fib6_ifup() and fib6_ifdown() so it happens after rt6_multipath_rebalance(). The new serial is then published only after the ECMP upper bounds it describes. The fully ordered atomic_try_cmpxchg() in fib6_new_sernum() orders the rebalance before the serial store.
Quoted 4 lines
net/ipv6/route.c +0
-0
[ ... ]
net/ipv6/route.c static int fib6_ifdown(struct fib6_info *rt, void *p_arg) · line 5021
Quoted 9 lines
net/ipv6/route.c +1
-1@@ -5015,8 +5015,8 @@ static int fib6_ifdown(struct fib6_info *rt, void *p_arg) }rt6_multipath_nh_flags_set (rt, dev,RTNH_F_DEAD |RTNH_F_LINKDOWN ); -fib6_update_sernum (net, rt);rt6_multipath_rebalance (rt); +fib6_update_sernum (net, rt); }return -2 ;
[Severity: Medium]
Does this reorder close the race, or does it only make the window smaller?
Some multipath routes do not use nexthop objects (rt->nh == NULL). For those, ip6_rt_pcpu_alloc() leaves pcpu_rt->sernum at 0:
net/ipv6/route.c:ip6_rt_pcpu_alloc() {
...
if (f6i->nh)
pcpu_rt->sernum = rt_genid_ipv6(dev_net(dev));
...
}The cookie therefore comes from fn->fn_sernum through rt6_get_cookie()->fib6_get_cookie_safe(). It is read only after the lookup has finished, for example in ip6_dst_store():
np->dst_cookie = rt6_get_cookie(dst_rt6_info(dst));
inet6_sk_rx_dst_set(), udp6_sk_rx_dst_set() and xfrm6_fill_dst() also read the cookie after the dst has been selected.
Before that, the lookup reads the nexthop state without the lock, in fib6_select_path() and in rt6_score_route():
if (hash <= atomic_read(&first->fib6_nh->fib_nh_upper_bound)) {So the reader reads upper_bound and flags first, then fn_sernum. With this patch the writer stores flags and upper_bound, issues a full barrier, then stores fn_sernum. That order only pairs with a reader that reads the serial first.
The smp_rmb() in fib6_get_cookie_safe() comes after the fn_sernum read. It cannot order the earlier upper bound reads.
Can this interleaving still happen?
CPU0 (connect()) CPU1 (fib6_ifdown(), NETDEV_DOWN)fib6_select_path()
selects sibling A with
old upper bounds/flags
rt6_multipath_nh_flags_set()
A |= RTNH_F_DEAD | RTNH_F_LINKDOWN
rt6_multipath_rebalance() fib6_update_sernum()
fn_sernum = N + 1ip6_dst_store()
np->dst_cookie = N + 1
Later, ip6_dst_check()->rt6_dst_from_check()->fib6_check() compares N + 1 with N + 1. It accepts the cached dst for the dead nexthop A.
The NETDEV_CHANGE path in fib6_ifdown() has the same ordering. So does fib6_ifup() with fib6_update_sernum_upto_root().
The commit message says:
The cached dst then passes dst_check although it was selected from the old state, until the next relevant change.
That outcome looks reachable whenever a lookup overlaps both writes. The patch only removes the case where the whole lookup falls between the serial bump and the rebalance.
A full fix seems to need the reader to sample the generation before the lookup. The separately proposed "ipv6: validate cached dsts against the netns route generation" series does that.
This patch carries Fixes: tags and may be backported without that series. Could the commit message say that the patch narrows the window rather than closes it?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126081353.55240-1-ralf%40mandelbit.com
Quoted 18 lines · Ralf Lici
fib6_ifupandfib6_ifdownupdate the node serial before callingrt6_multipath_rebalance. A lookup that runs between the two can select a nexthop using the old ECMP upper bounds and read the new serial as its cookie. The cached dst then passesdst_checkalthough it was selected from the old state, until the next relevant change.Update the serial after
rt6_multipath_rebalance, so that it is published only after the routing state it describes.fib6_new_sernumallocates the serial with a fully orderedatomic_try_cmpxchg, which orders the rebalance before the serial update. The invalidation scope is unchanged:fib6_ifupstill updates the node and its ancestors,fib6_ifdownonly the node.Validating dsts against the generation sampled before the lookup, as proposed in "ipv6: validate cached dsts against the netns route generation", relies on this order as well: a lookup that reads the new generation must also observe the routing change it describes.
Quoted 7 lines
Reported by Sashiko while reviewing an earlier version of this change.
Fixes d7dedee184e7 ("ipv6: Calculate hash thresholds for IPv6 nexthops")Fixes 4bc852006b62 ("ipv6: update route serial number on NETDEV_CHANGE")Signed-off-by Ralf Lici <[email protected]>Reviewed-by Xia Yan <[email protected]>
Didn't receive Sashiko's review [1] by email this time and it's not on the list either, not sure why.
Sashiko asks whether the reorder closes the race or only narrows it.
It closes the case described in the commit message: a lookup that runs entirely between the serial update and the rebalance. A lookup that selects its nexthop before both writes and reads the cookie after them is the late cookie sampling race in general, which this patch does not address on its own. The series in the Link closes it by sampling the generation before the lookup, and relies on this order to do so, as the third paragraph says.
I don't think this needs a respin, but I can send a v2 if you'd prefer the commit message to say this explicitly.
[1] https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126081353.55240-1-ralf%40mandelbit.com
Signature · 2 lines
Ralf Lici Mandelbit Srl