From: Ido Schimmel <idosch@nvidia.com>
To: Zihan Xi <zihanx@nebusec.ai>
Cc: netdev@vger.kernel.org, horms@kernel.org, davem@davemloft.net,
pch@ordbogen.com, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, Vega <vega@nebusec.ai>
Subject: Re: [PATCH net 1/1] ipv4: Fix fib_rebalance() divide-by-zero race
Date: Wed, 19 Aug 2026 18:31:09 +0300 [thread overview]
Message-ID: <20260819153109.GB1248049@shredder> (raw)
In-Reply-To: <2080e22819c552b0d186563eda255a44c68404f7.1786812660.git.zihanx@nebusec.ai>
On Mon, Aug 17, 2026 at 01:12:10PM +0000, Zihan Xi wrote:
> fib_rebalance() reads ignore_routes_with_linkdown while summing active
> nexthop weights and then reads it again while calculating each upper
> bound. Sysctl writes are not serialized by RTNL. If all nexthops are
> link-down, a concurrent 1-to-0 change can leave total at zero and make
> the second pass divide by zero.
>
> Route insertion and link-state updates call fib_rebalance() under RTNL,
> and netlink devconf changes are already protected by RTNL. Make the
> sysctl handler take the per-net RTNL lock before changing
> ignore_routes_with_linkdown. This gives both passes a stable policy view
> without adding work to route lookup or rebalance paths.
>
> Fixes: 0e884c78ee19 ("ipv4: L3 hash-based multipath")
> Cc: stable@vger.kernel.org
> Reported-by: Vega <vega@nebusec.ai>
> Assisted-by: Codex:gpt-5.4
> Signed-off-by: Zihan Xi <zihanx@nebusec.ai>
I think that this is a better direction:
https://lore.kernel.org/netdev/20260817013237.2797-1-blbllhy@gmail.com/
Instead of taking RTNL, make it consistent with IPv6 and mark all the
nexthops as dead (upper_bound = -1) when total==0, as the first pass
indicated. Something like [1].
It's true that it can lead to incorrect upper bounds if a concurrent
1-to-0 change didn't result in total==0: during the second pass we will
account for nexthops that we skipped in the first pass.
It's not very interesting. This sysctl was never meant to be configured
on the fly and the kernel doesn't rebalance nexthop groups when it is
toggled.
Let's wait for the IPv6 patch to be applied so that you could reference
it in the commit message.
[1]
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index 0483519b7fb0..7a362f2e2c2b 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -874,7 +874,7 @@ static void fib_rebalance(struct fib_info *fi)
change_nexthops(fi) {
int upper_bound;
- if (nexthop_nh->fib_nh_flags & RTNH_F_DEAD) {
+ if (!total || nexthop_nh->fib_nh_flags & RTNH_F_DEAD) {
upper_bound = -1;
} else if (ip_ignore_linkdown(nexthop_nh->fib_nh_dev) &&
nexthop_nh->fib_nh_flags & RTNH_F_LINKDOWN) {
next prev parent reply other threads:[~2026-08-19 15:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 13:12 [PATCH net 0/1] ipv4: Fix fib_rebalance() divide-by-zero race Zihan Xi
2026-08-17 13:12 ` [PATCH net 1/1] " Zihan Xi
2026-08-19 15:31 ` Ido Schimmel [this message]
2026-08-19 15:48 ` zihan xi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260819153109.GB1248049@shredder \
--to=idosch@nvidia.com \
--cc=davem@davemloft.net \
--cc=horms@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pch@ordbogen.com \
--cc=stable@vger.kernel.org \
--cc=vega@nebusec.ai \
--cc=zihanx@nebusec.ai \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox