mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: John Ernberg <john.ernberg@actia.se>
To: Valentina Manea <valentina.manea.m@gmail.com>,
	Shuah Khan <shuah@kernel.org>, Hongren Zheng <i@zenithal.me>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Nobuo Iwata <nobuo.iwata@fujixerox.co.jp>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Wiliam Puranen <wiliam.puranen@actia.se>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>,
	John Ernberg <john.ernberg@actia.se>
Subject: [PATCH] usbip: Stop tracking work context in event_handler()
Date: Mon, 3 Aug 2026 10:43:58 +0000	[thread overview]
Message-ID: <20260803104342.2790105-1-john.ernberg@actia.se> (raw)

From: Wiliam Puranen <wiliam.puranen@actia.se>

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: stable@vger.kernel.org # v4.6+
Assisted-by: claude:opus-5
Signed-off-by: Wiliam Puranen <wiliam.puranen@actia.se>
Signed-off-by: John Ernberg <john.ernberg@actia.se>
---
 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)
 	}
 
 	/* If usb reset is called from event handler */
-	if (usbip_in_eh(current))
+	if (usbip_in_eh())
 		return;
 
 	/* we already have busid_priv, just lock busid_lock */
diff --git a/drivers/usb/usbip/usbip_common.h b/drivers/usb/usbip/usbip_common.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);
 
 static inline int interface_to_busnum(struct usb_interface *interface)
 {
diff --git a/drivers/usb/usbip/usbip_event.c b/drivers/usb/usbip/usbip_event.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;
 }
 
-static struct task_struct *worker_context;
-
 static void event_handler(struct work_struct *work)
 {
 	struct usbip_device *ud;
 
-	if (worker_context == NULL) {
-		worker_context = current;
-	}
-
 	while ((ud = get_event()) != NULL) {
 		usbip_dbg_eh("pending event %lx\n", ud->event);
 
@@ -186,9 +180,9 @@ int usbip_event_happened(struct usbip_device *ud)
 }
 EXPORT_SYMBOL_GPL(usbip_event_happened);
 
-int usbip_in_eh(struct task_struct *task)
+int usbip_in_eh(void)
 {
-	if (task == worker_context)
+	if (current_work() == &usbip_work)
 		return 1;
 
 	return 0;
-- 
2.53.0

             reply	other threads:[~2026-08-03 10:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03 10:43 John Ernberg [this message]
2026-11-11 22:13 ` Michael Grzeschik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260803104342.2790105-1-john.ernberg@actia.se \
    --to=john.ernberg@actia.se \
    --cc=gregkh@linuxfoundation.org \
    --cc=i@zenithal.me \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=nobuo.iwata@fujixerox.co.jp \
    --cc=shuah@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=valentina.manea.m@gmail.com \
    --cc=wiliam.puranen@actia.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®