tty: close race between device register and open
authorJohan Hovold <johan@kernel.org>
Thu, 30 Mar 2017 13:39:34 +0000 (15:39 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 31 Mar 2017 09:37:13 +0000 (11:37 +0200)
commit6a7e6f78c235975cc14d4e141fa088afffe7062c
treecd5a4aa96a9a064f0b9205d93b7df3389ea3621e
parent53c1cf42817899f88114c28c6bbe4fe0f3c8afb6
tty: close race between device register and open

The tty class device is currently not registered until after the
character device has been registered thereby leaving a small window
were a racing open could end up with a NULL tty->dev pointer due to the
class-device lookup failing in alloc_tty_struct.

Close this race by registering the class device before the character
device while making sure to defer the user-space uevent notification
until after the character device has been registered.

Note that some tty drivers expect a valid tty->dev and would misbehave
or crash otherwise. Some line disciplines also currently dereference the
class device unconditionally despite the fact that not every tty is
guaranteed to have one (Unix98 pty), but this is being fixed separately.

Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/tty_io.c