From: "Yannick Müller" <mail@ynnk.dev>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: "Johan Hovold" <johan@kernel.org>,
linux-usb@vger.kernel.org, netdev@vger.kernel.org,
"Yannick Müller" <mail@ynnk.dev>
Subject: [PATCH net] net: hso: fix use-after-free after failed tty open
Date: Tue, 1 Dec 2026 11:13:36 +0100 [thread overview]
Message-ID: <20261201101336.164922-1-mail@ynnk.dev> (raw)
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
next reply other threads:[~2026-12-01 10:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 10:13 Yannick Müller [this message]
2026-12-01 10:18 ` [PATCH net] net: hso: fix use-after-free after failed tty open netdev-bot+sinfo
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=20261201101336.164922-1-mail@ynnk.dev \
--to=mail@ynnk.dev \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=johan@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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