From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 4/6] android/avdtp: Fix crashes caused by re-entrant calls
Date: Thu, 26 Mar 2015 16:20:23 +0200 [thread overview]
Message-ID: <1427379625-20412-4-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1427379625-20412-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This make sure that while processing a PDU the session callbacks are
not able to destroy the session causing crashes.
---
android/avdtp.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/android/avdtp.c b/android/avdtp.c
index e4fd2b7..2252782 100644
--- a/android/avdtp.c
+++ b/android/avdtp.c
@@ -784,6 +784,10 @@ static void handle_unanswered_req(struct avdtp *session,
struct avdtp_local_sep *lsep;
struct avdtp_error err;
+ if (!session->req->timeout)
+ /* Request is in process */
+ return;
+
if (session->req->signal_id == AVDTP_ABORT) {
/* Avoid freeing the Abort request here */
DBG("handle_unanswered_req: Abort req, returning");
@@ -2017,6 +2021,9 @@ static gboolean session_cb(GIOChannel *chan, GIOCondition cond,
break;
}
+ /* Take a reference to protect against callback destroying session */
+ avdtp_ref(session);
+
if (session->in.message_type == AVDTP_MSG_TYPE_COMMAND) {
if (!avdtp_parse_cmd(session, session->in.transaction,
session->in.signal_id,
@@ -2031,21 +2038,25 @@ static gboolean session_cb(GIOChannel *chan, GIOCondition cond,
goto next;
}
+ avdtp_unref(session);
return TRUE;
}
if (session->req == NULL) {
error("No pending request, ignoring message");
+ avdtp_unref(session);
return TRUE;
}
if (header->transaction != session->req->transaction) {
error("Transaction label doesn't match");
+ avdtp_unref(session);
return TRUE;
}
if (session->in.signal_id != session->req->signal_id) {
error("Response signal doesn't match");
+ avdtp_unref(session);
return TRUE;
}
@@ -2085,7 +2096,10 @@ next:
pending_req_free(session->req);
session->req = NULL;
- process_queue(session);
+ if (session->ref > 1)
+ process_queue(session);
+
+ avdtp_unref(session);
return TRUE;
--
2.1.0
next prev parent reply other threads:[~2015-03-26 14:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-26 14:20 [PATCH BlueZ 1/6] unit/test-avctp: Use tester framework Luiz Augusto von Dentz
2015-03-26 14:20 ` [PATCH BlueZ 2/6] android/avctp: Fix crashes caused by re-entrant calls Luiz Augusto von Dentz
2015-03-26 14:39 ` Szymon Janc
2015-03-26 14:20 ` [PATCH BlueZ 3/6] unit/test-avdtp: Use tester framework Luiz Augusto von Dentz
2015-03-26 14:20 ` Luiz Augusto von Dentz [this message]
2015-03-26 14:20 ` [PATCH BlueZ 5/6] android/avdtp: Fix test /TP/SIG/SMG/BI-19-C Luiz Augusto von Dentz
2015-03-26 14:20 ` [PATCH BlueZ 6/6] android/avdtp: Fix test /TP/SIG/SMG/BV-09-C Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1427379625-20412-4-git-send-email-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox