Skip to content

Commit

Permalink
usbip: vudc: fix null pointer dereference on udc->lock
Browse files Browse the repository at this point in the history
commit df3334c 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: ea6873a ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Colin Ian King authored and gregkh committed Mar 19, 2018
1 parent f8187fd commit d4f0bf4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/usb/usbip/vudc_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,14 @@ static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,
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;
}
Expand Down

0 comments on commit d4f0bf4

Please sign in to comment.