Skip to contentSkip to conversation

Fix double free on AVDTP Abort response

PATCH In review Daniel Örstadius 4 participants 7 messages Feb 19, 2010 – Feb 23, 2010 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix double free on AVDTP Abort response

With the patch I submitted some time ago
http://git.kernel.org/?p=bluetooth/bluez.git;a=commit;h=e9b1a8f7266d0674b1ea068a5bb5698e9ee424c9
there is a code path leading to a double free:
session_cb -> avdtp_parse_resp -> avdtp_abort_resp -> avdtp_sep_set_state(..., AVDTP_STATE_IDLE) -> handle_unanswered_req

A response to AVDTP Abort could lead to the pending request being freed both in session_cb and handle_unanswered_req.

This patch avoids doing it in the latter function. The primary purpose of adding handle_unanswered_req was to trigger responses on the Audio API (it was based on avdtp.c:request_timeout). AFAIU, AVDTP Abort doesn't lead to an API response and will be freed elsewhere (session_cb or avdtp_unref).

/Daniel

From 803637bc0e452392498714cd8245a06f5aea2edc Mon Sep 17 00:00:00 2001
From: Daniel Orstadius <[email protected]>
Date: Fri, 19 Feb 2010 17:51:48 +0200
Subject: [PATCH] Fix double free on AVDTP Abort response

The pending request might be freed twice when receiving an Abort response, in handle_unanswered_req and session_cb. Avoid freeing it in handle_unanswered_req.

---
 audio/avdtp.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
