Skip to contentSkip to conversation

most: usb: don't use a NULL device on disconnect

PATCH New Greg Kroah-Hartman 1 participant 1 message Oct 27 Most(r) technology driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 most: usb: don't use a NULL device on disconnect

From: Josef Bacik <[email protected]>

hdm_disconnect() clears mdev->usb_device before it stops the link status timer and the work which that timer schedules. wq_netinfo() does not expect a NULL pointer: it hands it to drci_rd_reg(), which dereferences it. Stop the timer and the work first.

The interface stays registered until the end of hdm_disconnect(), so hdm_request_netinfo() can still be called and arm the timer. Shut the timer down, rather than delete it, so that this has no effect.

wq_clear_halt() has the same problem. It is only cancelled when the channels are poisoned, by most_deregister_interface(), and cannot be cancelled earlier since the URB handlers schedule it. It takes io_mutex, like the code which clears the pointer, so test the pointer there.

Fixes a4198cdf0c34 ("Staging: most: add MOST driver's hdm-usb module")
Cc stable <[email protected]>
Cc Parthiban Veerasooran <[email protected]>
Cc Christian Gromm <[email protected]>
---
 drivers/most/most_usb.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/most/most_usb.c +8 -3
index 6437733afee0..9485f5a51f5f 100644
@@ -735,6 +735,10 @@ static void wq_clear_halt(struct work_struct *wq_obj)
 	int peer;
 
 	mutex_lock(&mdev->io_mutex);
+	if (!mdev->usb_device) {
+		mutex_unlock(&mdev->io_mutex);
+		return;
+	}
 	most_stop_enqueue(&mdev->iface, channel);
 	usb_kill_anchored_urbs(&mdev->busy_urbs[channel]);
 	if (usb_clear_halt(mdev->usb_device, pipe))
@@ -1108,14 +1112,15 @@ static void hdm_disconnect(struct usb_interface *interface)
 {
 	struct most_dev *mdev = usb_get_intfdata(interface);
 
+	/* hdm_request_netinfo() can still be called, and arms the timer */
+	timer_shutdown_sync(&mdev->link_stat_timer);
+	cancel_work_sync(&mdev->poll_work_obj);
+
 	mutex_lock(&mdev->io_mutex);
 	usb_set_intfdata(interface, NULL);
 	mdev->usb_device = NULL;
 	mutex_unlock(&mdev->io_mutex);
 
-	timer_delete_sync(&mdev->link_stat_timer);
-	cancel_work_sync(&mdev->poll_work_obj);
-
 	if (mdev->dci)
 		device_unregister(&mdev->dci->dev);
 	most_deregister_interface(&mdev->iface);
Signature · 1 line
2.56.0