Skip to content

Commit 598dbba

Browse files
V4belVudentz
authored andcommitted
Bluetooth: SCO: Fix use-after-free in sco_recv_frame() due to missing sock_hold
sco_recv_frame() reads conn->sk under sco_conn_lock() but immediately releases the lock without holding a reference to the socket. A concurrent close() can free the socket between the lock release and the subsequent sk->sk_state access, resulting in a use-after-free. Other functions in the same file (sco_sock_timeout(), sco_conn_del()) correctly use sco_sock_hold() to safely hold a reference under the lock. Fix by using sco_sock_hold() to take a reference before releasing the lock, and adding sock_put() on all exit paths. Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Hyunwoo Kim <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent c65bd94 commit 598dbba

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

net/bluetooth/sco.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ static void sco_recv_frame(struct sco_conn *conn, struct sk_buff *skb)
401401
struct sock *sk;
402402

403403
sco_conn_lock(conn);
404-
sk = conn->sk;
404+
sk = sco_sock_hold(conn);
405405
sco_conn_unlock(conn);
406406

407407
if (!sk)
@@ -410,11 +410,15 @@ static void sco_recv_frame(struct sco_conn *conn, struct sk_buff *skb)
410410
BT_DBG("sk %p len %u", sk, skb->len);
411411

412412
if (sk->sk_state != BT_CONNECTED)
413-
goto drop;
413+
goto drop_put;
414414

415-
if (!sock_queue_rcv_skb(sk, skb))
415+
if (!sock_queue_rcv_skb(sk, skb)) {
416+
sock_put(sk);
416417
return;
418+
}
417419

420+
drop_put:
421+
sock_put(sk);
418422
drop:
419423
kfree_skb(skb);
420424
}

0 commit comments

Comments
 (0)