linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] TTY: serial_core: Fix crash if agetty() run on non-console serial port
@ 2011-10-07 21:59 Doug Anderson
  2011-10-08  8:49 ` Jiri Slaby
  2011-10-12  0:25 ` [PATCH v2] TTY: serial_core: Fix crash if DCD drop during suspend Doug Anderson
  0 siblings, 2 replies; 8+ messages in thread
From: Doug Anderson @ 2011-10-07 21:59 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Alan Cox; +Cc: linux-serial, linux-kernel, Doug Anderson

The symptoms of the bug showed up if you were running agetty on ttyS0
but not using ttyS0 as the console= port on the kernel command
line.  In this case, if you suspended the system you'd get a crash
on resume.

The specific order of operations that were running:
* uart_suspend_port() would be called to put the uart in suspend mode
* a tty hangup would be processed
* the hangup would call uart_shutdown()
* ... suspend / resume happens ...
* uart_resume_port() would be called and run the code in the
  (port->flags & ASYNC_SUSPENDED) block, which would startup the port
  (and enable tx again).
* Since the UART would be available for tx, we'd immediately get
  an interrupt, eventually calling transmit_chars()
* The transmit_chars() function would crash.  The first crash would
  be a dereference of a NULL tty member, but since the port has been
  shutdown that was just a symptom.

Signed-off-by: Doug Anderson <dianders@chromium.org>
---
 drivers/tty/serial/serial_core.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index a3efbea..668e56a 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -255,6 +255,14 @@ static void uart_shutdown(struct tty_struct *tty, struct uart_state *state)
 	}
 
 	/*
+	 * It's possible for shutdown to be called after suspend.  Specifically
+	 * if agetty() is listening to the serial port we get a HUP after the
+	 * suspend happend (and HUP calls shutdown).  Clear suspended bit so
+	 * we don't try to resume a port that has been shutdown.
+	 */
+	clear_bit(ASYNCB_SUSPENDED, &port->flags);
+
+	/*
 	 * kill off our tasklet
 	 */
 	tasklet_kill(&state->tlet);
-- 
1.7.3.1


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

end of thread, other threads:[~2011-10-19 19:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-07 21:59 [PATCH] TTY: serial_core: Fix crash if agetty() run on non-console serial port Doug Anderson
2011-10-08  8:49 ` Jiri Slaby
2011-10-08 15:55   ` Doug Anderson
2011-10-10 20:28     ` Doug Anderson
2011-10-12  0:25 ` [PATCH v2] TTY: serial_core: Fix crash if DCD drop during suspend Doug Anderson
2011-10-12 11:57   ` Alan Cox
2011-10-18 21:21   ` Greg KH
2011-10-19 18:52     ` [PATCH v3] " Doug Anderson

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).