Skip to content

Commit 49eaf14

Browse files
q2vengregkh
authored andcommitted
ipv4: fib: Don't ignore error route in local/main tables.
[ Upstream commit b72f0db ] When CONFIG_IP_MULTIPLE_TABLES is enabled but no rule is added, fib_lookup() performs route lookup directly on two tables. Since the first lookup does not properly bail out, the result of an error route in the merged local/main table could be overwritten by another route in the default table: # unshare -n # ip link set lo up # ip route add 192.168.0.0/24 dev lo table 253 # ip route add unreachable 192.168.0.0/24 # ip route get 192.168.0.1 192.168.0.1 dev lo table default uid 0 cache <local> Once a random rule is added, the error route is respected: # ip rule add table 0 # ip rule del table 0 # ip route get 192.168.0.1 RTNETLINK answers: No route to host Let's fix the inconsistent behaviour. Fixes: f4530fa ("ipv4: Avoid overhead when no custom FIB rules are installed.") Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20260619212753.3367244-1-kuniyu@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 302d57e commit 49eaf14

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

include/net/ip_fib.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ static inline int fib_lookup(struct net *net, struct flowi4 *flp,
370370
struct fib_result *res, unsigned int flags)
371371
{
372372
struct fib_table *tb;
373-
int err = -ENETUNREACH;
373+
int err = -EAGAIN;
374374

375375
flags |= FIB_LOOKUP_NOREF;
376376
if (net->ipv4.fib_has_custom_rules)
@@ -384,17 +384,16 @@ static inline int fib_lookup(struct net *net, struct flowi4 *flp,
384384
if (tb)
385385
err = fib_table_lookup(tb, flp, res, flags);
386386

387-
if (!err)
387+
if (err != -EAGAIN)
388388
goto out;
389389

390390
tb = rcu_dereference_rtnl(net->ipv4.fib_default);
391391
if (tb)
392392
err = fib_table_lookup(tb, flp, res, flags);
393393

394-
out:
395394
if (err == -EAGAIN)
396395
err = -ENETUNREACH;
397-
396+
out:
398397
rcu_read_unlock();
399398

400399
return err;

0 commit comments

Comments
 (0)