Received: by 10.213.65.68 with SMTP id h4csp3675907imn; Tue, 3 Apr 2018 08:57:46 -0700 (PDT) X-Google-Smtp-Source: AIpwx49zMaiHeqz3vtuDMTW1RY3eZMd8RZaLMgkMhQ5rJ4nBx8Qwm+8EEKpKt5dIwnXsZDgIWMlD X-Received: by 10.98.236.220 with SMTP id e89mr10899675pfm.173.1522771066749; Tue, 03 Apr 2018 08:57:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522771066; cv=none; d=google.com; s=arc-20160816; b=HnGaJ3UMs2cY/qcosbstBAUNEgHmIDtIZGNfOeUAiLvhw+h7kOyVbR/EZCUhdULrOM XlCme+ofF5WdsK0+re4T0M71JKYHHIvu8RGszTYVnFgARInPmLOkA11hSWZYS3AifJlA RhL/1TX/nBXxvoKJHC7f7FK6GvU2UkqwQGgZKxbWJ4D0mph5tACPyCXO3/7Q/KMH60Ii rt/COiGxkO7ibzn9F09SG4g0pcbgUF36fXVl1sLvvA+dfBa0Hh1HokaaARIurw9wgRTg /taGlDzLRGrViM180VCgp2UiC1TPhywO4B/IxW5QooGecNjBvY9vwLI0iW2Z4cnKaDtV J7nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :arc-authentication-results; bh=ASJHBKTzlQ+GPY/dn4zuSbxg7YhzLN+iJ5xDYbB9kjQ=; b=mH8lsh/Fam5ZUZbcjdtpTuEIq6jnCMbIZ+ZRfpIEVX5Kxem1yveX5KOyQOD01jcNIk 6IUswfC8b0vk1rxvHGuUfuuzgA/K1Xy3gXxP2w75/O4zqJL8R8qI3CRSr4Z5A/znxv7I KbeM9fmwWJd1smV01MeSuVNVGlC/6V54nDOChsQLSxPlSdjugeyehuEfDc3q0bcTQfWC MaNJitjIlEZ3K52qhY/aw3DdLaUudMD3wDrxP+sxgAveL1hQ2I49D53FCf+lpxsQCkWo zhmetnMOM3crmfNLXf463vEugOrwnZ2jZcSwYnEZZv8r+tIpprlYNF7Dphj8eoNXQ3p9 zWZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o11-v6si758856plk.199.2018.04.03.08.57.32; Tue, 03 Apr 2018 08:57:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752075AbeDCP4T (ORCPT + 99 others); Tue, 3 Apr 2018 11:56:19 -0400 Received: from osg.samsung.com ([64.30.133.232]:57924 "EHLO osg.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751323AbeDCP4R (ORCPT ); Tue, 3 Apr 2018 11:56:17 -0400 Received: from localhost (localhost [127.0.0.1]) by osg.samsung.com (Postfix) with ESMTP id B29E3281F4; Tue, 3 Apr 2018 08:56:16 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at dev.s-opensource.com Received: from osg.samsung.com ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id i_YbdcKoMLhV; Tue, 3 Apr 2018 08:56:15 -0700 (PDT) Received: from [192.168.1.87] (c-24-9-64-241.hsd1.co.comcast.net [24.9.64.241]) by osg.samsung.com (Postfix) with ESMTPSA id 1B28F281E9; Tue, 3 Apr 2018 08:56:15 -0700 (PDT) Subject: Re: [PATCH] usbip: vhc_hcd: prevent module being removed while device are attached To: Greg KH Cc: valentina.manea.m@gmail.com, shuah@kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Shuah Khan References: <20180402205232.21659-1-shuahkh@osg.samsung.com> <20180403065618.GA1093@kroah.com> From: Shuah Khan Openpgp: preference=signencrypt Autocrypt: addr=shuahkh@osg.samsung.com; prefer-encrypt=mutual; keydata= xsFNBFIzbI0BEADtNDUjCT2vg2pVl9+XAwjq43AnDpggRIWjq8c82lcGgt9WYeQ2ezoGHADx 9XS5dP8OUdf2e1j2GtxOA9DpuAE6KNp9q4n2WHl9Q6Y06JwaXcMKlqH1WzAu8QWDou8KC8UL k+Ma/80uqlwQDmy+SDuLSLSPXP03P3NfKII8vAdREVTDfDzle+IKXDgYB8E5On1533QNVXdH rWQOU/SggOF8pGklv/a8VMR6KUYbkkkFy9wGLSLeBUx6ZfRkZSYBcAinwHLqWyDGB1993l1K y/FArlfEYLjKZ9od9ZGmnA3Ww9EMqpUUTP9b7a/sNuBhmsk5WVwMhMEtCxtIxHj0PVX8+m2R mj7mvdBukwsBOfu4ef0tK8CJHUNOXpWwNEl8LY1S+yJS/AZuwvzjpmfNQCzdixGG48oAeb11 9YKDCAUP0gjI44jZOiWb38jUn1SGqphW4i2jSiDi9R82mCtrcEXFHUuom2aRGyXEVdL9cEor 9/e4uaLDDZPGI4QqlbH6VoJkLzNFTAZnCKW9UsPXonQ7lP9hzH4+3sekYDkpmm2FcIXfVBRC XQPri2YuJtk/tgjuTC/5Y+b1itiI/xuKj7YmTYwFICUjYF9ehNe/6giG7zYZPIp2cr+oKwW5 OTo49wqTdUVm84gULn90p2YQlXnbcw81l+K09AvGj5BntvmjDQARAQABzSFTaHVhaCBLaGFu IDxzaHVhaEBnb25laGlraW5nLm9yZz7CwXoEEwECACQCGwMCHgECF4AFCwkIBwMFFQoJCAsF FgIDAQAFAlIzc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9GyT/t3HsKs= Message-ID: <6022b8f0-821a-2d1c-8032-4b298835feae@osg.samsung.com> Date: Tue, 3 Apr 2018 09:56:14 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180403065618.GA1093@kroah.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/03/2018 12:56 AM, Greg KH wrote: > 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 >> --- >> 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 >> #include >> #include >> +#include >> >> #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. Thanks. Good to know. > > 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". This is a virtual device associated to a real physical device on a different system. My concern is that if the module gets removed accidentally then it could disrupt access to the remote device. The remote nature of the device with several players involved makes this scenario a bit more complex than a regular usb case when device is physically on the system. It is probably one of the minor problems that could happen with a remote device. I found a few modules that hold reference to themselves in the kernel. Block, crypto, net, md, vfio, nfs. md for example holds reference to itself when it creates a blank device. vfio get regerence to itself it when opens pci and mediated devices. Some network drivers do the same for handling virtual functions. nfs does this for rpc handling. I am not making a case for adding one more, however I am curious if this vhci_hcd falls into a similar special case of handling virtual connections and devices. > > 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 :) > Yes. This will not be a usual scenario. The question is whether not kernel should detect driver is in use and prevent it. thanks, -- Shuah