Skip to content

Commit 5fdc233

Browse files
committed
Merge tag 'rxrpc-fixes-20211129' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs
David Howells says: ==================== rxrpc: Leak fixes Here are a couple of fixes for leaks in AF_RXRPC: (1) Fix a leak of rxrpc_peer structs in rxrpc_look_up_bundle(). (2) Fix a leak of rxrpc_local structs in rxrpc_lookup_peer(). * tag 'rxrpc-fixes-20211129' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs: rxrpc: Fix rxrpc_local leak in rxrpc_lookup_peer() rxrpc: Fix rxrpc_peer leak in rxrpc_look_up_bundle() ==================== Link: https://lore.kernel.org/r/163820097905.226370.17234085194655347888.stgit@warthog.procyon.org.uk Signed-off-by: Jakub Kicinski <[email protected]>
2 parents cbd92e7 + beacff5 commit 5fdc233

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

net/rxrpc/conn_client.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,20 @@ struct rxrpc_bundle *rxrpc_get_bundle(struct rxrpc_bundle *bundle)
135135
return bundle;
136136
}
137137

138+
static void rxrpc_free_bundle(struct rxrpc_bundle *bundle)
139+
{
140+
rxrpc_put_peer(bundle->params.peer);
141+
kfree(bundle);
142+
}
143+
138144
void rxrpc_put_bundle(struct rxrpc_bundle *bundle)
139145
{
140146
unsigned int d = bundle->debug_id;
141147
unsigned int u = atomic_dec_return(&bundle->usage);
142148

143149
_debug("PUT B=%x %u", d, u);
144-
if (u == 0) {
145-
rxrpc_put_peer(bundle->params.peer);
146-
kfree(bundle);
147-
}
150+
if (u == 0)
151+
rxrpc_free_bundle(bundle);
148152
}
149153

150154
/*
@@ -328,7 +332,7 @@ static struct rxrpc_bundle *rxrpc_look_up_bundle(struct rxrpc_conn_parameters *c
328332
return candidate;
329333

330334
found_bundle_free:
331-
kfree(candidate);
335+
rxrpc_free_bundle(candidate);
332336
found_bundle:
333337
rxrpc_get_bundle(bundle);
334338
spin_unlock(&local->client_bundles_lock);

net/rxrpc/peer_object.c

Lines changed: 9 additions & 5 deletions
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)