linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usbip: vudc: fix null pointer dereference on udc->lock
@ 2018-02-22 17:39 Colin King
  2018-02-26 16:40 ` Shuah Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Colin King @ 2018-02-22 17:39 UTC (permalink / raw)
  To: Shuah Khan, Greg Kroah-Hartman, linux-usb; +Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently the driver attempts to spin lock on udc->lock before a NULL
pointer check is performed on udc, hence there is a potential null
pointer dereference on udc->lock.  Fix this by moving the null check
on udc before the lock occurs.

Fixes: ea6873a45a22 ("usbip: vudc: Add SysFS infrastructure for VUDC")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Shuah Khan <shuahkh@osg.samsung.com>
Reviewed-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Cc: stable <stable@vger.kernel.org>
---
 drivers/usb/usbip/vudc_sysfs.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/usbip/vudc_sysfs.c b/drivers/usb/usbip/vudc_sysfs.c
index d86f72bbbb91..6dcd3ff655c3 100644
--- a/drivers/usb/usbip/vudc_sysfs.c
+++ b/drivers/usb/usbip/vudc_sysfs.c
@@ -105,10 +105,14 @@ static ssize_t usbip_sockfd_store(struct device *dev, struct device_attribute *a
 	if (rv != 0)
 		return -EINVAL;
 
+	if (!udc) {
+		dev_err(dev, "no device");
+		return -ENODEV;
+	}
 	spin_lock_irqsave(&udc->lock, flags);
 	/* Don't export what we don't have */
-	if (!udc || !udc->driver || !udc->pullup) {
-		dev_err(dev, "no device or gadget not bound");
+	if (!udc->driver || !udc->pullup) {
+		dev_err(dev, "gadget not bound");
 		ret = -ENODEV;
 		goto unlock;
 	}
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] usbip: vudc: fix null pointer dereference on udc->lock
  2018-02-22 17:39 [PATCH] usbip: vudc: fix null pointer dereference on udc->lock Colin King
@ 2018-02-26 16:40 ` Shuah Khan
  2018-02-27 13:24   ` Krzysztof Opasiak
  0 siblings, 1 reply; 3+ messages in thread
From: Shuah Khan @ 2018-02-26 16:40 UTC (permalink / raw)
  To: Colin King, Greg Kroah-Hartman, linux-usb
  Cc: kernel-janitors, linux-kernel, Shuah Khan, Shuah Khan

On 02/22/2018 10:39 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently the driver attempts to spin lock on udc->lock before a NULL
> pointer check is performed on udc, hence there is a potential null
> pointer dereference on udc->lock.  Fix this by moving the null check
> on udc before the lock occurs.
> 
> Fixes: ea6873a45a22 ("usbip: vudc: Add SysFS infrastructure for VUDC")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/usb/usbip/vudc_sysfs.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/usbip/vudc_sysfs.c b/drivers/usb/usbip/vudc_sysfs.c
> index d86f72bbbb91..6dcd3ff655c3 100644
> --- a/drivers/usb/usbip/vudc_sysfs.c
> +++ b/drivers/usb/usbip/vudc_sysfs.c
> @@ -105,10 +105,14 @@ static ssize_t usbip_sockfd_store(struct device *dev, struct device_attribute *a
>  	if (rv != 0)
>  		return -EINVAL;
>  
> +	if (!udc) {
> +		dev_err(dev, "no device");
> +		return -ENODEV;
> +	}
>  	spin_lock_irqsave(&udc->lock, flags);
>  	/* Don't export what we don't have */
> -	if (!udc || !udc->driver || !udc->pullup) {
> -		dev_err(dev, "no device or gadget not bound");
> +	if (!udc->driver || !udc->pullup) {
> +		dev_err(dev, "gadget not bound");
>  		ret = -ENODEV;
>  		goto unlock;
>  	}
> 

Thanks for the patch. Looks good to me.

Acked-by: Shuah Khan <shuahkh@osg.samsung.com>

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usbip: vudc: fix null pointer dereference on udc->lock
  2018-02-26 16:40 ` Shuah Khan
@ 2018-02-27 13:24   ` Krzysztof Opasiak
  0 siblings, 0 replies; 3+ messages in thread
From: Krzysztof Opasiak @ 2018-02-27 13:24 UTC (permalink / raw)
  To: shuah, Colin King, Greg Kroah-Hartman, linux-usb
  Cc: kernel-janitors, linux-kernel, Shuah Khan



On 02/26/2018 05:40 PM, Shuah Khan wrote:
> On 02/22/2018 10:39 AM, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> Currently the driver attempts to spin lock on udc->lock before a NULL
>> pointer check is performed on udc, hence there is a potential null
>> pointer dereference on udc->lock.  Fix this by moving the null check
>> on udc before the lock occurs.
>>
>> Fixes: ea6873a45a22 ("usbip: vudc: Add SysFS infrastructure for VUDC")
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>> ---
>>   drivers/usb/usbip/vudc_sysfs.c | 8 ++++++--
>>   1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/usb/usbip/vudc_sysfs.c b/drivers/usb/usbip/vudc_sysfs.c
>> index d86f72bbbb91..6dcd3ff655c3 100644
>> --- a/drivers/usb/usbip/vudc_sysfs.c
>> +++ b/drivers/usb/usbip/vudc_sysfs.c
>> @@ -105,10 +105,14 @@ static ssize_t usbip_sockfd_store(struct device *dev, struct device_attribute *a
>>   	if (rv != 0)
>>   		return -EINVAL;
>>   
>> +	if (!udc) {
>> +		dev_err(dev, "no device");
>> +		return -ENODEV;
>> +	}
>>   	spin_lock_irqsave(&udc->lock, flags);
>>   	/* Don't export what we don't have */
>> -	if (!udc || !udc->driver || !udc->pullup) {
>> -		dev_err(dev, "no device or gadget not bound");
>> +	if (!udc->driver || !udc->pullup) {
>> +		dev_err(dev, "gadget not bound");
>>   		ret = -ENODEV;
>>   		goto unlock;
>>   	}
>>
> 
> Thanks for the patch. Looks good to me.
> 
> Acked-by: Shuah Khan <shuahkh@osg.samsung.com>

Reviewed-by: Krzysztof Opasiak <k.opasiak@samsung.com>

but you could fix also a similar bug one one function above 
(dev_desc_read()) ;)

Best regards,
-- 
Krzysztof Opasiak
Samsung R&D Institute Poland
Samsung Electronics

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-02-27 13:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-22 17:39 [PATCH] usbip: vudc: fix null pointer dereference on udc->lock Colin King
2018-02-26 16:40 ` Shuah Khan
2018-02-27 13:24   ` Krzysztof Opasiak

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).