Linux Serial subsystem development
 help / color / mirror / Atom feed
* A data race between tty_port_open() and uart_do_autoconfig()
@ 2021-04-14  0:17 Gong, Sishuai
  2021-04-14  6:20 ` Greg KH
  0 siblings, 1 reply; 5+ messages in thread
From: Gong, Sishuai @ 2021-04-14  0:17 UTC (permalink / raw)
  To: jirislaby@kernel.org, a.darwish@linutronix.de, aik@ozlabs.ru,
	johan@kernel.org
  Cc: linux-serial@vger.kernel.org

Hi,

We found a data race between two tty functions tty_port_open() and uart_do_autoconfig() in linux-5.12-rc3 and we are able to reproduce it under x86. In general, when tty_port_open() and uart_do_autoconfig() are running in parallel, uart_do_autoconfig() may fetch an out-of-date value of port->count and enter into a different execution path, as shown below.

Currently, we haven’t found any explicit errors due to this data race but we noticed the developer has used lock to read port->count, so we want to point out this data race in case this is unexpected.

------------------------------------------
Execution interleaving

Thread 1					Thread 2
tty_port_open()			uart_do_autoconfig()

spin_lock_irq(&port->lock);
						if (mutex_lock_interruptible(&port->mutex))
						…
						if (tty_port_users(port) == 1) {
							uart_shutdown(tty, state);

++port->count;
spin_unlock_irq(&port->lock);




Thanks,
Sishuai


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

end of thread, other threads:[~2021-04-14 16:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-14  0:17 A data race between tty_port_open() and uart_do_autoconfig() Gong, Sishuai
2021-04-14  6:20 ` Greg KH
2021-04-14 14:35   ` Gong, Sishuai
2021-04-14 15:08     ` Greg KH
2021-04-14 16:31       ` Gong, Sishuai

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