Skip to content

Commit 9ebedde

Browse files
committed
rxrpc: rxrpc_peer needs to hold a ref on the rxrpc_local record
The rxrpc_peer record needs to hold a reference on the rxrpc_local record it points as the peer is used as a base to access information in the rxrpc_local record. This can cause problems in __rxrpc_put_peer(), where we need the network namespace pointer, and in rxrpc_send_keepalive(), where we need to access the UDP socket, leading to symptoms like: BUG: KASAN: use-after-free in __rxrpc_put_peer net/rxrpc/peer_object.c:411 [inline] BUG: KASAN: use-after-free in rxrpc_put_peer+0x685/0x6a0 net/rxrpc/peer_object.c:435 Read of size 8 at addr ffff888097ec0058 by task syz-executor823/24216 Fix this by taking a ref on the local record for the peer record. Fixes: ace45be ("rxrpc: Fix firewall route keepalive") Fixes: 2baec2c ("rxrpc: Support network namespacing") Reported-by: [email protected] Signed-off-by: David Howells <[email protected]>
1 parent 48c9e0e commit 9ebedde

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

net/rxrpc/peer_object.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *local, gfp_t gfp)
216216
peer = kzalloc(sizeof(struct rxrpc_peer), gfp);
217217
if (peer) {
218218
atomic_set(&peer->usage, 1);
219-
peer->local = local;
219+
peer->local = rxrpc_get_local(local);
220220
INIT_HLIST_HEAD(&peer->error_targets);
221221
peer->service_conns = RB_ROOT;
222222
seqlock_init(&peer->service_conn_lock);
@@ -307,7 +307,6 @@ void rxrpc_new_incoming_peer(struct rxrpc_sock *rx, struct rxrpc_local *local,
307307
unsigned long hash_key;
308308

309309
hash_key = rxrpc_peer_hash_key(local, &peer->srx);
310-
peer->local = local;
311310
rxrpc_init_peer(rx, peer, hash_key);
312311

313312
spin_lock(&rxnet->peer_hash_lock);
@@ -417,6 +416,7 @@ static void __rxrpc_put_peer(struct rxrpc_peer *peer)
417416
list_del_init(&peer->keepalive_link);
418417
spin_unlock_bh(&rxnet->peer_hash_lock);
419418

419+
rxrpc_put_local(peer->local);
420420
kfree_rcu(peer, rcu);
421421
}
422422

@@ -453,6 +453,7 @@ void rxrpc_put_peer_locked(struct rxrpc_peer *peer)
453453
if (n == 0) {
454454
hash_del_rcu(&peer->hash_link);
455455
list_del_init(&peer->keepalive_link);
456+
rxrpc_put_local(peer->local);
456457
kfree_rcu(peer, rcu);
457458
}
458459
}

0 commit comments

Comments
 (0)