audio/avdtp.c +7 -0
index 2591845..ae7c88e 100644
@@ -905,6 +905,13 @@ static void handle_unanswered_req(struct avdtp *session,
 	struct avdtp_local_sep *lsep;
 	struct avdtp_error err;
 
+	if (session->req == AVDTP_ABORT) {
+		/* Avoid freeing the Abort request here */
+		debug("handle_unanswered_req: Abort req, returning");
+		session->req->stream = NULL;
+		return;
+	}
+
 	req = session->req;
 	session->req = NULL;
 
Signature · 1 line
1.6.0.4
#1 lore raw

Hi Daniel,

audio/avdtp.c static void handle_unanswered_req(struct avdtp *session, · line 913

Quoted 6 lines · Daniel Örstadius
audio/avdtp.c +6 -0
+	if (session->req == AVDTP_ABORT) {
+		/* Avoid freeing the Abort request here */
+		debug("handle_unanswered_req: Abort req, returning");
+		session->req->stream = NULL;
+		return;
+	}

Please try to at least do a compile check before you submit patches. This one gives the following error:
audio/avdtp.c: In function ‘handle_unanswered_req’:
audio/avdtp.c:908: error: comparison between pointer and integer

What you probably want is session->req->signal_id == AVDTP_ABORT.

Johan

#2 lore raw
Quoted 7 lines · Johan Hedberg

Please try to at least do a compile check before you submit patches. This one gives the following error:
audio/avdtp.c: In function ‘handle_unanswered_req’:
audio/avdtp.c:908: error: comparison between pointer and integer

What you probably want is session->req->signal_id == AVDTP_ABORT.

Sorry. The attached patch compiles without warnings on "./configure && make". (new dependency to a capabilities lib prevents ./bootstrap-configure atm)

Br,
Daniel

From f45006ec75c23b55470e8088fe64e8f0b6ab6404 Mon Sep 17 00:00:00 2001
From: Daniel Orstadius <[email protected]>
Date: Sun, 21 Feb 2010 14:39:49 +0200
Subject: [PATCH] Fix double free on AVDTP Abort response

The pending request might be freed twice when receiving an Abort response, in handle_unanswered_req and session_cb. Avoid freeing it in handle_unanswered_req.

---
 audio/avdtp.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
audio/avdtp.c +7 -0
index 2591845..add08f1 100644
@@ -905,6 +905,13 @@ static void handle_unanswered_req(struct avdtp *session,
 	struct avdtp_local_sep *lsep;
 	struct avdtp_error err;
 
+	if (session->req->signal_id == AVDTP_ABORT) {
+		/* Avoid freeing the Abort request here */
+		debug("handle_unanswered_req: Abort req, returning");
+		session->req->stream = NULL;
+		return;
+	}
+
 	req = session->req;
 	session->req = NULL;
 
Signature · 1 line
1.6.0.4
maintainer
#3 lore raw

Hi Daniel,

Quoted 10 lines
Quoted 7 lines

Please try to at least do a compile check before you submit patches. This one gives the following error:
audio/avdtp.c: In function ‘handle_unanswered_req’:
audio/avdtp.c:908: error: comparison between pointer and integer

What you probably want is session->req->signal_id == AVDTP_ABORT.

Sorry. The attached patch compiles without warnings on "./configure && make". (new dependency to a capabilities lib prevents ./bootstrap-configure atm)

you can use ./bootstrap-configure --disable-capng.

Regards

Marcel

#4 lore raw
In reply to Daniel Örstadius

Hi Daniel,

Quoted 10 lines · Daniel Örstadius
Quoted 7 lines

Please try to at least do a compile check before you submit patches. This one gives the following error:
audio/avdtp.c: In function ‘handle_unanswered_req’:
audio/avdtp.c:908: error: comparison between pointer and integer

What you probably want is session->req->signal_id == AVDTP_ABORT.

Sorry. The attached patch compiles without warnings on "./configure && make". (new dependency to a capabilities lib prevents ./bootstrap-configure atm)

You can avoid that with "./bootstrap-configure --disable-capng"

Quoted 6 lines

The pending request might be freed twice when receiving an Abort response, in handle_unanswered_req and session_cb. Avoid freeing it in handle_unanswered_req.

---
 audio/avdtp.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

Thanks, the patch is now upstream.

Johan

#5 lore raw

Hi Johan,

Quoted 16 lines · Johan Hedberg

Hi Daniel,

Quoted 10 lines · Daniel Örstadius
Quoted 7 lines

Please try to at least do a compile check before you submit patches. This one gives the following error:
audio/avdtp.c: In function ‘handle_unanswered_req’:
audio/avdtp.c:908: error: comparison between pointer and integer

What you probably want is session->req->signal_id == AVDTP_ABORT.

Sorry. The attached patch compiles without warnings on "./configure && make". (new dependency to a capabilities lib prevents ./bootstrap-configure atm)

You can avoid that with "./bootstrap-configure --disable-capng"

Quoted 8 lines
Quoted 6 lines

The pending request might be freed twice when receiving an Abort response, in handle_unanswered_req and session_cb. Avoid freeing it in handle_unanswered_req.
---
 audio/avdtp.c |    7 +++++++

 1 files changed, 7 insertions(+), 0 deletions(-)

Thanks, the patch is now upstream.

While discussing this problem we find out that our timeout doesn't really work as we imagine due to the possibility of abort being rejected, so either we don't call any callback on timeout and do it on abort response while changing to aborting state (which probably means 4-8 sec before we are really able to abort/cancel) or we disconnect as the other end seems to not cooperate on aborting.

Btw, we probably should have a smaller timeout for avdtp_abort anyway and make sure we call it upon RequestDisconnect not avdtp_close which has no priority over the others commands.

Regards,

Signature · 2 lines
Luiz Augusto von Dentz
Computer Engineer
#6 lore raw

Hi Luiz,

Quoted 10 lines · Luiz Augusto von Dentz

While discussing this problem we find out that our timeout doesn't really work as we imagine due to the possibility of abort being rejected, so either we don't call any callback on timeout and do it on abort response while changing to aborting state (which probably means 4-8 sec before we are really able to abort/cancel) or we disconnect as the other end seems to not cooperate on aborting.

Btw, we probably should have a smaller timeout for avdtp_abort anyway and make sure we call it upon RequestDisconnect not avdtp_close which has no priority over the others commands.

Makes sense. Feel free to propose a patch (or multiple patches) for all this ;)

Johan