Commit 47f23a25 authored by Muhammad Bilal's avatar Muhammad Bilal Committed by Luiz Augusto von Dentz
Browse files

Bluetooth: ISO: fix UAF in iso_recv_frame



iso_recv_frame reads conn->sk under iso_conn_lock but releases the lock
before using sk, with no reference held. A concurrent iso_sock_kill()
can free sk in that window, causing use-after-free on sk->sk_state and
sock_queue_rcv_skb().

Fix by replacing the bare pointer read with iso_sock_hold(conn), which
calls sock_hold() while the spinlock is held, atomically elevating the
refcount before the lock drops. Add a drop_put label so sock_put() is
called on all exit paths where the hold succeeded.

Fixes: ccf74f23 ("Bluetooth: Add BTPROTO_ISO socket type")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarMuhammad Bilal <meatuni001@gmail.com>
Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
parent 41c2713b
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -564,7 +564,7 @@ static void iso_recv_frame(struct iso_conn *conn, struct sk_buff *skb)
	struct sock *sk;

	iso_conn_lock(conn);
	sk = conn->sk;
	sk = iso_sock_hold(conn);
	iso_conn_unlock(conn);

	if (!sk)
@@ -573,11 +573,15 @@ static void iso_recv_frame(struct iso_conn *conn, struct sk_buff *skb)
	BT_DBG("sk %p len %d", sk, skb->len);

	if (sk->sk_state != BT_CONNECTED)
		goto drop;
		goto drop_put;

	if (!sock_queue_rcv_skb(sk, skb))
	if (!sock_queue_rcv_skb(sk, skb)) {
		sock_put(sk);
		return;
	}

drop_put:
	sock_put(sk);
drop:
	kfree_skb(skb);
}