From: Johan Hovold <johan@kernel.org>
To: linux-usb@vger.kernel.org
Cc: Peter Hurley <peter@hurleysoftware.com>,
linux-serial@vger.kernel.org, Johan Hovold <johan@kernel.org>,
stable <stable@vger.kernel.org>
Subject: [PATCH v2 2/2] USB: console: fix potential use after free
Date: Mon, 5 Jan 2015 16:04:13 +0100 [thread overview]
Message-ID: <1420470253-8141-2-git-send-email-johan@kernel.org> (raw)
In-Reply-To: <1420470253-8141-1-git-send-email-johan@kernel.org>
Use tty kref to release the fake tty in usb_console_setup to avoid use
after free if the underlying serial driver has acquired a reference.
Note that using the tty destructor release_one_tty requires some more
state to be initialised.
Fixes: 4a90f09b20f4 ("tty: usb-serial krefs")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
Changes since v1:
- Use tty_kref_put to release tty also in setup()
- Some more state must be initialised to avoid NULL derefs when the tty
destructor is run after the underlying driver puts its reference.
drivers/usb/serial/console.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
index e56f394b58d8..29fa1c3d0089 100644
--- a/drivers/usb/serial/console.c
+++ b/drivers/usb/serial/console.c
@@ -46,6 +46,8 @@ static struct console usbcons;
* ------------------------------------------------------------
*/
+static const struct tty_operations usb_console_fake_tty_ops = {
+};
/*
* The parsing of the command line works exactly like the
@@ -137,14 +139,17 @@ static int usb_console_setup(struct console *co, char *options)
goto reset_open_count;
}
kref_init(&tty->kref);
- tty_port_tty_set(&port->port, tty);
tty->driver = usb_serial_tty_driver;
tty->index = co->index;
init_ldsem(&tty->ldisc_sem);
+ INIT_LIST_HEAD(&tty->tty_files);
+ kref_get(&tty->driver->kref);
+ tty->ops = &usb_console_fake_tty_ops;
if (tty_init_termios(tty)) {
retval = -ENOMEM;
- goto free_tty;
+ goto put_tty;
}
+ tty_port_tty_set(&port->port, tty);
}
/* only call the device specific open if this
@@ -162,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
serial->type->set_termios(tty, port, &dummy);
tty_port_tty_set(&port->port, NULL);
- kfree(tty);
+ tty_kref_put(tty);
}
set_bit(ASYNCB_INITIALIZED, &port->port.flags);
}
@@ -178,8 +183,8 @@ static int usb_console_setup(struct console *co, char *options)
fail:
tty_port_tty_set(&port->port, NULL);
- free_tty:
- kfree(tty);
+ put_tty:
+ tty_kref_put(tty);
reset_open_count:
port->port.count = 0;
usb_autopm_put_interface(serial->interface);
--
2.0.5
next prev parent reply other threads:[~2015-01-05 15:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-18 16:18 USB-serial console and lockdep Johan Hovold
2015-01-01 2:07 ` Peter Hurley
[not found] ` <54A4ABFF.5000304-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org>
2015-01-03 16:26 ` Johan Hovold
2015-01-03 16:28 ` [PATCH 1/2] USB: console: fix uninitialised ldisc semaphore Johan Hovold
2015-01-03 16:28 ` [PATCH 2/2] USB: console: fix potential use after free Johan Hovold
2015-01-05 15:04 ` [PATCH v2 1/2] USB: console: fix uninitialised ldisc semaphore Johan Hovold
2015-01-05 15:04 ` Johan Hovold [this message]
2015-01-05 15:26 ` USB-serial console and lockdep Peter Hurley
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=1420470253-8141-2-git-send-email-johan@kernel.org \
--to=johan@kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=peter@hurleysoftware.com \
--cc=stable@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).