Re: [PATCH] rxrpc: Fix use-after-free in rxrpc_destroy_all_peers()
From: Eric Dumazet
Date: Mon Aug 31 2026 - 13:08:55 EST
On Mon, Aug 31, 2026 at 4:41 PM syzbot <syzbot@xxxxxxxxxx> wrote:
>
> From: Marco Elver <elver@xxxxxxxxxx>
>
> During network namespace teardown, rxrpc_destroy_all_peers() iterates over
> the rxnet->peer_hash table to print leaked peers. However, it does so
> without holding rxnet->peer_hash_lock. This allows a race condition with
> asynchronous peer destruction, where RCU callbacks concurrently remove
> peers from the hash table and free them. When rxrpc_destroy_all_peers()
> accesses the freed peer, it results in a KASAN slab-use-after-free.
>
> BUG: KASAN: slab-use-after-free in rxrpc_destroy_all_peers+0xcc/0x150
> net/rxrpc/peer_object.c:461
> Read of size 8 at addr ffff88811089e420 by task kworker/u8:1/13
> Call Trace:
> <TASK>
> rxrpc_destroy_all_peers+0xcc/0x150 net/rxrpc/peer_object.c:461
> rxrpc_exit_net+0x7f/0xc0 net/rxrpc/net_ns.c:114
> ops_exit_list net/core/net_namespace.c:199 [inline]
> ops_undo_list+0x43d/0x8d0 net/core/net_namespace.c:252
> cleanup_net+0x572/0x810 net/core/net_namespace.c:702
> process_one_work kernel/workqueue.c:3322 [inline]
> process_scheduled_works+0xa8e/0x14e0 kernel/workqueue.c:3405
> worker_thread+0x92d/0xe10 kernel/workqueue.c:3486
> kthread+0x388/0x470 kernel/kthread.c:436
> ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
> ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
> </TASK>
>
> To fix the slab-use-after-free, acquire rxnet->peer_hash_lock with
> spin_lock_bh() while iterating over rxnet->peer_hash in
> rxrpc_destroy_all_peers().
>
> Additionally, insert rcu_barrier() in rxrpc_exit_net() prior to destroying
> peers and local endpoints. Without rcu_barrier(), rxrpc_destroy_all_peers()
> races with pending RCU callbacks that drop peer and local references,
> logging spurious leak warnings. Furthermore, this missing synchronization
> causes a downstream panic hazard in rxrpc_destroy_all_locals() because
> in-flight peer releases leave rxnet->local_endpoints populated. Calling
> rcu_barrier() ensures all pending RCU callbacks that drop peer and local
> references complete prior to leak checks and local endpoint destruction.
>
> Fixes: 17226f124038 ("rxrpc: Fix leak of rxrpc_peer objects")
> Assisted-by: Gemini:gemini-3.6-flash Gemini:gemini-3.1-pro-preview syzbot
> Reported-by: syzbot+c876adfab6362679008c@xxxxxxxxxxxxxxxxxxxxxxxxx
> Closes: https://syzkaller.appspot.com/bug?extid=c876adfab6362679008c
> Link: https://syzkaller.appspot.com/ai_job?id=7fecbeb2-cd9b-4ca2-8149-48663e20b153
> Signed-off-by: Marco Elver <elver@xxxxxxxxxx>
>
> ---
> diff --git a/net/rxrpc/net_ns.c b/net/rxrpc/net_ns.c
> index 9a9834145..c00cddfd3 100644
> --- a/net/rxrpc/net_ns.c
> +++ b/net/rxrpc/net_ns.c
> @@ -111,6 +111,11 @@ static __net_exit void rxrpc_exit_net(struct net *net)
> timer_delete_sync(&rxnet->peer_keepalive_timer);
> rxrpc_destroy_all_calls(rxnet);
> rxrpc_destroy_all_connections(rxnet);
> + /*
> + * Wait for pending RCU callbacks that drop peer and local
> + * references to avoid spurious leak warnings and panics.
> + */
> + rcu_barrier();
Hi Marco.
This rcu_barrier() is a pretty big hammer as you might guess.
Please ask your LLM to use pre_exit method in truct pernet_operations
rxrpc_net_ops
(split existing rxrpc_exit_net(struct net *net) in two parts)
pw-bot: cr