Linux USB
 help / color / mirror / Atom feed
* [PATCH] USB: cdc-acm: fix racy TIOCMIWAIT implementation
@ 2026-09-07  6:55 Johan Hovold
  2026-09-07  8:17 ` Oliver Neukum
  0 siblings, 1 reply; 14+ messages in thread
From: Johan Hovold @ 2026-09-07  6:55 UTC (permalink / raw)
  To: Oliver Neukum, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Johan Hovold, stable, Oliver Neukum

The wakeup condition needs to be checked after adding the task to the
waitqueue and updating the task state to avoid missing a racing modem
status update or disconnect.

Fixes: 5a6a62bdb925 ("cdc-acm: add TIOCMIWAIT")
Cc: stable@vger.kernel.org	# 3.14
Cc: Oliver Neukum <oneukum@suse.de>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/class/cdc-acm.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 7bc5329fa3ed..00c250515e83 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -1027,7 +1027,10 @@ static int wait_serial_change(struct acm *acm, unsigned long arg)
 	DECLARE_WAITQUEUE(wait, current);
 	struct async_icount old, new;
 
-	do {
+	add_wait_queue(&acm->wioctl, &wait);
+	for (;;) {
+		set_current_state(TASK_INTERRUPTIBLE);
+
 		spin_lock_irq(&acm->read_lock);
 		old = acm->oldcount;
 		new = acm->iocount;
@@ -1044,22 +1047,20 @@ static int wait_serial_change(struct acm *acm, unsigned long arg)
 			old.rng != new.rng)
 			break;
 
-		add_wait_queue(&acm->wioctl, &wait);
-		set_current_state(TASK_INTERRUPTIBLE);
-		schedule();
-		remove_wait_queue(&acm->wioctl, &wait);
 		if (acm->disconnected) {
-			if (arg & TIOCM_CD)
-				break;
-			else
-				rv = -ENODEV;
-		} else {
-			if (signal_pending(current))
-				rv = -ERESTARTSYS;
+			rv = -ENODEV;
+			break;
 		}
-	} while (!rv);
 
-	
+		schedule();
+
+		if (signal_pending(current)) {
+			rv = -ERESTARTSYS;
+			break;
+		}
+	}
+	__set_current_state(TASK_RUNNING);
+	remove_wait_queue(&acm->wioctl, &wait);
 
 	return rv;
 }
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2026-09-11  6:57 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-07  6:55 [PATCH] USB: cdc-acm: fix racy TIOCMIWAIT implementation Johan Hovold
2026-09-07  8:17 ` Oliver Neukum
2026-09-07  8:47   ` Johan Hovold
2026-09-07  9:13     ` Johan Hovold
2026-09-07  9:50     ` Oliver Neukum
2026-09-07 10:01       ` Johan Hovold
2026-09-07 10:28         ` Oliver Neukum
2026-09-07 11:38           ` Johan Hovold
2026-09-07 12:46             ` Oliver Neukum
2026-09-07 13:03               ` Johan Hovold
2026-09-08  6:54                 ` Oliver Neukum
2026-09-08  7:12                   ` Johan Hovold
2026-09-08  9:23                     ` Oliver Neukum
2026-09-11  6:57                       ` Johan Hovold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox