From: "Hans J. Koch" <hjk@hansjkoch.de>
To: Benedikt Spranger <b.spranger@linutronix.de>
Cc: linux-kernel@vger.kernel.org, hjk@hansjkoch.de,
gregkh@linuxfoundation.org, Alexander.Frank@eberspaecher.com
Subject: Re: [PATCH 2/2] uio: avoid module unloding of in module created UIO devices
Date: Thu, 6 Dec 2012 23:25:53 +0100 [thread overview]
Message-ID: <20121206222552.GC2611@local> (raw)
In-Reply-To: <1354797897-23423-3-git-send-email-b.spranger@linutronix.de>
On Thu, Dec 06, 2012 at 01:44:57PM +0100, Benedikt Spranger wrote:
> A kernel module can create a uio device. Get a reference to the module, if the
> UIO device is in use. Otherwise the device can be removed and a uio write or an
> access to am mmaped memory can cause a kernel Oops or other strange effects.
>
> Signed-off-by: Benedikt Spranger <b.spranger@linutronix.de>
> ---
> drivers/uio/uio.c | 8 ++++++++
> include/linux/uio_driver.h | 1 +
> 2 files changed, 9 insertions(+)
>
> diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
> index b96499a..3b62da0 100644
> --- a/drivers/uio/uio.c
> +++ b/drivers/uio/uio.c
> @@ -446,6 +446,7 @@ static void uio_release_listener(struct kref *kref)
> idev->info->release(idev->info);
>
> module_put(idev->owner);
> + module_put(idev->info->owner);
> kfree(listener);
> }
>
> @@ -468,6 +469,11 @@ static int uio_open(struct inode *inode, struct file *filep)
> goto out;
> }
>
> + if (!try_module_get(idev->info->owner)) {
> + ret = -ENODEV;
> + goto err_get_module;
> + }
> +
> listener = kmalloc(sizeof(*listener), GFP_KERNEL);
> if (!listener) {
> ret = -ENOMEM;
> @@ -493,6 +499,8 @@ err_infoopen:
>
> err_alloc_listener:
> module_put(idev->owner);
> +err_get_module:
> + module_put(idev->owner);
>
> out:
> return ret;
> diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
> index 1bc6493..2862de23 100644
> --- a/include/linux/uio_driver.h
> +++ b/include/linux/uio_driver.h
> @@ -95,6 +95,7 @@ struct uio_info {
> int (*open)(struct uio_info *info);
> void (*release)(struct uio_info *info);
> int (*irqcontrol)(struct uio_info *info, s32 irq_on);
> + struct module *owner;
Where is that needed? I won't add a new element to struct uio_info without
an in-kernel user.
Thanks,
Hans
prev parent reply other threads:[~2012-12-06 22:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-06 12:44 [PATCH 0/2] uio: some fixes Benedikt Spranger
2012-12-06 12:44 ` [PATCH 1/2] uio: be aware of open(), mmap(), close() Benedikt Spranger
2012-12-06 22:28 ` Hans J. Koch
2012-12-06 12:44 ` [PATCH 2/2] uio: avoid module unloding of in module created UIO devices Benedikt Spranger
2012-12-06 22:25 ` Hans J. Koch [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=20121206222552.GC2611@local \
--to=hjk@hansjkoch.de \
--cc=Alexander.Frank@eberspaecher.com \
--cc=b.spranger@linutronix.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@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