From: Shuah Khan <shuahkh@osg.samsung.com>
To: Sakari Ailus <sakari.ailus@iki.fi>
Cc: mchehab@osg.samsung.com, linux-media@vger.kernel.org,
linux-kernel@vger.kernel.org,
Shuah Khan <shuahkh@osg.samsung.com>
Subject: Re: [PATCH] media: fix media devnode ioctl/syscall and unregister race
Date: Fri, 17 Jun 2016 07:42:36 -0600 [thread overview]
Message-ID: <5763FE4C.3040007@osg.samsung.com> (raw)
In-Reply-To: <20160617060843.GE24980@valkosipuli.retiisi.org.uk>
On 06/17/2016 12:08 AM, Sakari Ailus wrote:
> Hi Shuah,
>
> On Fri, Jun 10, 2016 at 11:37:23AM -0600, Shuah Khan wrote:
>> Media devnode open/ioctl could be in progress when media device unregister
>> is initiated. System calls and ioctls check media device registered status
>> at the beginning, however, there is a window where unregister could be in
>> progress without changing the media devnode status to unregistered.
>>
>> process 1 process 2
>> fd = open(/dev/media0)
>> media_devnode_is_registered()
>> (returns true here)
>>
>> media_device_unregister()
>> (unregister is in progress
>> and devnode isn't
>> unregistered yet)
>> ...
>> ioctl(fd, ...)
>> __media_ioctl()
>> media_devnode_is_registered()
>> (returns true here)
>> ...
>> media_devnode_unregister()
>> ...
>> (driver releases the media device
>> memory)
>>
>> media_device_ioctl()
>> (By this point
>> devnode->media_dev does not
>> point to allocated memory.
>> use-after free in in mutex_lock_nested)
>>
>> BUG: KASAN: use-after-free in mutex_lock_nested+0x79c/0x800 at addr
>> ffff8801ebe914f0
>>
>> Fix it by clearing register bit when unregister starts to avoid the race.
>
> Does this patch solve the problem? You'd have to take the mutex for the
> duration of the IOCTL which I don't see the patch doing.
>
> Instead of serialising operations using mutexes, I believe a proper fix for
> this is to take a reference to the data structures required.
>
It fixes the problem Mauro and I have seen. It closes the window enough
to avoid problem. We have disconnected data structure issue as you pointed
out. media devnode register/unregister are protected by media_devnode_lock
and the graph is protected by graph_mutex. I avoided taking the mutex for
the entire duration of the ioctl.
I think what you are suggesting is that the ioctl take a reference to
media_device? One reason I avoided that is by doing that we will end up
with 3 different objects with varied lifetimes dependent on each other.
We have media_devnode and cdev dependency which handled by using devnode
struct dev as cdev parent. It is possible to link media_device to devnode
lifetime, by having media_ioctl or media_opne take reference to media_device.
Is that what you have in mind?
thanks,
-- Shuah
prev parent reply other threads:[~2016-06-17 13:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-10 17:37 Shuah Khan
2016-06-17 6:08 ` Sakari Ailus
2016-06-17 13:42 ` Shuah Khan [this message]
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=5763FE4C.3040007@osg.samsung.com \
--to=shuahkh@osg.samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@osg.samsung.com \
--cc=sakari.ailus@iki.fi \
/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®