Linux USB
 help / color / mirror / Atom feed
* [PATCH net] net: hso: fix use-after-free after failed tty open
@ 2026-12-01 10:13 Yannick Müller
  2026-12-01 10:18 ` netdev-bot+sinfo
  2026-12-02 10:15 ` sashiko-bot
  0 siblings, 2 replies; 3+ messages in thread
From: Yannick Müller @ 2026-12-01 10:13 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: Johan Hovold, linux-usb, netdev, Yannick Müller

hso_serial_open() takes a reference to the serial device only if the
first open succeeds. The tty core, however, calls the cleanup()
operation after a failed open as well, and hso_serial_cleanup() drops a
reference whenever the driver data of the tty is set, which
hso_serial_open() does before it tries to start the device.

A first open that fails to start the device therefore drops the
reference taken at probe. The serial device is freed while its tty
device and its serial_table[] entry are still registered, and the next
open or the disconnect uses the freed memory.

Take the reference when the tty is bound to the serial device instead,
so that cleanup() always drops a reference that the tty holds.

The failed open has dropped one reference too many since the driver was
added. Commit 29bd3bc1194c ("hso: fix crash when device disappears
while serial port is open") only moved the final drop from close() to
cleanup().

Fixes: 72dc1c096c70 ("HSO: add option hso driver")
Cc: stable@vger.kernel.org
Signed-off-by: Yannick Müller <mail@ynnk.dev>
---
 drivers/net/usb/hso.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index 71caa3764b23..9d43e573d347 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -1250,7 +1250,11 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
 	hso_dbg(0x1, "Opening %d\n", serial->minor);
 
 	/* setup */
-	tty->driver_data = serial;
+	if (tty->driver_data != serial) {
+		/* The tty holds a reference until hso_serial_cleanup(). */
+		kref_get(&serial->parent->ref);
+		tty->driver_data = serial;
+	}
 	tty_port_tty_set(&serial->port, tty);
 
 	/* check for port already opened, if not set the termios */
@@ -1265,8 +1269,6 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
 		if (result) {
 			hso_stop_serial_device(serial->parent);
 			serial->port.count--;
-		} else {
-			kref_get(&serial->parent->ref);
 		}
 	} else {
 		hso_dbg(0x1, "Port was already open\n");

base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d
-- 
2.47.3


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

* Re: [PATCH net] net: hso: fix use-after-free after failed tty open
  2026-12-01 10:13 [PATCH net] net: hso: fix use-after-free after failed tty open Yannick Müller
@ 2026-12-01 10:18 ` netdev-bot+sinfo
  2026-12-02 10:15 ` sashiko-bot
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-12-01 10:18 UTC (permalink / raw)
  To: Yannick Müller
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Johan Hovold, linux-usb, netdev

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

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

* Re: [PATCH net] net: hso: fix use-after-free after failed tty open
  2026-12-01 10:13 [PATCH net] net: hso: fix use-after-free after failed tty open Yannick Müller
  2026-12-01 10:18 ` netdev-bot+sinfo
@ 2026-12-02 10:15 ` sashiko-bot
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-02 10:15 UTC (permalink / raw)
  To: Yannick Müller; +Cc: linux-usb

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] net: usb: hso: active serial URBs not killed in
  hso_free_interface() [1]
--

commit 6069581307322cf466dfc112f9e4e7a8b3902bd1
Author: Yannick Müller <mail@ynnk.dev>

net: hso: fix use-after-free after failed tty open

This commit takes the serial device reference when binding tty->driver_data
in hso_serial_open() rather than after hso_start_serial_device() succeeds,
so that a failed initial open does not drop the probe reference in
hso_serial_cleanup().

> diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
> index 71caa3764b239..9d43e573d3478 100644
> --- a/drivers/net/usb/hso.c
> +++ b/drivers/net/usb/hso.c
> @@ -1250,7 +1250,11 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
>  	hso_dbg(0x1, "Opening %d\n", serial->minor);
>  
>  	/* setup */
> -	tty->driver_data = serial;
> +	if (tty->driver_data != serial) {
> +		/* The tty holds a reference until hso_serial_cleanup(). */
> +		kref_get(&serial->parent->ref);
> +		tty->driver_data = serial;
> +	}
>  	tty_port_tty_set(&serial->port, tty);
>  
>  	/* check for port already opened, if not set the termios */
> @@ -1265,8 +1269,6 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
>  		if (result) {
>  			hso_stop_serial_device(serial->parent);
>  			serial->port.count--;
> -		} else {
> -			kref_get(&serial->parent->ref);
>  		}
>  	} else {
>  		hso_dbg(0x1, "Port was already open\n");

[Severity: Critical]
This problem wasn't introduced by this patch, but can disconnecting an open
serial port leave in-flight URBs active when the final reference is dropped in
hso_serial_cleanup() [1]?

When an interface is torn down while a serial port is open,
hso_free_interface() sets serial->parent->usb_gone = 1 and drops the probe
reference without calling hso_stop_serial_device():

drivers/net/usb/hso.c:hso_free_interface() {
	...
			serial = dev2ser(serial_table[i]);
			tty_port_tty_hangup(&serial->port, false);
			mutex_lock(&serial->parent->mutex);
			serial->parent->usb_gone = 1;
			mutex_unlock(&serial->parent->mutex);
			cancel_work_sync(&serial_table[i]->async_put_intf);
			cancel_work_sync(&serial_table[i]->async_get_intf);
			hso_serial_tty_unregister(serial);
			kref_put(&serial->parent->ref, hso_serial_ref_free);
	...
}

When userspace then closes the hung-up TTY, hso_serial_close() sees usb_gone
set and skips hso_stop_serial_device():

drivers/net/usb/hso.c:hso_serial_close() {
	...
	if (serial->port.count <= 0) {
		serial->port.count = 0;
		tty_port_tty_set(&serial->port, NULL);
		if (!usb_gone)
			hso_stop_serial_device(serial->parent);
		tasklet_kill(&serial->unthrottle_tasklet);
	}
	...
}

hso_serial_cleanup() then drops the final serial->parent->ref, and
hso_free_serial_device() and hso_free_shared_int() call usb_free_urb() and
kfree() on active URBs and transfer buffers that were never killed via
usb_kill_urb(), triggering a WARN_ON in usb_free_urb() and a use-after-free
when those URBs complete.

[1] https://sashiko.dev/#/bug/linux-138610c9-94b5-4a04-b8c0-02e4a533d28f

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201101336.164922-1-mail@ynnk.dev?part=1

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

end of thread, other threads:[~2026-12-02 10:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 10:13 [PATCH net] net: hso: fix use-after-free after failed tty open Yannick Müller
2026-12-01 10:18 ` netdev-bot+sinfo
2026-12-02 10:15 ` sashiko-bot

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