Skip to contentSkip to conversation

avdtp: Fix use-after-free in connection_lost

PATCH Applied Jinwang Li 3 participants 3 messages Nov 16 – Nov 18 Bluetooth drivers

lore
Share & tools
lore

Jinwang Li

author
#0 lore raw

PATCH v4 1/1 avdtp: Fix use-after-free in connection_lost

A sink may start reverse discovery when processing a remote stream configuration. If the signaling channel disconnects after the stream is configured and discovery holds the last setup reference, stream cleanup frees that setup before the pending discovery callback runs, causing a use-after-free.

Complete discovery with the disconnect error before releasing streams so the callback runs while its setup is still valid.

Fixes 02877c5e98b8 ("a2dp: Add reverse discovery")
Assisted-by Claude:claude-sonnet-5

---
Changes for V4:
- Rebased the patch.
- Add Fixes tag.
- V3 link
https://lore.kernel.org/all/[email protected]/

Changes for V3:
- Update commit message.
- V2 link
https://lore.kernel.org/all/[email protected]/

Changes for V2:
- Rebased the patch.
- V1 link
https://lore.kernel.org/all/[email protected]/

---
 profiles/audio/avdtp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
profiles/audio/avdtp.c +2 -2
index 30f80a0c2..5ebc0c5cc 100644
@@ -1159,11 +1159,11 @@ static void connection_lost(struct avdtp *session, int err)
 	ba2str(device_get_address(session->device), address);
 	DBG("Disconnected from %s", address);
 
+	finalize_discovery(session, err);
+
 	g_slist_foreach(session->streams, (GFunc) release_stream, session);
 	session->streams = NULL;
 
-	finalize_discovery(session, err);
-
 	avdtp_set_state(session, AVDTP_SESSION_STATE_DISCONNECTED);
 
 	avdtp_unref(session);
Signature · 1 line
2.34.1
#1 lore raw

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/1212473/

---Test result---

Test Summary:

CheckPatch                    PASS      0.27 seconds
GitLint                       PASS      0.20 seconds
BuildEll                      PASS      16.49 seconds
BluezMake                     PASS      238.19 seconds
MakeCheck                     PASS      2.75 seconds
MakeDistcheck                 PASS      121.38 seconds
CheckValgrind                 PASS      124.29 seconds
CheckSmatch                   PASS      238.10 seconds
bluezmakeextell               PASS      77.42 seconds
TestFunctional                PASS      1035.17 seconds
IncrementalBuild              PASS      241.41 seconds
ScanBuild                     PASS      868.53 seconds

https://github.com/bluez/bluez/pull/2834

---
Regards,
Linux Bluetooth

#2 lore raw
In reply to Jinwang Li
This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 10 lines · On Mon, 16 Nov 2026 17:07:19 +0800 you wrote:

A sink may start reverse discovery when processing a remote stream configuration. If the signaling channel disconnects after the stream is configured and discovery holds the last setup reference, stream cleanup frees that setup before the pending discovery callback runs, causing a use-after-free.

Complete discovery with the disconnect error before releasing streams so the callback runs while its setup is still valid.

[...]

Here is the summary with links:
- [BlueZ,v4] avdtp: Fix use-after-free in connection_lost

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=43de1efcb453

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html