2011-06-13 10:49:49

by Rafal Michalski

[permalink] [raw]
Subject: [PATCH v2 1/4] Fix invalid write to memory issue in a2dp module

Under some circumstances (such as terminating bluetoothd during music is
streamed) sep object may be destroyed (memory for sep object is internally
freed, directly by "a2dp_unregister_sep") after invoking
"media_endpoint_clear_configuration" (in "stream_state_changed").
It leads to invalid write issue (reported by valgrind) after assignment
"sep->stream = NULL", since "sep" is "alias" pointer to sep object which
is already out of date (memory for sep object has been already freed)

This patch prevents from this issue by ensuring that assignment
"sep->stream = NULL" would be executed when sep object certainly exists.
---
audio/a2dp.c | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/audio/a2dp.c b/audio/a2dp.c
index b4ec274..f3e7af3 100644
--- a/audio/a2dp.c
+++ b/audio/a2dp.c
@@ -371,11 +371,10 @@ static void stream_state_changed(struct avdtp_stream *stream,
sep->session = NULL;
}

- if (sep->endpoint)
- media_endpoint_clear_configuration(sep->endpoint);
-
sep->stream = NULL;

+ if (sep->endpoint)
+ media_endpoint_clear_configuration(sep->endpoint);
}

static gboolean auto_config(gpointer data)
--
1.6.3.3



2011-06-14 09:08:38

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH v2 1/4] Fix invalid write to memory issue in a2dp module

Hi Rafal,

On Mon, Jun 13, 2011, Rafal Michalski wrote:
> Under some circumstances (such as terminating bluetoothd during music is
> streamed) sep object may be destroyed (memory for sep object is internally
> freed, directly by "a2dp_unregister_sep") after invoking
> "media_endpoint_clear_configuration" (in "stream_state_changed").
> It leads to invalid write issue (reported by valgrind) after assignment
> "sep->stream = NULL", since "sep" is "alias" pointer to sep object which
> is already out of date (memory for sep object has been already freed)
>
> This patch prevents from this issue by ensuring that assignment
> "sep->stream = NULL" would be executed when sep object certainly exists.
> ---
> audio/a2dp.c | 5 ++---
> 1 files changed, 2 insertions(+), 3 deletions(-)

All four patches have been pushed upstream. Thanks.

Johan