Skip to content

Commit 246b435

Browse files
committed
Bluetooth: ISO: Fix UAF on iso_sock_timeout
conn->sk maybe have been unlinked/freed while waiting for iso_conn_lock so this checks if the conn->sk is still valid by checking if it part of iso_sk_list. Fixes: ccf74f2 ("Bluetooth: Add BTPROTO_ISO socket type") Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 1bf4470 commit 246b435

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

net/bluetooth/iso.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,24 @@ static struct sock *iso_get_sock(bdaddr_t *src, bdaddr_t *dst,
9393
#define ISO_CONN_TIMEOUT (HZ * 40)
9494
#define ISO_DISCONN_TIMEOUT (HZ * 2)
9595

96+
static struct sock *iso_sock_hold(struct iso_conn *conn)
97+
{
98+
if (!conn || !bt_sock_linked(&iso_sk_list, conn->sk))
99+
return NULL;
100+
101+
sock_hold(conn->sk);
102+
103+
return conn->sk;
104+
}
105+
96106
static void iso_sock_timeout(struct work_struct *work)
97107
{
98108
struct iso_conn *conn = container_of(work, struct iso_conn,
99109
timeout_work.work);
100110
struct sock *sk;
101111

102112
iso_conn_lock(conn);
103-
sk = conn->sk;
104-
if (sk)
105-
sock_hold(sk);
113+
sk = iso_sock_hold(conn);
106114
iso_conn_unlock(conn);
107115

108116
if (!sk)
@@ -209,9 +217,7 @@ static void iso_conn_del(struct hci_conn *hcon, int err)
209217

210218
/* Kill socket */
211219
iso_conn_lock(conn);
212-
sk = conn->sk;
213-
if (sk)
214-
sock_hold(sk);
220+
sk = iso_sock_hold(conn);
215221
iso_conn_unlock(conn);
216222

217223
if (sk) {

0 commit comments

Comments
 (0)