* [PATCH BlueZ v2 0/1] Fix use-after-free in BAP broadcast cleanup
@ 2026-02-14 15:36 Sarveshwar Bajaj
2026-02-14 15:36 ` [PATCH BlueZ v2 1/1] bap: Fix use-after-free in broadcast sink cleanup Sarveshwar Bajaj
2026-02-17 14:50 ` [PATCH BlueZ v2 0/1] " patchwork-bot+bluetooth
0 siblings, 2 replies; 5+ messages in thread
From: Sarveshwar Bajaj @ 2026-02-14 15:36 UTC (permalink / raw)
To: linux-bluetooth, luiz.dentz
Cc: vinit.mehta, sarveshwar.bajaj, devyani.godbole
This fixes a use-after-free crash when broadcast audio sources
disconnect or undergo RPA rotation as reported in issue #1866.
The crash occurs because bap_data_free() was freeing streams before
destroying the broadcast sink setups that still held references to them.
Tested with AddressSanitizer on latest 6.19 kernel with NXPs
controller as broadcast sink and Samsung S23 broadcast source.
No crashes observed with disconnect or RPA rotation after fix.
Changes in v2:
- Use safe cleanup pattern to avoid nested queue operations (Pauli Virtanen)
- Apply fix to both bap_bcast_remove() and bap_bcast_disconnect()
Sarveshwar Bajaj (1):
bap: Fix use-after-free in broadcast sink cleanup
profiles/audio/bap.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
--
2.51.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH BlueZ v2 1/1] bap: Fix use-after-free in broadcast sink cleanup
2026-02-14 15:36 [PATCH BlueZ v2 0/1] Fix use-after-free in BAP broadcast cleanup Sarveshwar Bajaj
@ 2026-02-14 15:36 ` Sarveshwar Bajaj
2026-02-14 16:34 ` Fix use-after-free in BAP broadcast cleanup bluez.test.bot
2026-02-17 14:50 ` [PATCH BlueZ v2 0/1] " patchwork-bot+bluetooth
1 sibling, 1 reply; 5+ messages in thread
From: Sarveshwar Bajaj @ 2026-02-14 15:36 UTC (permalink / raw)
To: linux-bluetooth, luiz.dentz
Cc: vinit.mehta, sarveshwar.bajaj, devyani.godbole
bap_data_free() was calling bt_bap_detach() before destroying
bcast_snks queue. bt_bap_detach() frees all streams but broadcast
sink setups in bcast_snks queue were still holding pointers to these
streams. When queue_destroy() calls setup_free() as its destructor,
it attempts to access these already-freed stream pointers, causing
a use-after-free.
Fix this by destroying the bcast_snks queue before calling
bt_bap_detach() and ensuring stream references are released
while the streams are still valid.
Used safe cleanup pattern to avoid nested queue operations during
destruction as setup_free()may attempt to remove items from queue
being destroyed.
Crash trace:
AddressSanitizer: heap-use-after-free
#0 bt_bap_stream_unlock src/shared/bap.c:6384
#1 setup_free profiles/audio/bap.c:1123
#2 queue_destroy src/shared/queue.c:60
#3 bap_data_free profiles/audio/bap.c:210
https://github.com/bluez/bluez/issues/1866
---
profiles/audio/bap.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c
index 90a978667..375026440 100644
--- a/profiles/audio/bap.c
+++ b/profiles/audio/bap.c
@@ -3808,6 +3808,7 @@ static void bap_bcast_remove(struct btd_service *service)
{
struct btd_device *device = btd_service_get_device(service);
struct bap_data *data;
+ struct queue *bcast_snks;
char addr[18];
ba2str(device_get_address(device), addr);
@@ -3822,6 +3823,13 @@ static void bap_bcast_remove(struct btd_service *service)
return;
}
+ /* Clean up before bis_remove and data_remove */
+ if (data->bcast_snks) {
+ bcast_snks = data->bcast_snks;
+ data->bcast_snks = NULL;
+ queue_destroy(bcast_snks, setup_free);
+ }
+
bt_bap_bis_remove(data->bap);
bap_data_remove(data);
@@ -3929,6 +3937,7 @@ static int bap_disconnect(struct btd_service *service)
static int bap_bcast_disconnect(struct btd_service *service)
{
struct bap_data *data;
+ struct queue *bcast_snks;
/* Lookup the bap session for this service since in case of
* bass_delegator its user data is set by bass plugin.
@@ -3938,6 +3947,12 @@ static int bap_bcast_disconnect(struct btd_service *service)
error("BAP service not handled by profile");
return -EINVAL;
}
+ /* Clean up broadcast sinks before detach (like unicast does) */
+ if (data->bcast_snks) {
+ bcast_snks = data->bcast_snks;
+ data->bcast_snks = NULL;
+ queue_destroy(bcast_snks, setup_free);
+ }
bt_bap_detach(data->bap);
--
2.51.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH BlueZ v2 0/1] Fix use-after-free in BAP broadcast cleanup
2026-02-14 15:36 [PATCH BlueZ v2 0/1] Fix use-after-free in BAP broadcast cleanup Sarveshwar Bajaj
2026-02-14 15:36 ` [PATCH BlueZ v2 1/1] bap: Fix use-after-free in broadcast sink cleanup Sarveshwar Bajaj
@ 2026-02-17 14:50 ` patchwork-bot+bluetooth
1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+bluetooth @ 2026-02-17 14:50 UTC (permalink / raw)
To: Sarveshwar Bajaj
Cc: linux-bluetooth, luiz.dentz, vinit.mehta, devyani.godbole
Hello:
This patch was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Sat, 14 Feb 2026 21:06:14 +0530 you wrote:
> This fixes a use-after-free crash when broadcast audio sources
> disconnect or undergo RPA rotation as reported in issue #1866.
>
> The crash occurs because bap_data_free() was freeing streams before
> destroying the broadcast sink setups that still held references to them.
>
> Tested with AddressSanitizer on latest 6.19 kernel with NXPs
> controller as broadcast sink and Samsung S23 broadcast source.
> No crashes observed with disconnect or RPA rotation after fix.
>
> [...]
Here is the summary with links:
- [BlueZ,v2,1/1] bap: Fix use-after-free in broadcast sink cleanup
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=feb4ee9dcd4b
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH BlueZ v1 1/1] bap: Fix use-after-free in broadcast sink cleanup
@ 2026-02-13 16:41 Sarveshwar Bajaj
2026-02-13 17:50 ` Fix use-after-free in BAP broadcast cleanup bluez.test.bot
0 siblings, 1 reply; 5+ messages in thread
From: Sarveshwar Bajaj @ 2026-02-13 16:41 UTC (permalink / raw)
To: linux-bluetooth, luiz.dentz
Cc: vinit.mehta, sarveshwar.bajaj, devyani.godbole
bap_data_free() was calling bt_bap_detach() before destroying
bcast_snks queue. bt_bap_detach() frees all streams but broadcast
sink setups in bcast_snks queue were still holding pointers to these
streams. When queue_destroy() calls setup_free() as its destructor,
it attempts to access these already-freed stream pointers, causing
a use-after-free.
Fix this by destroying the bcast_snks queue before calling
bt_bap_detach() and ensuring stream references are released while the
streams are still valid. This matches the cleanup order already used
for unicast.
Crash trace:
AddressSanitizer: heap-use-after-free
#0 bt_bap_stream_unlock src/shared/bap.c:6384
#1 setup_free profiles/audio/bap.c:1123
#2 queue_destroy src/shared/queue.c:60
#3 bap_data_free profiles/audio/bap.c:210
https://github.com/bluez/bluez/issues/1866
---
profiles/audio/bap.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c
index 90a978667..9108bf729 100644
--- a/profiles/audio/bap.c
+++ b/profiles/audio/bap.c
@@ -3822,6 +3822,12 @@ static void bap_bcast_remove(struct btd_service *service)
return;
}
+ /* Clean up before bis_remove and data_remove */
+ if (data->bcast_snks) {
+ queue_destroy(data->bcast_snks, setup_free);
+ data->bcast_snks = NULL;
+ }
+
bt_bap_bis_remove(data->bap);
bap_data_remove(data);
@@ -3938,6 +3944,11 @@ static int bap_bcast_disconnect(struct btd_service *service)
error("BAP service not handled by profile");
return -EINVAL;
}
+ /* Clean up broadcast sinks before detach (like unicast does) */
+ if (data->bcast_snks) {
+ queue_destroy(data->bcast_snks, setup_free);
+ data->bcast_snks = NULL;
+ }
bt_bap_detach(data->bap);
--
2.51.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-02-17 14:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-14 15:36 [PATCH BlueZ v2 0/1] Fix use-after-free in BAP broadcast cleanup Sarveshwar Bajaj
2026-02-14 15:36 ` [PATCH BlueZ v2 1/1] bap: Fix use-after-free in broadcast sink cleanup Sarveshwar Bajaj
2026-02-14 16:34 ` Fix use-after-free in BAP broadcast cleanup bluez.test.bot
2026-02-17 14:50 ` [PATCH BlueZ v2 0/1] " patchwork-bot+bluetooth
-- strict thread matches above, loose matches on Subject: below --
2026-02-13 16:41 [PATCH BlueZ v1 1/1] bap: Fix use-after-free in broadcast sink cleanup Sarveshwar Bajaj
2026-02-13 17:50 ` Fix use-after-free in BAP broadcast cleanup 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