mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: EunTaik Lee <eun.taik.lee@samsung.com>
To: "Laura Abbott" <labbott@redhat.com>,
	이은택 <eun.taik.lee@samsung.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"arve@android.com" <arve@android.com>,
	"riandrews@android.com" <riandrews@android.com>,
	"sumit.semwal@linaro.org" <sumit.semwal@linaro.org>,
	"gioh.kim@lge.com" <gioh.kim@lge.com>,
	"dan.carpenter@oracle.com" <dan.carpenter@oracle.com>,
	"Rohit Kumar" <rohit.kr@samsung.com>,
	"sriram@marirs.net.in" <sriram@marirs.net.in>,
	"shawn.lin@rock-chips.com" <shawn.lin@rock-chips.com>,
	"devel@driverdev.osuosl.org" <devel@driverdev.osuosl.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: Re: [RFC PATCH] staging/android/ion : fix a race condition in the ion driver
Date: Thu, 18 Feb 2016 08:07:07 +0000 (GMT)	[thread overview]
Message-ID: <700032691.1082951455782822577.JavaMail.weblogic@epmlwas08c> (raw)

2016-02-18 3:54 GMT+09:00 Laura Abbott <labbott@redhat.com>:
> On 02/16/2016 10:32 PM, EunTaik Lee wrote:
>> There was a use-after-free problem in the ion driver.
>>
>> The problem is detected as an unaligned access in the
>> spin lock functions since it uses load exclusive
>>   instruction. In some cases it corrupts the slub's
>> free pointer which causes a unaligned access to the
>> next free pointer.(thus the kmalloc function returns
>> a pointer like ffffc0745b4580aa). And it causes lots of other
>> hard-to-debug problems.
>>
>> This symptom is caused since the first member in the
>> ion_handle structure is the reference count and the
>> ion driver decrements the reference after it has been
>> freed.
>>
>> To fix this problem client->lock mutex is extended
>> to protect all the codes that uses the handle.
>>
>
> This describes the symptoms very well but what's the actual
> race condition?

The actual race condition was in case ION_IOC_FREE of ion_ioctl()
function.

A handle has ref count of 1 and two tasks on different
cpus calls ION_IOC_FREE simultaneously.

cpu 0					cpu 1
-------------------------------------------------------
ion_handle_get_by_id()
(ref == 2)
				ion_handle_get_by_id()
				(ref == 3)

ion_free()
(ref == 2)

ion_handle_put()
(ref == 1)

				ion_free()
				(ref == 0 so ion_handle_destroy() is called
				 and the handle is freed.)
				
				ion_handle_put() is called and it
				decreases the slub's next free pointer

So it's basically a double free on the userspace.
But I made this patch since I don't think we should 
take a risk of such a malicious code to mess up
the kernel.

> Also what tree did you generate this against? It doesn't
> seem to apply.

The patch was generated against the stable-kernel.
I will resend the patch using the latest stable-kernel
along with a silly mistake that I've made when merging the
patch(made against 3.18.20) to the stable-kernel.
(Thank you Julia <julia.lawall@lip6.fr> for pointing out
 my mistake)

                 reply	other threads:[~2016-02-18  8:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=700032691.1082951455782822577.JavaMail.weblogic@epmlwas08c \
    --to=eun.taik.lee@samsung.com \
    --cc=arve@android.com \
    --cc=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gioh.kim@lge.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=labbott@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=riandrews@android.com \
    --cc=rohit.kr@samsung.com \
    --cc=shawn.lin@rock-chips.com \
    --cc=sriram@marirs.net.in \
    --cc=sumit.semwal@linaro.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

all inboxes | Powered by JetHome®