[PATCH 4.15 016/128] usbip: vudc: fix null pointer dereference on udc->lock

2018-03-16 Thread Greg Kroah-Hartman
4.15-stable review patch.  If anyone has any objections, please let me know.

--

From: Colin Ian King 

commit df3334c223a033f562645712e832ca4cbb326bbf upstream.

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 
Acked-by: Shuah Khan 
Reviewed-by: Krzysztof Opasiak 
Cc: stable 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/usbip/vudc_sysfs.c |8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

--- a/drivers/usb/usbip/vudc_sysfs.c
+++ b/drivers/usb/usbip/vudc_sysfs.c
@@ -105,10 +105,14 @@ static ssize_t store_sockfd(struct devic
if (rv != 0)
return -EINVAL;
 
+   if (!udc) {
+   dev_err(dev, "no device");
+   return -ENODEV;
+   }
spin_lock_irqsave(>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;
}




[PATCH 4.15 016/128] usbip: vudc: fix null pointer dereference on udc->lock

2018-03-16 Thread Greg Kroah-Hartman
4.15-stable review patch.  If anyone has any objections, please let me know.

--

From: Colin Ian King 

commit df3334c223a033f562645712e832ca4cbb326bbf upstream.

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 
Acked-by: Shuah Khan 
Reviewed-by: Krzysztof Opasiak 
Cc: stable 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/usbip/vudc_sysfs.c |8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

--- a/drivers/usb/usbip/vudc_sysfs.c
+++ b/drivers/usb/usbip/vudc_sysfs.c
@@ -105,10 +105,14 @@ static ssize_t store_sockfd(struct devic
if (rv != 0)
return -EINVAL;
 
+   if (!udc) {
+   dev_err(dev, "no device");
+   return -ENODEV;
+   }
spin_lock_irqsave(>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;
}