tty: n_gsm: fix race condition in gsmld_write()
authorDaniel Starke <daniel.starke@siemens.com>
Fri, 1 Jul 2022 06:16:52 +0000 (08:16 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Aug 2022 12:24:05 +0000 (14:24 +0200)
commitc9754e10f1a57c1be24f6fb0cade58253e05a109
treee58debfaa634bb3607ce0f2155e2bb394a1a45d8
parenta7fa41552407f95cb520bc90b3cfe590344d323b
tty: n_gsm: fix race condition in gsmld_write()

[ Upstream commit 32dd59f96924f45e33bc79854f7a00679c0fa28e ]

The function may be used by the user directly and also by the n_gsm
internal functions. They can lead into a race condition which results in
interleaved frames if both are writing at the same time. The receiving side
is not able to decode those interleaved frames correctly.

Add a lock around the low side tty write to avoid race conditions and frame
interleaving between user originated writes and n_gsm writes.

Fixes: e1eaea46bb40 ("tty: n_gsm line discipline")
Signed-off-by: Daniel Starke <daniel.starke@siemens.com>
Link: https://lore.kernel.org/r/20220701061652.39604-9-daniel.starke@siemens.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/tty/n_gsm.c