From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: ashishsangwan2@gmail.com
Cc: linux-kernel@vger.kernel.org,
Ashish Sangwan <a.sangwan@samsung.com>,
Namjae Jeon <namjae.jeon@samsung.com>
Subject: Re: [PATCH] driver core: access dev->driver under dev->mutex in dev_uevent
Date: Wed, 14 Jan 2015 12:46:35 -0800 [thread overview]
Message-ID: <20150114204635.GD31119@kroah.com> (raw)
In-Reply-To: <1421259054-2574-1-git-send-email-a.sangwan@samsung.com>
On Wed, Jan 14, 2015 at 11:40:54PM +0530, ashishsangwan2@gmail.com wrote:
> From: Ashish Sangwan <a.sangwan@samsung.com>
>
> We have hit a race condition while parallely accessing device's uevent
> and rmmoding device's driver.
How are you doing that? By reading the uevent file and removing the
device?
Removing a kernel module is not a "normal" thing at all, so this type of
"error" is very low on anyone's list.
> In dev_uevent() first dev->driver is checked if
> present which becomes true but before calling add_uevent_var
> dev->driver is set to NULL and driver is freed in __device_release_driver().
> This results in either NULL pointer derefrence or invalid virtual address
> access. Fix this race by accessing dev->driver under dev->mutex.
>
> Signed-off-by: Ashish Sangwan <a.sangwan@samsung.com>
> Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
> ---
> drivers/base/core.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 97e2baf..f8e854a 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -326,8 +326,15 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
> if (dev->type && dev->type->name)
> add_uevent_var(env, "DEVTYPE=%s", dev->type->name);
>
> + /*
> + * dev->driver is set NULL under dev->mutex so it should be checked
> + * after acquiring dev->mutex. This prevents a race between
> + * __device_release_driver and dev_uevent.
> + */
> + device_lock(dev);
> if (dev->driver)
> add_uevent_var(env, "DRIVER=%s", dev->driver->name);
> + device_unlock(dev);
Always run your patches through checkpatch before sending them out so
you don't get grumpy email responses about how you need to run patches
through checkpatch before sending them out...
thanks,
greg k-h
next prev parent reply other threads:[~2015-01-14 20:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-14 18:10 [PATCH] driver core: access dev->driver under dev->mutex in dev_uevent ashishsangwan2
2015-01-14 20:46 ` Greg Kroah-Hartman [this message]
2015-01-19 18:20 ` Ashish Sangwan
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=20150114204635.GD31119@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=a.sangwan@samsung.com \
--cc=ashishsangwan2@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=namjae.jeon@samsung.com \
/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