Netdev List
 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
  0 siblings, 1 reply; 2+ 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] 2+ 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
  0 siblings, 0 replies; 2+ 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] 2+ messages in thread

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

Thread overview: 2+ 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

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