Linux bluetooth development
 help / color / mirror / Atom feed
From: Simon Mikuda <simon.mikuda@streamunlimited.com>
To: linux-bluetooth@vger.kernel.org
Cc: Simon Mikuda <simon.mikuda@streamunlimited.com>
Subject: [PATCH BlueZ 4/4] bap: Close a pending PA or BIG sync when a broadcast sink session ends
Date: Sun, 22 Nov 2026 12:50:45 +0100	[thread overview]
Message-ID: <20261122115045.1077168-4-simon.mikuda@streamunlimited.com> (raw)
In-Reply-To: <20261122115045.1077168-1-simon.mikuda@streamunlimited.com>

bap_bcast_disconnect() frees the broadcast sink setups, but listen_io
stays open with a callback on one of them. A PA sync that completes
after the session ended crashes bluetoothd:

    #4  iso_do_big_sync (io=0xaaaad1ab3a30, user_data=0xaaaad1a87110)
        at profiles/audio/bap.c:3689
    #5  server_cb (io=0xaaaad1aabd30, cond=<optimized out>,
        user_data=0xaaaad1ad1310) at btio/btio.c:285

Close listen_io before freeing the setups.

Fixes: feb4ee9dcd4b ("bap: Fix use-after-free in broadcast sink cleanup")
Assisted-by: Claude:claude-opus-5-5
---
 profiles/audio/bap.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c
index 5e717cbef..af532537b 100644
--- a/profiles/audio/bap.c
+++ b/profiles/audio/bap.c
@@ -4284,6 +4284,16 @@ static int bap_bcast_disconnect(struct btd_service *service)
 		error("BAP service not handled by profile");
 		return -EINVAL;
 	}
+
+	/* A pending PA or BIG sync calls back with one of the setups freed
+	 * below, close it.
+	 */
+	if (data->listen_io) {
+		g_io_channel_shutdown(data->listen_io, TRUE, NULL);
+		g_io_channel_unref(data->listen_io);
+		data->listen_io = NULL;
+	}
+
 	/* Clean up broadcast sinks before detach (like unicast does) */
 	if (data->bcast_snks) {
 		bcast_snks = data->bcast_snks;
-- 
2.43.0


  parent reply	other threads:[~2026-11-22 11:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 11:50 [PATCH BlueZ 1/4] shared/bap: Remove broadcast sink PACs in bt_bap_remove_pac() Simon Mikuda
2026-11-22 11:50 ` [PATCH BlueZ 2/4] unit/test-bap: Check that a broadcast sink PAC can be removed Simon Mikuda
2026-11-22 11:50 ` [PATCH BlueZ 3/4] bap: Don't leak the io of a PA sync that failed Simon Mikuda
2026-11-22 11:50 ` Simon Mikuda [this message]
2026-11-22 19:01 ` [BlueZ,1/4] shared/bap: Remove broadcast sink PACs in bt_bap_remove_pac() bluez.test.bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261122115045.1077168-4-simon.mikuda@streamunlimited.com \
    --to=simon.mikuda@streamunlimited.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox