All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tomasz Stanislawski <t.stanislaws@samsung.com>
To: Rob Clark <rob.clark@linaro.org>
Cc: linaro-mm-sig@lists.linaro.org, dri-devel@lists.freedesktop.org,
	linux-media@vger.kernel.org, patches@linaro.org,
	sumit.semwal@linaro.org, daniel@ffwll.ch, airlied@redhat.com,
	"Rob Clark" <rob@ti.com>,
	"Marek Szyprowski" <m.szyprowski@samsung.com>,
	'박경민' <kyungmin.park@samsung.com>, "InKi Dae" <daeinki@gmail.com>
Subject: Re: [PATCH] dma-buf: add get_dma_buf()
Date: Tue, 22 May 2012 15:47:12 +0200	[thread overview]
Message-ID: <4FBB98E0.8040600@samsung.com> (raw)
In-Reply-To: <1331913881-13105-1-git-send-email-rob.clark@linaro.org>

Hi,
I think I discovered an interesting issue with dma_buf.
I found out that dma_buf_fd does not increase reference
count for dma_buf::file. This leads to potential kernel
crash triggered by user space. Please, take a look on
the scenario below:

The applications spawns two thread. One of them is exporting DMABUF.

      Thread I         |   Thread II       | Comments
-----------------------+-------------------+-----------------------------------
dbuf = dma_buf_export  |                   | dma_buf is creates, refcount is 1
fd = dma_buf_fd(dbuf)  |                   | assume fd is set to 42, refcount is still 1
                       |      close(42)    | The file descriptor is closed asynchronously, dbuf's refcount drops to 0
                       |  dma_buf_release  | dbuf structure is freed, dbuf becomes a dangling pointer
int size = dbuf->size; |                   | the dbuf is dereferenced, causing a kernel crash
-----------------------+-------------------+-----------------------------------

I think that the problem could be fixed in two ways.
a) forcing driver developer to call get_dma_buf just before calling dma_buf_fd.
b) increasing dma_buf->file's reference count at dma_buf_fd

I prefer solution (b) because it prevents symmetry between dma_buf_fd and close.
I mean that dma_buf_fd increases reference count, close decreases it.

What is your opinion about the issue?

Regards,
Tomasz Stanislawski



On 03/16/2012 05:04 PM, Rob Clark wrote:
> From: Rob Clark <rob@ti.com>
> 
> Works in a similar way to get_file(), and is needed in cases such as
> when the exporter needs to also keep a reference to the dmabuf (that
> is later released with a dma_buf_put()), and possibly other similar
> cases.
> 
> Signed-off-by: Rob Clark <rob@ti.com>
> ---

  parent reply	other threads:[~2012-05-22 13:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-16 16:04 [PATCH] dma-buf: add get_dma_buf() Rob Clark
2012-03-16 17:53 ` [Linaro-mm-sig] " Dave Airlie
2012-03-18  7:42   ` Sumit Semwal
2012-03-18 19:04     ` Daniel Vetter
2012-03-18 19:15       ` Daniel Vetter
2012-03-18 19:15         ` Daniel Vetter
2012-05-22 13:47 ` Tomasz Stanislawski [this message]
2012-05-22 14:32   ` Daniel Vetter
2012-05-22 15:00     ` Tomasz Stanislawski
2012-05-22 15:05       ` Daniel Vetter
2012-05-22 15:13         ` Dave Airlie
2012-05-22 17:37           ` Rob Clark
  -- strict thread matches above, loose matches on Subject: below --
2012-03-16 20:02 Rob Clark
2012-03-16 20:02 ` Rob Clark

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=4FBB98E0.8040600@samsung.com \
    --to=t.stanislaws@samsung.com \
    --cc=airlied@redhat.com \
    --cc=daeinki@gmail.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kyungmin.park@samsung.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-media@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=patches@linaro.org \
    --cc=rob.clark@linaro.org \
    --cc=rob@ti.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.