Skip to content

Commit a4a3e06

Browse files
dvyukovgregkh
authored andcommitted
tty: fix data race in tty_ldisc_ref_wait()
tty_ldisc_ref_wait() checks tty->ldisc under tty->ldisc_sem. But if ldisc==NULL it releases them sem and reloads tty->ldisc without holding the sem. This is wrong and can lead to returning non-NULL ldisc without protection. Don't reload tty->ldisc second time. Signed-off-by: Dmitry Vyukov <[email protected]> Cc: [email protected] Cc: [email protected] Cc: Greg Kroah-Hartman <[email protected]> Cc: Jiri Slaby <[email protected]> Cc: Peter Hurley <[email protected]> Cc: One Thousand Gnomes <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5362544 commit a4a3e06

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/tty/tty_ldisc.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,13 @@ const struct file_operations tty_ldiscs_proc_fops = {
271271

272272
struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty)
273273
{
274+
struct tty_ldisc *ld;
275+
274276
ldsem_down_read(&tty->ldisc_sem, MAX_SCHEDULE_TIMEOUT);
275-
if (!tty->ldisc)
277+
ld = tty->ldisc;
278+
if (!ld)
276279
ldsem_up_read(&tty->ldisc_sem);
277-
return tty->ldisc;
280+
return ld;
278281
}
279282
EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait);
280283

0 commit comments

Comments
 (0)