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.
Unified · Split
| @@ -263,6 +263,7 @@ static void iso_chan_del(struct sock *sk, int err) · 262 unmodified lines | ||
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | static void iso_conn_del(struct hci_conn *hcon, int err) |
| 266 | + __must_hold(&hcon->hdev->lock) | |
| 266 | 267 | { |
| 267 | 268 | struct iso_conn *conn = hcon->iso_data; |
| 268 | 269 | struct sock *sk; |
| @@ -277,11 +278,10 @@ static void iso_conn_del(struct hci_conn *hcon, int err) · 8 unmodified lines | ||
| 277 | 278 | iso_conn_lock(conn); |
| 278 | 279 | sk = iso_sock_hold(conn); |
| 279 | 280 | iso_conn_unlock(conn); |
| 280 | − iso_conn_put(conn); | |
| 281 | 281 | |
| 282 | 282 | if (!sk) { |
| 283 | 283 | iso_conn_put(conn); |
| 284 | − return; | |
| 284 | + goto done; | |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | iso_sock_disable_timer(sk); |
| @@ -291,6 +291,15 @@ static void iso_conn_del(struct hci_conn *hcon, int err) · 3 unmodified lines | ||
| 291 | 291 | release_sock(sk); |
| 292 | 292 | iso_sock_kill(sk); |
| 293 | 293 | 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); | |
| 294 | 303 | } |
| 295 | 304 | |
| 296 | 305 | 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 | ||
| 306 | 315 | return -EBUSY; |
| 307 | 316 | } |
| 308 | 317 | |
| 318 | + if (!conn->hcon) { | |
| 319 | + BT_ERR("conn->hcon missing"); | |
| 320 | + return -EIO; | |
| 321 | + } | |
| 322 | + | |
| 309 | 323 | iso_pi(sk)->conn = conn; |
| 310 | 324 | conn->sk = sk; |
| 311 | 325 | clear_bit(ISO_CONN_DROPPED, conn->flags); |
| @@ -2500,6 +2514,7 @@ done: · 2188 unmodified lines | ||
| 2500 | 2514 | } |
| 2501 | 2515 | |
| 2502 | 2516 | static void iso_connect_cfm(struct hci_conn *hcon, __u8 status) |
| 2517 | + __must_hold(&hcon->hdev->lock) | |
| 2503 | 2518 | { |
| 2504 | 2519 | if (hcon->type != CIS_LINK && hcon->type != BIS_LINK && |
| 2505 | 2520 | hcon->type != PA_LINK) { |
| @@ -2511,8 +2526,10 @@ static void iso_connect_cfm(struct hci_conn *hcon, __u8 status) · 5 unmodified lines | ||
| 2511 | 2526 | struct hci_link *link, *t; |
| 2512 | 2527 | |
| 2513 | 2528 | list_for_each_entry_safe(link, t, &hcon->link_list, |
| 2514 | − list) | |
| 2529 | + list) { | |
| 2530 | + lockdep_assert_held(&link->conn->hdev->lock); | |
| 2515 | 2531 | iso_conn_del(link->conn, bt_to_errno(status)); |
| 2532 | + } | |
| 2516 | 2533 | |
| 2517 | 2534 | return; |
| 2518 | 2535 | } |
| @@ -2542,6 +2559,7 @@ static void iso_connect_cfm(struct hci_conn *hcon, __u8 status) · 23 unmodified lines | ||
| 2542 | 2559 | } |
| 2543 | 2560 | |
| 2544 | 2561 | static void iso_disconn_cfm(struct hci_conn *hcon, __u8 reason) |
| 2562 | + __must_hold(&hcon->hdev->lock) | |
| 2545 | 2563 | { |
| 2546 | 2564 | if (hcon->type != CIS_LINK && hcon->type != BIS_LINK && |
| 2547 | 2565 | hcon->type != PA_LINK) |