[PATCH] usbip: Stop tracking work context in event_handler()

John Ernberg <[email protected]> Mon, 3 Aug 2026 10:43:58 +0000
Newsgroups org.kernel.vger.linux-usb,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <[email protected]>
From: Wiliam Puranen <[email protected]>

The work queue used by usbip is not pinned to a specific context.

When usbip_in_eh() evaluates if the call comes from the event handler
it doesn't actually check if the call comes from the event handler but
if the call comes from the same context as the event handler was first
called from.

This can result in "sticky" devices on the client side, due to the
teardown path in stub_disconnect() being lied to, and thus skipping
the teardown when it shouldn't, or vice versa.

Fixes: bb7871ad99ea ("usbip: event handler as one thread")
Cc: [email protected] # v4.6+
Assisted-by: claude:opus-5
Signed-off-by: Wiliam Puranen <[email protected]>
Signed-off-by: John Ernberg <[email protected]>
---
 drivers/usb/usbip/stub_dev.c     |  2 +-
 drivers/usb/usbip/usbip_common.h |  2 +-
 drivers/usb/usbip/usbip_event.c  | 10 ++--------
 3 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/usbip/stub_dev.c b/drivers/usb/usbip/stub_dev.c
index abfa11d6bde7..407ac55d85c5 100644
--- a/drivers/usb/usbip/stub_dev.c
+++ b/drivers/usb/usbip/stub_dev.c
@@ -474,7 +474,7 @@ static void stub_disconnect(struct usb_device *udev)
 	}
=20
 	/* If usb reset is called from event handler */
-	if (usbip_in_eh(current))
+	if (usbip_in_eh())
 		return;
=20
 	/* we already have busid_priv, just lock busid_lock */
diff --git a/drivers/usb/usbip/usbip_common.h b/drivers/usb/usbip/usbip_com=
mon.h
index be4c5e65a7f8..2c91187e6469 100644
--- a/drivers/usb/usbip/usbip_common.h
+++ b/drivers/usb/usbip/usbip_common.h
@@ -321,7 +321,7 @@ int usbip_start_eh(struct usbip_device *ud);
 void usbip_stop_eh(struct usbip_device *ud);
 void usbip_event_add(struct usbip_device *ud, unsigned long event);
 int usbip_event_happened(struct usbip_device *ud);
-int usbip_in_eh(struct task_struct *task);
+int usbip_in_eh(void);
=20
 static inline int interface_to_busnum(struct usb_interface *interface)
 {
diff --git a/drivers/usb/usbip/usbip_event.c b/drivers/usb/usbip/usbip_even=
t.c
index 0e00c2d000f8..695af652c512 100644
--- a/drivers/usb/usbip/usbip_event.c
+++ b/drivers/usb/usbip/usbip_event.c
@@ -57,16 +57,10 @@ static struct usbip_device *get_event(void)
 	return ud;
 }
=20
-static struct task_struct *worker_context;
-
 static void event_handler(struct work_struct *work)
 {
 	struct usbip_device *ud;
=20
-	if (worker_context =3D=3D NULL) {
-		worker_context =3D current;
-	}
-
 	while ((ud =3D get_event()) !=3D NULL) {
 		usbip_dbg_eh("pending event %lx\n", ud->event);
=20
@@ -186,9 +180,9 @@ int usbip_event_happened(struct usbip_device *ud)
 }
 EXPORT_SYMBOL_GPL(usbip_event_happened);
=20
-int usbip_in_eh(struct task_struct *task)
+int usbip_in_eh(void)
 {
-	if (task =3D=3D worker_context)
+	if (current_work() =3D=3D &usbip_work)
 		return 1;
=20
 	return 0;
--=20
2.53.0