public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tty: fix data race in n_tty_receive_buf_common
@ 2018-01-03 13:48 Gaurav Kohli
  2018-01-03 19:38 ` Alan Cox
  0 siblings, 1 reply; 18+ messages in thread
From: Gaurav Kohli @ 2018-01-03 13:48 UTC (permalink / raw)
  To: jslaby, gregkh, mikey; +Cc: linux-kernel, Gaurav Kohli

There can be a race, if receive_buf call comes before
tty initialization completes in n_tty_open and tty->disc_data
may be NULL.

CPU0                                        cpu1
----                                        ----
 000|n_tty_receive_buf_common()     n_tty_open()
-001|n_tty_receive_buf2()           tty_ldisc_open.isra.3()
-002|tty_ldisc_receive_buf(inline)  tty_ldisc_setup()

If tty->disc_data is NULL, then return from flush_to_ldisc

Signed-off-by: Gaurav Kohli <gkohli@codeaurora.org>

diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index 25d7368..5d49183 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -35,6 +35,9 @@ static int tty_port_default_receive_buf(struct tty_port *port,
 	if (!disc)
 		return 0;
 
+	if (!tty->disc_data)
+		return 0;
+
 	ret = tty_ldisc_receive_buf(disc, p, (char *)f, count);
 
 	tty_ldisc_deref(disc);
-- 
1.9.1

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

end of thread, other threads:[~2018-01-20 18:49 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-03 13:48 [PATCH] tty: fix data race in n_tty_receive_buf_common Gaurav Kohli
2018-01-03 19:38 ` Alan Cox
2018-01-04  5:47   ` Kohli, Gaurav
2018-01-04 11:09     ` Alan Cox
2018-01-04 13:46       ` Kohli, Gaurav
2018-01-04 14:37         ` Alan Cox
2018-01-05  7:34           ` Kohli, Gaurav
2018-01-05  7:45             ` Kohli, Gaurav
2018-01-05 13:36               ` Alan Cox
2018-01-05 13:56                 ` Kohli, Gaurav
2018-01-05 14:15                   ` Alan Cox
2018-01-05 20:14                     ` Kohli, Gaurav
2018-01-05 20:24                       ` Kohli, Gaurav
2018-01-05 21:05                         ` Alan Cox
2018-01-06  7:50                           ` Kohli, Gaurav
2018-01-17 13:25                             ` Kohli, Gaurav
2018-01-20 18:49                               ` Alan Cox
2018-01-05 20:28                       ` Kohli, Gaurav

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