Commit a4a3e061 authored by Dmitry Vyukov's avatar Dmitry Vyukov Committed by Greg Kroah-Hartman
Browse files

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: default avatarDmitry Vyukov <>
Cc: Greg Kroah-Hartman <>
Cc: Jiri Slaby <>
Cc: Peter Hurley <>
Cc: One Thousand Gnomes <>
Signed-off-by: default avatarGreg Kroah-Hartman <>
parent 5362544b
......@@ -271,10 +271,13 @@ const struct file_operations tty_ldiscs_proc_fops = {
struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty)
struct tty_ldisc *ld;
ldsem_down_read(&tty->ldisc_sem, MAX_SCHEDULE_TIMEOUT);
if (!tty->ldisc)
ld = tty->ldisc;
if (!ld)
return tty->ldisc;
return ld;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment