Skip to contentSkip to conversation

Bluetooth: ISO: ensure no dangling hcon references in iso_conn

PATCH In review Daniel Pereira 2 participants 2 messages Aug 30 – Aug 31 Stable branch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bluetooth: ISO: ensure no dangling hcon references in iso_conn

commit aa9f7cb2bd3a2be998ceb739fc9a2f986eba43eb upstream.

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.

[ Daniel Pereira ]
Backport notes:
- Adjusted the context in iso_conn_del() as 6.1.y handles iso_conn freeing without refcounting (kfree(conn)). Explicitly cleared conn->hcon under iso_conn_lock() right before freeing to maintain the safety invariant and prevent any concurrent socket accesses from holding dangling hcon pointers.

---
 net/bluetooth/iso.c | 5 +++++
 1 file changed, 5 insertions(+)
net/bluetooth/iso.c +5 -0
index aad4baec9..ef31fcd47 100644
@@ -183,6 +183,7 @@ static void iso_chan_del(struct sock *sk, int err)
 }
 
 static void iso_conn_del(struct hci_conn *hcon, int err)
+	__must_hold(&hcon->hdev->lock)
 {
 	struct iso_conn *conn = hcon->iso_data;
 	struct sock *sk;
@@ -208,6 +209,9 @@ static void iso_conn_del(struct hci_conn *hcon, int err)
 	/* Ensure no more work items will run before freeing conn. */
 	cancel_delayed_work_sync(&conn->timeout_work);
 
+	iso_conn_lock(conn);
+	conn->hcon = NULL;
+	iso_conn_unlock(conn);
 	hcon->iso_data = NULL;
 	kfree(conn);
 }
@@ -1669,6 +1673,7 @@ static void iso_connect_cfm(struct hci_conn *hcon, __u8 status)
 }
 
 static void iso_disconn_cfm(struct hci_conn *hcon, __u8 reason)
+	__must_hold(&hcon->hdev->lock)
 {
 	if (hcon->type != ISO_LINK)
 		return;
Signature · 1 line
2.47.3
maintainer
#1 lore raw
Quoted 5 lines

commit aa9f7cb2bd3a2be998ceb739fc9a2f986eba43eb upstream.

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.

Thanks, but this doesn't do anything on 6.1.y. iso_conn isn't kref-refcounted there yet - dc26097bdb86 came later - so iso_conn_del() kfree()s conn two statements after your conn->hcon = NULL, and nothing can observe the store.

Signature · 2 lines
Thanks,
Sasha