From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Shuah Khan <shuahkh@osg.samsung.com>
Cc: valentina.manea.m@gmail.com, shuah@kernel.org,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: usbip: vhc_hcd: prevent module being removed while device are attached
Date: Tue, 3 Apr 2018 08:56:18 +0200 [thread overview]
Message-ID: <20180403065618.GA1093@kroah.com> (raw)
On Mon, Apr 02, 2018 at 02:52:31PM -0600, Shuah Khan wrote:
> vhci_hcd module can be removed even when devices are attached. Fix to
> prevent module removal when devices are still attached.
>
> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> ---
> drivers/usb/usbip/vhci_sysfs.c | 25 +++++++++++++++++++++----
> 1 file changed, 21 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/usb/usbip/vhci_sysfs.c b/drivers/usb/usbip/vhci_sysfs.c
> index 48808388ec33..6a54b9aa92be 100644
> --- a/drivers/usb/usbip/vhci_sysfs.c
> +++ b/drivers/usb/usbip/vhci_sysfs.c
> @@ -9,6 +9,7 @@
> #include <linux/net.h>
> #include <linux/platform_device.h>
> #include <linux/slab.h>
> +#include <linux/module.h>
>
> #include "usbip_common.h"
> #include "vhci.h"
> @@ -252,6 +253,8 @@ static ssize_t detach_store(struct device *dev, struct device_attribute *attr,
> if (ret < 0)
> return -EINVAL;
>
> + module_put(THIS_MODULE);
> +
> usbip_dbg_vhci_sysfs("Leave\n");
>
> return count;
> @@ -302,7 +305,7 @@ static ssize_t attach_store(struct device *dev, struct device_attribute *attr,
> struct vhci_hcd *vhci_hcd;
> struct vhci_device *vdev;
> struct vhci *vhci;
> - int err;
> + int err, ret;
> unsigned long flags;
>
> /*
> @@ -339,10 +342,18 @@ static ssize_t attach_store(struct device *dev, struct device_attribute *attr,
> else
> vdev = &vhci->vhci_hcd_hs->vdev[rhport];
>
> + /* get module ref to avoid being removed with active attached devs */
> + if (!try_module_get(THIS_MODULE)) {
> + ret = -EAGAIN;
> + goto module_get_err;
> + }
That's really not a good idea, trying to grab your own module reference
is considered racy and we stopped adding that code pattern to the kernel
a long time ago.
What's wrong if you remove the vhci module if devices are attached? You
can do that today for any other USB host driver, this shouldn't be
"special".
Also, kernel modules are never automatically removed by the system, so
someone has to do this by hand, so they knew what they were doing :)
thanks,
greg k-h
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next reply other threads:[~2018-04-03 6:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-03 6:56 Greg Kroah-Hartman [this message]
-- strict thread matches above, loose matches on Subject: below --
2018-04-18 16:43 usbip: vhc_hcd: prevent module being removed while device are attached Sasha Levin
2018-04-05 19:11 Greg KH
2018-04-05 17:09 Sasha Levin
2018-04-05 16:54 Shuah Khan
2018-04-05 16:42 Sasha Levin
2018-04-04 15:14 Shuah Khan
2018-04-04 8:25 Oliver Neukum
2018-04-03 15:56 Shuah Khan
2018-04-02 20:52 Shuah Khan
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=20180403065618.GA1093@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=shuahkh@osg.samsung.com \
--cc=valentina.manea.m@gmail.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;
as well as URLs for NNTP newsgroup(s).