]> git.baikalelectronics.ru Git - kernel.git/commit
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)
commitddb10e5c79208df06b5f91f387227e37eacb300f
treecd5a4aa96a9a064f0b9205d93b7df3389ea3621e
parentf0dc22c3e727602af56334962cdb4ce96ed1b1bc
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