Skip to content

Commit bd8b820

Browse files
shuahkhgregkh
authored andcommitted
usbip: vudc synchronize sysfs code paths
Fuzzing uncovered race condition between sysfs code paths in usbip drivers. Device connect/disconnect code paths initiated through sysfs interface are prone to races if disconnect happens during connect and vice versa. Use sysfs_lock to protect sysfs paths in vudc. Cc: [email protected] Reported-and-tested-by: [email protected] Signed-off-by: Shuah Khan <[email protected]> Link: https://lore.kernel.org/r/caabcf3fc87bdae970509b5ff32d05bb7ce2fb15.1616807117.git.skhan@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9dbf34a commit bd8b820

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

drivers/usb/usbip/vudc_dev.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ static int init_vudc_hw(struct vudc *udc)
572572
init_waitqueue_head(&udc->tx_waitq);
573573

574574
spin_lock_init(&ud->lock);
575+
mutex_init(&ud->sysfs_lock);
575576
ud->status = SDEV_ST_AVAILABLE;
576577
ud->side = USBIP_VUDC;
577578

drivers/usb/usbip/vudc_sysfs.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ static ssize_t usbip_sockfd_store(struct device *dev,
112112
dev_err(dev, "no device");
113113
return -ENODEV;
114114
}
115+
mutex_lock(&udc->ud.sysfs_lock);
115116
spin_lock_irqsave(&udc->lock, flags);
116117
/* Don't export what we don't have */
117118
if (!udc->driver || !udc->pullup) {
@@ -187,6 +188,8 @@ static ssize_t usbip_sockfd_store(struct device *dev,
187188

188189
wake_up_process(udc->ud.tcp_rx);
189190
wake_up_process(udc->ud.tcp_tx);
191+
192+
mutex_unlock(&udc->ud.sysfs_lock);
190193
return count;
191194

192195
} else {
@@ -207,6 +210,7 @@ static ssize_t usbip_sockfd_store(struct device *dev,
207210
}
208211

209212
spin_unlock_irqrestore(&udc->lock, flags);
213+
mutex_unlock(&udc->ud.sysfs_lock);
210214

211215
return count;
212216

@@ -216,6 +220,7 @@ static ssize_t usbip_sockfd_store(struct device *dev,
216220
spin_unlock_irq(&udc->ud.lock);
217221
unlock:
218222
spin_unlock_irqrestore(&udc->lock, flags);
223+
mutex_unlock(&udc->ud.sysfs_lock);
219224

220225
return ret;
221226
}

0 commit comments

Comments
 (0)