Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ] shared/bap: Fix use-after-free in bt_bap_detach
@ 2026-08-31 14:44 Frédéric Danis
  2026-08-31 15:57 ` [BlueZ] " bluez.test.bot
  2026-09-02 15:40 ` [PATCH BlueZ] " patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Frédéric Danis @ 2026-08-31 14:44 UTC (permalink / raw)
  To: linux-bluetooth

bt_bap_detach() invoked the pending request's completion callback via
bap_req_detach(bap->req) before clearing bap->req. Since the completion
callback (req->func) can trigger synchronous cleanup that re-enters
bt_bap_stream_cancel() for the same stream, and bt_bap_stream_cancel()
frees bap->req whenever it still matches the request being canceled,
the request could be freed while bap_req_complete() was still executing
on it, causing bap_req_complete() to dereference the now-freed request
once the callback returned.

Clear bap->req before invoking the completion callback, matching the
pattern already used by bap_abort_stream_req(), the ASE IDLE state
handler and bap_cp_notify(), so a reentrant cancel no longer finds a
stale bap->req to free.

Assisted-by: Claude:claude-sonnet-5
---
 src/shared/bap.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/shared/bap.c b/src/shared/bap.c
index da3e265e2..891a2f4fd 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -5958,8 +5958,10 @@ void bt_bap_detach(struct bt_bap *bap)
 
 	/* Cancel ongoing request */
 	if (bap->req) {
-		bap_req_detach(bap->req);
+		struct bt_bap_req *req = bap->req;
+
 		bap->req = NULL;
+		bap_req_detach(req);
 	}
 
 	bt_gatt_client_idle_unregister(bap->client, bap->idle_id);
-- 
2.43.0


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

end of thread, other threads:[~2026-09-02 15:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-31 14:44 [PATCH BlueZ] shared/bap: Fix use-after-free in bt_bap_detach Frédéric Danis
2026-08-31 15:57 ` [BlueZ] " bluez.test.bot
2026-09-02 15:40 ` [PATCH BlueZ] " patchwork-bot+bluetooth

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