public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ v1] bass: Fix crash if setup is freed before bass_bcode_req response
@ 2026-02-12 20:57 Luiz Augusto von Dentz
  2026-02-12 21:50 ` [BlueZ,v1] " bluez.test.bot
  2026-02-13 20:20 ` [PATCH BlueZ v1] " patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2026-02-12 20:57 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

If a the stream is set to idle (e.g. because the endpoint is
unregistered) the bass_bcode_req would be left with a dangling
pointer possibly leading to a crash if the remote peer respond or
the request times out.
---
 profiles/audio/bass.c | 42 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 6 deletions(-)

diff --git a/profiles/audio/bass.c b/profiles/audio/bass.c
index 031f527be9f5..9c8046dad99b 100644
--- a/profiles/audio/bass.c
+++ b/profiles/audio/bass.c
@@ -385,6 +385,41 @@ static void delegator_disconnect(struct bass_delegator *dg)
 	}
 }
 
+static bool match_bcode_setup(const void *data, const void *user_data)
+{
+	const struct bass_bcode_req *req = data;
+	const struct bass_setup *setup = user_data;
+
+	return req->setup == setup;
+}
+
+static void setup_clear(struct bass_setup *setup, int bis)
+{
+	struct bass_delegator *dg = setup->dg;
+	struct bass_bcode_req *req;
+
+	DBG("%p", setup);
+
+	bt_bass_clear_bis_sync(dg->src, bis);
+	setup->stream = NULL;
+	queue_remove(setup->dg->setups, setup);
+
+	/* Remove any pending bcode request associated with setup */
+	req = queue_remove_if(dg->bcode_reqs, match_bcode_setup, setup);
+	if (req) {
+		free(req);
+		if (dg->timeout) {
+			g_source_remove(dg->timeout);
+			dg->timeout = 0;
+		}
+	}
+
+	setup_free(setup);
+
+	if (queue_isempty(dg->setups))
+		delegator_disconnect(dg);
+}
+
 static void bap_state_changed(struct bt_bap_stream *stream, uint8_t old_state,
 				uint8_t new_state, void *user_data)
 {
@@ -474,12 +509,7 @@ static void bap_state_changed(struct bt_bap_stream *stream, uint8_t old_state,
 			bt_bass_clear_bis_sync(dg->src, bis);
 		break;
 	case BT_BAP_STREAM_STATE_IDLE:
-		bt_bass_clear_bis_sync(dg->src, bis);
-		setup->stream = NULL;
-		queue_remove(setup->dg->setups, setup);
-		setup_free(setup);
-		if (queue_isempty(dg->setups))
-			delegator_disconnect(dg);
+		setup_clear(setup, bis);
 		break;
 	}
 }
-- 
2.52.0


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

end of thread, other threads:[~2026-02-13 20:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-12 20:57 [PATCH BlueZ v1] bass: Fix crash if setup is freed before bass_bcode_req response Luiz Augusto von Dentz
2026-02-12 21:50 ` [BlueZ,v1] " bluez.test.bot
2026-02-13 20:20 ` [PATCH BlueZ v1] " 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