Linux Serial subsystem development
 help / color / mirror / Atom feed
* [PATCH] tty/serial: atmel: use port->name as name in request_irq()
@ 2018-04-26 15:06 Sebastian Andrzej Siewior
  2018-04-26 15:12 ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 13+ messages in thread
From: Sebastian Andrzej Siewior @ 2018-04-26 15:06 UTC (permalink / raw)
  To: linux-serial
  Cc: Alexandre Belloni, Peter Hurley, Richard Genoud,
	Greg Kroah-Hartman, Jiri Slaby, tglx, linux-arm-kernel

I was puzzled while looking at /proc/interrupts and random things showed
up between reboots. This occurred more often but I realised it later. The
"correct" output should be:
|38:      11861  atmel-aic5   2 Level     ttyS0

but I saw sometimes
|38:       6426  atmel-aic5   2 Level     tty1

and I accounted it wrongly as correct. This is use after free and the
former example randomly got the "old" pointer which pointed to the same
content. With SLAB_FREELIST_RANDOM and HARDENED I even got
|38:       7067  atmel-aic5   2 Level     E=Started User Manager for UID 0

or other nonsense.
As it turns out the tty, pointer that is accessed in atmel_startup(), is
freed() before atmel_shutdown(). It seems to happen quite often that the
tty for ttyS0 is allocated and freed while ->shutdown is not invoked. I
don't do anything special - just a systemd boot :)

It seems not to happen in v4.1.51 but it happens in v4.9 and v4.17-rc2
so if it broke accidentally it was not recently.

Use port->name as the IRQ name for request_irq(). This exists as long as
the driver is loaded so no use-after-free here.

Cc: stable@vger.kernel.org
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 drivers/tty/serial/atmel_serial.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index e287fe8f10fc..d3189816740e 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -1757,7 +1757,6 @@ static int atmel_startup(struct uart_port *port)
 {
 	struct platform_device *pdev = to_platform_device(port->dev);
 	struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
-	struct tty_struct *tty = port->state->port.tty;
 	int retval;
 
 	/*
@@ -1772,8 +1771,7 @@ static int atmel_startup(struct uart_port *port)
 	 * Allocate the IRQ
 	 */
 	retval = request_irq(port->irq, atmel_interrupt,
-			IRQF_SHARED | IRQF_COND_SUSPEND,
-			tty ? tty->name : "atmel_serial", port);
+			     IRQF_SHARED | IRQF_COND_SUSPEND, port->name, port);
 	if (retval) {
 		dev_err(port->dev, "atmel_startup - Can't get irq\n");
 		return retval;
-- 
2.17.0

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

end of thread, other threads:[~2018-05-07 17:11 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-26 15:06 [PATCH] tty/serial: atmel: use port->name as name in request_irq() Sebastian Andrzej Siewior
2018-04-26 15:12 ` Sebastian Andrzej Siewior
2018-04-27 10:31   ` Richard Genoud
2018-05-02 19:16     ` Sebastian Andrzej Siewior
2018-05-03 12:36       ` Richard Genoud
2018-05-03 12:44         ` Sebastian Andrzej Siewior
2018-05-03 13:34           ` Richard Genoud
2018-05-03 15:12             ` Richard Genoud
2018-05-04  6:35             ` Richard Genoud
2018-05-04  8:14               ` [PATCH v2] " Sebastian Andrzej Siewior
2018-05-04 10:28                 ` Richard Genoud
2018-05-04 20:23                   ` Rob Herring
2018-05-07 17:11                     ` [PATCH v3] " Sebastian Andrzej Siewior

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