Skip to content

Commit ac782f4

Browse files
idoschPaolo Abeni
authored andcommitted
ipv4: Fix reference count leak when using error routes with nexthop objects
When a nexthop object is deleted, it is marked as dead and then fib_table_flush() is called to flush all the routes that are using the dead nexthop. The current logic in fib_table_flush() is to only flush error routes (e.g., blackhole) when it is called as part of network namespace dismantle (i.e., with flush_all=true). Therefore, error routes are not flushed when their nexthop object is deleted: # ip link add name dummy1 up type dummy # ip nexthop add id 1 dev dummy1 # ip route add 198.51.100.1/32 nhid 1 # ip route add blackhole 198.51.100.2/32 nhid 1 # ip nexthop del id 1 # ip route show blackhole 198.51.100.2 nhid 1 dev dummy1 As such, they keep holding a reference on the nexthop object which in turn holds a reference on the nexthop device, resulting in a reference count leak: # ip link del dev dummy1 [ 70.516258] unregister_netdevice: waiting for dummy1 to become free. Usage count = 2 Fix by flushing error routes when their nexthop is marked as dead. IPv6 does not suffer from this problem. Fixes: 493ced1 ("ipv4: Allow routes to use nexthop objects") Reported-by: Tetsuo Handa <[email protected]> Closes: https://lore.kernel.org/netdev/[email protected]/ Reported-by: [email protected] Signed-off-by: Ido Schimmel <[email protected]> Reviewed-by: David Ahern <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent fa0b198 commit ac782f4

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

net/ipv4/fib_trie.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,10 +2053,11 @@ int fib_table_flush(struct net *net, struct fib_table *tb, bool flush_all)
20532053
continue;
20542054
}
20552055

2056-
/* Do not flush error routes if network namespace is
2057-
* not being dismantled
2056+
/* When not flushing the entire table, skip error
2057+
* routes that are not marked for deletion.
20582058
*/
2059-
if (!flush_all && fib_props[fa->fa_type].error) {
2059+
if (!flush_all && fib_props[fa->fa_type].error &&
2060+
!(fi->fib_flags & RTNH_F_DEAD)) {
20602061
slen = fa->fa_slen;
20612062
continue;
20622063
}

0 commit comments

Comments
 (0)