shared/bap: Remove broadcast sink PACs in bt_bap_remove_pac()
PATCH v3 1/4 shared/bap: Remove broadcast sink PACs in bt_bap_remove_pac()
bt_bap_remove_pac() looked for the PAC in the sink, source and broadcast source lists only, so a broadcast sink PAC stayed in broadcast_sinks after its endpoint was freed. When the endpoint owner goes away, like WirePlumber restarting, the next BIGInfo matches the stale PAC and bluetoothd crashes:
pac_bcast_config (endpoint=<freed>) at profiles/audio/media.c pac_config () at profiles/audio/media.c bap_bcast_config () at src/shared/bap.c bt_bap_stream_config () at src/shared/bap.c create_stream_for_bis () at profiles/audio/bap.c bis_handler () at profiles/audio/bap.c bt_bap_parse_base () at src/shared/bap.c big_info_report_cb () at profiles/audio/bap.c
--- src/shared/bap.c | 3 +++ 1 file changed, 3 insertions(+)
src/shared/bap.c +3 -0
@@ -4864,6 +4864,9 @@ bool bt_bap_remove_pac(struct bt_bap_pac *pac)if (queue_remove_if (pac->bdb->broadcast_sources,NULL , pac)) goto found; +if (queue_remove_if (pac->bdb->broadcast_sinks,NULL , pac)) + goto found; +return false; found:
base-commit: 1608f836188610aabeff5a3164169ebe0360e443
Signature · 1 line
2.43.0
PATCH v3 2/4 unit/test-bap: Check that a broadcast sink PAC can be removed
bt_bap_remove_pac() did not find a broadcast sink PAC, which left the PAC of an unregistered endpoint in use. Check in the teardown of every test that registers one that its removal succeeds.
--- unit/test-bap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
unit/test-bap.c +4 -1
@@ -1307,7 +1307,10 @@ static void test_teardown(const void *user_data)bt_bap_remove_pac (data->snk);bt_bap_remove_pac (data->src);bt_bap_remove_pac (data->bsrc); -bt_bap_remove_pac (data->bsnk); + +if (data->bsnk) +g_assert (bt_bap_remove_pac (data->bsnk)); +gatt_db_unref (data->db);bt_gatt_server_unref (data->server); data->server =NULL ;
Signature · 1 line
2.43.0
PATCH v3 3/4 bap: Don't leak the io of a PA sync that failed
In reply to Simon MikudaFrom: Simon Mikuda <[email protected]>
The kernel reports a PA sync that times out twice. iso_pa_sync_confirm_cb() replaced data->io_id for the second io, so the watch of the first one stayed, holding the last reference of its io and keeping the failed sync in the kernel. Where PA syncs are BIS connections on BIG 0, a broadcast source on BIG 0 then fails to bind with EADDRINUSE until bluetoothd restarts.
Remove the previous watch, which also closes its io.
--- profiles/audio/bap.c | 7 +++++++ 1 file changed, 7 insertions(+)
profiles/audio/bap.c +7 -0
@@ -1912,6 +1912,13 @@ static void iso_pa_sync_confirm_cb(GIOChannel *io, void *user_data)* encryption flag is also available. */ DBG ("PA Sync done" ); + +/* A failed PA sync is reported twice. Dropping the previous watch also +* closes its io, as the watch holds the last reference. +*/ +if (data->io_id) +g_source_remove (data->io_id); + data->io_id =g_io_add_watch (io,G_IO_OUT , big_info_report_cb, user_data); }
Signature · 1 line
2.43.0
PATCH v3 4/4 bap: Close a pending PA or BIG sync when a sink session ends
In reply to Simon Mikudabap_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:285Remove 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.
--- profiles/audio/bap.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
profiles/audio/bap.c +20 -0
@@ -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;
Signature · 1 line
2.43.0
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1220993/
---Test result---
Test Summary:
CheckPatch PASS 1.27 seconds GitLint PASS 0.92 seconds BuildEll PASS 17.24 seconds BluezMake PASS 238.56 seconds MakeCheck PASS 13.51 seconds MakeDistcheck PASS 119.38 seconds CheckValgrind PASS 293.93 seconds CheckSmatch WARNING 241.76 seconds bluezmakeextell PASS 76.27 seconds TestFunctional PASS 949.07 seconds IncrementalBuild PASS 267.67 seconds ScanBuild PASS 891.63 seconds
Details
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:src/shared/bap.c:317:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structuressrc/shared/bap.c:317:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structuressrc/shared/bap.c:317:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structures
https://github.com/bluez/bluez/pull/2909
---
Regards,
Linux Bluetooth
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 15 lines · On Tue, 24 Nov 2026 16:09:19 +0100 you wrote:
bt_bap_remove_pac()looked for the PAC in the sink, source and broadcast source lists only, so a broadcast sink PAC stayed inbroadcast_sinksafter its endpoint was freed. When the endpoint owner goes away, like WirePlumber restarting, the next BIGInfo matches the stale PAC and bluetoothd crashes:
pac_bcast_config(endpoint=<freed>) atprofiles/audio/media.cpac_config() atprofiles/audio/media.cbap_bcast_config() atsrc/shared/bap.cbt_bap_stream_config() atsrc/shared/bap.ccreate_stream_for_bis() atprofiles/audio/bap.cbis_handler() atprofiles/audio/bap.cbt_bap_parse_base() atsrc/shared/bap.cbig_info_report_cb() atprofiles/audio/bap.c
Quoted 1 line
[...]
Here is the summary with links:
- [BlueZ,v3,1/4] shared/bap: Remove broadcast sink PACs in bt_bap_remove_pac()
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=9de52c6b51c4 - [BlueZ,v3,2/4] unit/test-bap: Check that a broadcast sink PAC can be removed https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=b0ffc6b9241f - [BlueZ,v3,3/4] bap: Don't leak the io of a PA sync that failed https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=2d690b7b42ed - [BlueZ,v3,4/4] bap: Close a pending PA or BIG sync when a sink session ends https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=79162c108911
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html