History

Bluetooth: ISO: ensure no dangling hcon references in iso_conn

After iso_conn_del(), ISO sockets should not dereference the hcon any more. Currently, clearing iso_conn::hcon relies on iso_conn_del() releasing the last reference to the iso_conn. Simplify this by explicitly clearing conn->hcon in iso_conn_del(), to avoid more complex reasoning on races about who holds the last reference.

Pauli Virtanen committed 3 months ago

Commit aa9f7cb1 parent 200fa161 file · +21 −3Browse files

Unified · Split

net/bluetooth/iso.c+21−3
@@ -263,6 +263,7 @@ static void iso_chan_del(struct sock *sk, int err) · 262 unmodified lines
263263 }
264264
265265 static void iso_conn_del(struct hci_conn *hcon, int err)
266+ __must_hold(&hcon->hdev->lock)
266267 {
267268 struct iso_conn *conn = hcon->iso_data;
268269 struct sock *sk;
@@ -277,11 +278,10 @@ static void iso_conn_del(struct hci_conn *hcon, int err) · 8 unmodified lines
277278 iso_conn_lock(conn);
278279 sk = iso_sock_hold(conn);
279280 iso_conn_unlock(conn);
280− iso_conn_put(conn);
281281
282282 if (!sk) {
283283 iso_conn_put(conn);
284− return;
284+ goto done;
285285 }
286286
287287 iso_sock_disable_timer(sk);
@@ -291,6 +291,15 @@ static void iso_conn_del(struct hci_conn *hcon, int err) · 3 unmodified lines
291291 release_sock(sk);
292292 iso_sock_kill(sk);
293293 sock_put(sk);
294+
295+done:
296+ /* No sk access to conn->hcon any more (lock_sock + hdev->lock) */
297+ iso_conn_lock(conn);
298+ conn->hcon = NULL;
299+ hcon->iso_data = NULL;
300+ iso_conn_unlock(conn);
301+
302+ iso_conn_put(conn);
294303 }
295304
296305 static int __iso_chan_add(struct iso_conn *conn, struct sock *sk,
@@ -306,6 +315,11 @@ static int __iso_chan_add(struct iso_conn *conn, struct sock *sk, · 9 unmodified lines
306315 return -EBUSY;
307316 }
308317
318+ if (!conn->hcon) {
319+ BT_ERR("conn->hcon missing");
320+ return -EIO;
321+ }
322+
309323 iso_pi(sk)->conn = conn;
310324 conn->sk = sk;
311325 clear_bit(ISO_CONN_DROPPED, conn->flags);
@@ -2500,6 +2514,7 @@ done: · 2188 unmodified lines
25002514 }
25012515
25022516 static void iso_connect_cfm(struct hci_conn *hcon, __u8 status)
2517+ __must_hold(&hcon->hdev->lock)
25032518 {
25042519 if (hcon->type != CIS_LINK && hcon->type != BIS_LINK &&
25052520 hcon->type != PA_LINK) {
@@ -2511,8 +2526,10 @@ static void iso_connect_cfm(struct hci_conn *hcon, __u8 status) · 5 unmodified lines
25112526 struct hci_link *link, *t;
25122527
25132528 list_for_each_entry_safe(link, t, &hcon->link_list,
2514− list)
2529+ list) {
2530+ lockdep_assert_held(&link->conn->hdev->lock);
25152531 iso_conn_del(link->conn, bt_to_errno(status));
2532+ }
25162533
25172534 return;
25182535 }
@@ -2542,6 +2559,7 @@ static void iso_connect_cfm(struct hci_conn *hcon, __u8 status) · 23 unmodified lines
25422559 }
25432560
25442561 static void iso_disconn_cfm(struct hci_conn *hcon, __u8 reason)
2562+ __must_hold(&hcon->hdev->lock)
25452563 {
25462564 if (hcon->type != CIS_LINK && hcon->type != BIS_LINK &&
25472565 hcon->type != PA_LINK)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t