Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH v2] Bluetooth: ISO: Don't drop the hold of a closed BIS socket twice
@ 2026-11-24 11:40 Simon Mikuda
  2026-11-24 18:54 ` [v2] " bluez.test.bot
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Mikuda @ 2026-11-24 11:40 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Simon Mikuda, Marcel Holtmann, Luiz Augusto von Dentz

A broadcast source BIS socket that is shut down and then closed while its
BIG is being created drops its hold on the BIS in shutdown() and frees its
iso_conn in close(). When LE Setup ISO Data Path of that BIS completes,
iso_connect_cfm() creates a new iso_conn for it, and freeing that iso_conn
drops the hold a second time.

The first BIS of a BIG is the parent of the others, so the extra drop
deletes it together with them while the BIG is still running. The sockets
of the other BISes get ECONNRESET, and the BIG is terminated twice. The
controller rejects the second LE Terminate BIG. In this capture the first
socket was shut down and closed about 10 ms before LE Create BIG was sent:

    < HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068)
            Handle: 0x00
            Advertising Handle: 0x01
            Number of BIS: 2
    ...
    > HCI Event: LE Meta Event (0x3e)
          LE Broadcast Isochronous Group Complete (0x1b)
            Status: Success (0x00)
            Handle: 0x00
    ...
            Connection Handle #0: 16
            Connection Handle #1: 17
    < HCI Command: LE Setup Isochronous Data Path (0x08|0x006e)
            Handle: 16
    ...
    < HCI Command: LE Setup Isochronous Data Path (0x08|0x006e)
            Handle: 17
    ...
    < HCI Command: LE Terminate Broadcast Isochronous Group (0x08|0x006a)
            BIG Handle: 0x00
    ...
    < HCI Command: LE Terminate Broadcast Isochronous Group (0x08|0x006a)
            BIG Handle: 0x00
            Reason: Connection Terminated By Local Host (0x16)
    > HCI Event: Command Status (0x0f)
          LE Terminate Broadcast Isochronous Group (0x08|0x006a)
            Status: Command Disallowed (0x0c)

The kernel logs the rejected command:

    Bluetooth: hci1: Opcode 0x206a failed: -16

close() alone does not trigger this: the socket then stays in BT_DISCONN
with its iso_conn.

Fix this by looking up the iso_conn that a source BIS got in connect()
instead of creating a new one. If it is gone, the socket is closed and
there is nothing to make ready. The lookup takes hcon->proto_lock, as
iso_conn_del() does, because the closing socket frees the iso_conn after
clearing hcon->iso_data under that lock.

Steps to reproduce, here with an nRF54L15 DK running Zephyr's controller
(no second device is needed):
1. Run btmon.
2. Open two broadcast source BIS sockets for one BIG (BIG handle 0x00) and
   connect them non-blocking, the first with BT_DEFER_SETUP. The second
   connect() creates the BIG.
3. Right after the second connect(), before LE BIG Complete, call
   shutdown(SHUT_WR) and then close() on the first socket.
4. The second socket gets ECONNRESET, and btmon shows LE Terminate BIG
   twice, the second one failing with Command Disallowed (5 of 5 runs).

Fixes: fdfde532ab1c ("Bluetooth: ISO: fix refcounting of iso_conn")
Signed-off-by: Simon Mikuda <simon.mikuda@streamunlimited.com>
---
Changes in v2:
- Steps: shutdown() and then close(); close() alone does not trigger it.
- Trace: btmon output of the reproduction, which ran on a kernel with
  the Bluetooth code of bluetooth-next as of 2026-10-07 (7.3-rc2); v1's
  was condensed and not from this tree.
- Status of the second LE Terminate BIG as captured: Command Disallowed.
- No code change.

 net/bluetooth/iso.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/iso.c b/net/bluetooth/iso.c
index 06f1e7ba2cb1..fd33a1ec53d6 100644
--- a/net/bluetooth/iso.c
+++ b/net/bluetooth/iso.c
@@ -2680,7 +2680,14 @@ static void iso_connect_cfm(struct hci_conn *hcon, __u8 status)
 	    test_bit(HCI_CONN_PA_SYNC_FAILED, hcon->flags)) {
 		struct iso_conn *conn;
 
-		conn = iso_conn_add(hcon);
+		if (hcon->type == BIS_LINK && hcon->role == HCI_ROLE_MASTER) {
+			spin_lock(&hcon->proto_lock);
+			conn = iso_conn_hold_unless_zero(hcon->iso_data);
+			spin_unlock(&hcon->proto_lock);
+		} else {
+			conn = iso_conn_add(hcon);
+		}
+
 		if (conn) {
 			iso_conn_ready(conn);
 			iso_conn_put(conn);

base-commit: 4fe38719e6738feaa90486e36b0790dd5d960a96
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-24 18:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 11:40 [PATCH v2] Bluetooth: ISO: Don't drop the hold of a closed BIS socket twice Simon Mikuda
2026-11-24 18:54 ` [v2] " bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox