From: Simon Mikuda <simon.mikuda@streamunlimited.com>
To: linux-bluetooth@vger.kernel.org
Cc: Simon Mikuda <simon.mikuda@streamunlimited.com>
Subject: [PATCH BlueZ v3 4/4] bap: Close a pending PA or BIG sync when a sink session ends
Date: Tue, 24 Nov 2026 16:09:22 +0100 [thread overview]
Message-ID: <20261124150922.341655-4-simon.mikuda@streamunlimited.com> (raw)
In-Reply-To: <20261124150922.341655-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, and so does the watch of a
PA sync waiting for BIGInfo, which is on the accepted channel rather
than on listen_io. A PA or BIG 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
Remove the watch and close listen_io before freeing the setups, and
release a PA sync kept for a stream to be enabled. iso_do_big_sync()
now clears io_id, so later cleanup does not remove an expired source.
Fixes: feb4ee9dcd4b ("bap: Fix use-after-free in broadcast sink cleanup")
Assisted-by: Claude:claude-opus-5-5
---
profiles/audio/bap.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c
index 9a456f45b..eff621762 100644
--- a/profiles/audio/bap.c
+++ b/profiles/audio/bap.c
@@ -3957,6 +3957,8 @@ static gboolean iso_do_big_sync(GIOChannel *io, GIOCondition cond,
struct bt_iso_qos qos;
struct queue *links = bt_bap_stream_io_get_links(setup->stream);
+ data->io_id = 0;
+
DBG("BIG info received, do BIG sync");
if (data->listen_io != io) {
@@ -4294,6 +4296,24 @@ 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, and a PA sync kept for them is of no use any more: close
+ * both.
+ */
+ if (data->io_id) {
+ g_source_remove(data->io_id);
+ data->io_id = 0;
+ }
+
+ pa_sync_release(data);
+
+ 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
next prev parent reply other threads:[~2026-11-24 15:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 15:09 [PATCH BlueZ v3 1/4] shared/bap: Remove broadcast sink PACs in bt_bap_remove_pac() Simon Mikuda
2026-11-24 15:09 ` [PATCH BlueZ v3 2/4] unit/test-bap: Check that a broadcast sink PAC can be removed Simon Mikuda
2026-11-24 15:09 ` [PATCH BlueZ v3 3/4] bap: Don't leak the io of a PA sync that failed Simon Mikuda
2026-11-24 15:09 ` Simon Mikuda [this message]
2026-11-24 20:52 ` [BlueZ,v3,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=20261124150922.341655-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