Linux bluetooth development
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@tieto.com>
To: Andrei Emeltchenko <Andrei.Emeltchenko.news@gmail.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH] android/scpp: Fix using freed memory
Date: Mon, 22 Dec 2014 14:13:53 +0100	[thread overview]
Message-ID: <3155639.Ajs76qMxjk@leonov> (raw)
In-Reply-To: <1419248953-31147-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

On Monday 22 of December 2014 13:49:13 Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> 
> Fixes use after free memory bug.
> req is assigned to user_data and then freed with destroy_gatt_req(req)
> ---
>  android/scpp.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/android/scpp.c b/android/scpp.c
> index 77f48cd..9f60c9f 100644
> --- a/android/scpp.c
> +++ b/android/scpp.c
> @@ -301,8 +301,6 @@ static void refresh_discovered_cb(uint8_t status, GSList
> *chars, uint16_t start, end;
>  	bt_uuid_t uuid;
> 
> -	destroy_gatt_req(req);
> -
>  	if (status) {
>  		error("Scan Refresh %s", att_ecode2str(status));
>  		return;
> @@ -329,6 +327,8 @@ static void refresh_discovered_cb(uint8_t status, GSList
> *chars,
> 
>  	discover_desc(scan, scan->attrib, start, end, &uuid,
>  					discover_descriptor_cb, user_data);
> +
> +	destroy_gatt_req(req);
>  }
> 
>  static void iwin_discovered_cb(uint8_t status, GSList *chars, void
> *user_data)

This patch doesn't fix the bug (actually it introduces some memleaks).

>From what I see in code gatt_request is packing userdata passed to 
discover_desc() so I think fix should be like:

--- a/android/scpp.c
+++ b/android/scpp.c
@@ -328,7 +328,7 @@ static void refresh_discovered_cb(uint8_t status, GSList 
*chars,
        bt_uuid16_create(&uuid, GATT_CLIENT_CHARAC_CFG_UUID);
 
        discover_desc(scan, scan->attrib, start, end, &uuid,
-                                       discover_descriptor_cb, user_data);
+                                       discover_descriptor_cb, scan);


Although here scan and userdata seems reluctant (since req is already holding 
sccp instance).

I'd wait for Luiz to comment on this since he wrote most of the scpp code.

-- 
BR
Szymon Janc

  reply	other threads:[~2014-12-22 13:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-22 11:49 [PATCH] android/scpp: Fix using freed memory Andrei Emeltchenko
2014-12-22 13:13 ` Szymon Janc [this message]
2014-12-22 13:30   ` Andrei Emeltchenko
2014-12-22 14:07     ` 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=3155639.Ajs76qMxjk@leonov \
    --to=szymon.janc@tieto.com \
    --cc=Andrei.Emeltchenko.news@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