* [PATCH net] ipv4: fib: free fib_alias with kfree_rcu() on insert error path
@ 2026-07-04 17:14 Weiming Shi
2026-07-05 8:00 ` Ido Schimmel
0 siblings, 1 reply; 2+ messages in thread
From: Weiming Shi @ 2026-07-04 17:14 UTC (permalink / raw)
To: netdev
Cc: dsahern, idosch, edumazet, kuba, pabeni, davem, horms, xmei5,
linux-kernel, Weiming Shi
fib_table_insert() publishes new_fa into the leaf's fa_list with
fib_insert_alias() before calling the fib entry notifiers. When a
notifier fails, the error path removes new_fa with fib_remove_alias()
(hlist_del_rcu) and frees it right away with kmem_cache_free().
fib_table_lookup() walks that list under rcu_read_lock() only, so a
concurrent lookup that already reached new_fa keeps reading it after the
free:
BUG: KASAN: slab-use-after-free in fib_table_lookup (net/ipv4/fib_trie.c:1601)
Read of size 1 at addr ffff88810676d4eb by task exploit/297
Call Trace:
fib_table_lookup (net/ipv4/fib_trie.c:1601)
ip_route_output_key_hash_rcu (net/ipv4/route.c:2814)
ip_route_output_key_hash (net/ipv4/route.c:2705)
__ip4_datagram_connect (net/ipv4/datagram.c:49)
udp_connect (net/ipv4/udp.c:2144)
__sys_connect (net/socket.c:2167)
__x64_sys_connect (net/socket.c:2173)
do_syscall_64
entry_SYSCALL_64_after_hwframe
which belongs to the cache ip_fib_alias of size 56
Triggering the error path needs CAP_NET_ADMIN and a registered fib
notifier that can reject a route; a netdevsim device whose IPv4 FIB
resource is exhausted is enough.
Free new_fa with alias_free_mem_rcu(), as fib_table_delete() already
does for a fib_alias removed from the trie.
Fixes: a6c76c17df02 ("ipv4: Notify route after insertion to the routing table")
Reported-by: Xiang Mei <xmei5@asu.edu>
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Weiming Shi <bestswngs@gmail.com>
---
net/ipv4/fib_trie.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 1308213791f1..2dc87e2156d3 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -1385,7 +1385,7 @@ int fib_table_insert(struct net *net, struct fib_table *tb,
out_remove_new_fa:
fib_remove_alias(t, tp, l, new_fa);
out_free_new_fa:
- kmem_cache_free(fn_alias_kmem, new_fa);
+ alias_free_mem_rcu(new_fa);
out:
fib_release_info(fi);
err:
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] ipv4: fib: free fib_alias with kfree_rcu() on insert error path
2026-07-04 17:14 [PATCH net] ipv4: fib: free fib_alias with kfree_rcu() on insert error path Weiming Shi
@ 2026-07-05 8:00 ` Ido Schimmel
0 siblings, 0 replies; 2+ messages in thread
From: Ido Schimmel @ 2026-07-05 8:00 UTC (permalink / raw)
To: Weiming Shi
Cc: netdev, dsahern, edumazet, kuba, pabeni, davem, horms, xmei5,
linux-kernel
On Sat, Jul 04, 2026 at 10:14:21AM -0700, Weiming Shi wrote:
> fib_table_insert() publishes new_fa into the leaf's fa_list with
> fib_insert_alias() before calling the fib entry notifiers. When a
> notifier fails, the error path removes new_fa with fib_remove_alias()
> (hlist_del_rcu) and frees it right away with kmem_cache_free().
>
> fib_table_lookup() walks that list under rcu_read_lock() only, so a
> concurrent lookup that already reached new_fa keeps reading it after the
> free:
>
> BUG: KASAN: slab-use-after-free in fib_table_lookup (net/ipv4/fib_trie.c:1601)
> Read of size 1 at addr ffff88810676d4eb by task exploit/297
> Call Trace:
> fib_table_lookup (net/ipv4/fib_trie.c:1601)
> ip_route_output_key_hash_rcu (net/ipv4/route.c:2814)
> ip_route_output_key_hash (net/ipv4/route.c:2705)
> __ip4_datagram_connect (net/ipv4/datagram.c:49)
> udp_connect (net/ipv4/udp.c:2144)
> __sys_connect (net/socket.c:2167)
> __x64_sys_connect (net/socket.c:2173)
> do_syscall_64
> entry_SYSCALL_64_after_hwframe
> which belongs to the cache ip_fib_alias of size 56
>
> Triggering the error path needs CAP_NET_ADMIN and a registered fib
> notifier that can reject a route; a netdevsim device whose IPv4 FIB
> resource is exhausted is enough.
>
> Free new_fa with alias_free_mem_rcu(), as fib_table_delete() already
> does for a fib_alias removed from the trie.
>
> Fixes: a6c76c17df02 ("ipv4: Notify route after insertion to the routing table")
> Reported-by: Xiang Mei <xmei5@asu.edu>
> Assisted-by: Claude:claude-opus-4-8
> Signed-off-by: Weiming Shi <bestswngs@gmail.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-05 8:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-04 17:14 [PATCH net] ipv4: fib: free fib_alias with kfree_rcu() on insert error path Weiming Shi
2026-07-05 8:00 ` Ido Schimmel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox