From: Kanishka De Silva <kpskanna1915@gmail.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: Oliver Neukum <oneukum@suse.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Kanishka De Silva <kpskanna1915@gmail.com>
Subject: [PATCH v2] usb: adutux: take buflock when resetting read_buffer_length in adu_open()
Date: Mon, 13 Jul 2026 13:26:16 +0530 [thread overview]
Message-ID: <20260713075616.1625-1-kpskanna1915@gmail.com> (raw)
In-Reply-To: <CAKJ0_Ldatt+6_q_Sudg8nCnJLz5Vc8eihK9O6mwKh7tKBZm8iw@mail.gmail.com>
dev->read_buffer_length is otherwise only ever touched under
dev->buflock (by adu_interrupt_in_callback() and adu_read()), per the
locking scheme documented in the comment above struct adu_device.
adu_open() resets it to 0 without holding buflock.
In the current code this is not a reachable race. adu_open() and
adu_release() are fully serialized by adutux_mutex, and
adu_release_internal() calls usb_kill_urb() (via
adu_abort_transfers()) before that mutex is dropped, which blocks
until any in-flight adu_interrupt_in_callback() has returned. The
write in adu_open() also precedes the urb (re)submission in program
order, so the callback cannot observe or race with it there either.
This change brings the assignment under buflock purely so the
field's locking is locally consistent with the driver's documented
scheme, making the invariant easy to verify without having to reason
across adu_open(), adu_release_internal(), and usb_kill_urb()'s
blocking semantics. No behavioral or functional change intended.
v2:
- Retitled and reframed from "fix unlocked read_buffer_length write
in adu_open() (data race)" to a lock-discipline consistency
change. Discussion on the RFC (with Oliver Neukum) established
that adutux_mutex serialization plus usb_kill_urb()'s blocking
semantics rule out any runtime-reachable race here, so this is
no longer presented as a bugfix. (Oliver Neukum, Greg
Kroah-Hartman)
Signed-off-by: Kanishka De Silva <kpskanna1915@gmail.com>
---
drivers/usb/misc/adutux.c | 3 ++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
index 1111111..2222222 100644
--- a/drivers/usb/misc/adutux.c
+++ b/drivers/usb/misc/adutux.c
@@ -337,7 +337,8 @@ static int adu_open(struct inode *inode, struct file *file)
file->private_data = dev;
/* initialize in direction */
- dev->read_buffer_length = 0;
+ spin_lock_irq(&dev->buflock);
+ dev->read_buffer_length = 0;
+ spin_unlock_irq(&dev->buflock);
/* fixup first read by having urb waiting for it */
usb_fill_int_urb(dev->interrupt_in_urb, dev->udev,
--
2.43.0
next prev parent reply other threads:[~2026-07-13 7:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-13 4:45 [PATCH RFC] usb: adutux: fix unlocked read_buffer_length write in adu_open() (data race) Kanishka De Silva
2026-07-13 5:15 ` Greg KH
2026-07-13 5:37 ` [PATCH] usb: adutux: fix unlocked read_buffer_length write in adu_open() Kanishka De Silva
2026-07-13 7:25 ` [PATCH RFC] usb: adutux: fix unlocked read_buffer_length write in adu_open() (data race) Oliver Neukum
2026-07-13 7:56 ` Kanishka De Silva [this message]
2026-07-13 12:03 ` [PATCH v2] usb: adutux: take buflock when resetting read_buffer_length in adu_open() Greg KH
2026-07-13 13:48 ` Alan Stern
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=20260713075616.1625-1-kpskanna1915@gmail.com \
--to=kpskanna1915@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=oneukum@suse.com \
/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®