Skip to content

Commit d514fd9

Browse files
committed
rxrpc: Fix rxrpc_local leak in rxrpc_lookup_peer()
jira LE-1907 Rebuild_History Non-Buildable kernel-rt-5.14.0-284.30.1.rt14.315.el9_2 commit-author Eiichi Tsukata <[email protected]> commit beacff5 Need to call rxrpc_put_local() for peer candidate before kfree() as it holds a ref to rxrpc_local. [DH: v2: Changed to abstract the peer freeing code out into a function] Fixes: 9ebedde ("rxrpc: rxrpc_peer needs to hold a ref on the rxrpc_local record") Signed-off-by: Eiichi Tsukata <[email protected]> Signed-off-by: David Howells <[email protected]> Reviewed-by: Marc Dionne <[email protected]> cc: [email protected] Link: https://lore.kernel.org/all/[email protected]/ # v1 (cherry picked from commit beacff5) Signed-off-by: Jonathan Maple <[email protected]>
1 parent b4c94da commit d514fd9

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

net/rxrpc/peer_object.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ static struct rxrpc_peer *rxrpc_create_peer(struct rxrpc_sock *rx,
299299
return peer;
300300
}
301301

302+
static void rxrpc_free_peer(struct rxrpc_peer *peer)
303+
{
304+
rxrpc_put_local(peer->local);
305+
kfree_rcu(peer, rcu);
306+
}
307+
302308
/*
303309
* Set up a new incoming peer. There shouldn't be any other matching peers
304310
* since we've already done a search in the list from the non-reentrant context
@@ -365,7 +371,7 @@ struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_sock *rx,
365371
spin_unlock_bh(&rxnet->peer_hash_lock);
366372

367373
if (peer)
368-
kfree(candidate);
374+
rxrpc_free_peer(candidate);
369375
else
370376
peer = candidate;
371377
}
@@ -420,8 +426,7 @@ static void __rxrpc_put_peer(struct rxrpc_peer *peer)
420426
list_del_init(&peer->keepalive_link);
421427
spin_unlock_bh(&rxnet->peer_hash_lock);
422428

423-
rxrpc_put_local(peer->local);
424-
kfree_rcu(peer, rcu);
429+
rxrpc_free_peer(peer);
425430
}
426431

427432
/*
@@ -457,8 +462,7 @@ void rxrpc_put_peer_locked(struct rxrpc_peer *peer)
457462
if (n == 0) {
458463
hash_del_rcu(&peer->hash_link);
459464
list_del_init(&peer->keepalive_link);
460-
rxrpc_put_local(peer->local);
461-
kfree_rcu(peer, rcu);
465+
rxrpc_free_peer(peer);
462466
}
463467
}
464468

0 commit comments

Comments
 (0)