From: Junzhe Li <ginger.jzllee@gmail.com>
To: gregkh@linuxfoundation.org
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] usb: misc: yurex: fix ordering of usb_deregister_dev() and usb_set_intfdata()
Date: Thu, 28 May 2026 16:27:51 +0800 [thread overview]
Message-ID: <20260528082751.204898-1-ginger.jzllee@gmail.com> (raw)
In yurex_disconnect(), usb_set_intfdata(interface, NULL) was called
before usb_deregister_dev(interface, &yurex_class).
This opens a race window with usb_open() in the USB core:
T0 (yurex_disconnect) T1 (usb_open)
-------------------------- -------------------------
usb_set_intfdata(iface, NULL) [t0]
fops = usb_minors[minor] [t1]
/* fops still valid here */
usb_deregister_dev()
usb_minors[minor] = NULL [t2]
file->f_op->open(inode, file)
yurex_open()
dev = usb_get_intfdata() [t3]
/* dev is NULL! */
Because t0 precedes t1 precedes t2 precedes t3, T1 can obtain the
file_operations pointer for the device (t1, while the minor is still
registered), then continue into yurex_open() where it calls
usb_get_intfdata() and gets NULL back, leading to a NULL dereference.
Fix the race by calling usb_deregister_dev() first, which removes the
device from usb_minors[] before the interface data pointer is cleared.
Any concurrent usb_open() that arrives after usb_deregister_dev()
returns will fail to look up the fops and will never reach yurex_open().
Reported-by: Junzhe Li <ginger.jzllee@gmail.com>
Closes: https://lore.kernel.org/linux-usb/2026042718-unwieldy-dicing-626f@gregkh
Signed-off-by: Junzhe Li <ginger.jzllee@gmail.com>
---
drivers/usb/misc/yurex.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/misc/yurex.c b/drivers/usb/misc/yurex.c
index 7a482cdee1e9..136272ac24ba 100644
--- a/drivers/usb/misc/yurex.c
+++ b/drivers/usb/misc/yurex.c
@@ -310,11 +310,12 @@ static void yurex_disconnect(struct usb_interface *interface)
int minor = interface->minor;
dev = usb_get_intfdata(interface);
- usb_set_intfdata(interface, NULL);
/* give back our minor */
usb_deregister_dev(interface, &yurex_class);
+ usb_set_intfdata(interface, NULL);
+
/* prevent more I/O from starting */
usb_poison_urb(dev->urb);
usb_poison_urb(dev->cntl_urb);
--
2.34.1
next reply other threads:[~2026-05-28 8:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-28 8:27 Junzhe Li [this message]
2026-05-28 9:56 ` [PATCH] usb: misc: yurex: fix ordering of usb_deregister_dev() and usb_set_intfdata() Oliver Neukum
2026-05-29 6:58 ` Ginger
2026-05-29 10:31 ` Oliver Neukum
2026-05-29 13:55 ` Ginger
-- strict thread matches above, loose matches on Subject: below --
2026-04-28 4:54 Ginger
2026-04-28 11:58 ` Greg KH
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=20260528082751.204898-1-ginger.jzllee@gmail.com \
--to=ginger.jzllee@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/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