Files
linux/drivers/char
Jiri Slaby 99c0f4e21e TTY: open/hangup race fixup
commit acfa747baf upstream.

Like in the "TTY: don't allow reopen when ldisc is changing" patch,
this one fixes a TTY WARNING as described in the option 1) there:
1) __tty_hangup from tty_ldisc_hangup to tty_ldisc_enable. During this
section tty_lock is held. However tty_lock is temporarily dropped in
the middle of the function by tty_ldisc_hangup.

The fix is to introduce a new flag which we set during the unlocked
window and check it in tty_reopen too. The flag is TTY_HUPPING and is
cleared after TTY_HUPPED is set.

While at it, remove duplicate TTY_HUPPED set_bit. The one after
calling ops->hangup seems to be more correct. But anyway, we hold
tty_lock, so there should be no difference.

Also document the function it does that kind of crap.

Nicely reproducible with two forked children:
static void do_work(const char *tty)
{
	if (signal(SIGHUP, SIG_IGN) == SIG_ERR) exit(1);
	setsid();
	while (1) {
		int fd = open(tty, O_RDWR|O_NOCTTY);
		if (fd < 0) continue;
		if (ioctl(fd, TIOCSCTTY)) continue;
		if (vhangup()) continue;
		close(fd);
	}
	exit(0);
}

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Reported-by: <Valdis.Kletnieks@vt.edu>
Reported-by: Kyle McMartin <kyle@mcmartin.ca>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-12-09 13:32:42 -08:00
..
2010-12-09 13:32:31 -08:00
2009-09-24 07:21:03 -07:00
2010-08-16 23:44:49 -06:00
2005-04-16 15:20:36 -07:00
2005-04-16 15:20:36 -07:00
2008-12-13 11:25:49 -08:00
2005-04-16 15:20:36 -07:00
2005-04-16 15:20:36 -07:00
2008-10-20 08:52:41 -07:00
2010-08-10 13:47:40 -07:00
2008-07-20 17:12:36 -07:00
2005-04-16 15:20:36 -07:00
2010-12-09 13:32:29 -08:00
2010-05-17 03:06:12 +02:00
2010-08-10 13:47:40 -07:00
2010-08-12 08:43:29 -07:00
2009-12-10 22:55:36 +01:00
2008-02-07 08:42:25 -08:00
2008-04-30 08:29:43 -07:00
2010-08-10 13:47:45 -07:00
2010-08-10 13:47:43 -07:00
2010-08-10 13:47:39 -07:00
2010-08-11 08:59:23 -07:00
2007-02-12 09:48:30 -08:00
2010-05-27 09:12:50 -07:00
2010-08-18 08:35:47 -04:00
2010-05-27 09:12:50 -07:00
2005-04-16 15:20:36 -07:00
2010-08-10 13:47:40 -07:00
2008-07-20 17:12:38 -07:00
2010-08-23 18:17:21 -07:00
2009-02-22 09:23:02 -08:00
2010-08-10 13:47:44 -07:00
2005-04-16 15:20:36 -07:00
2005-04-16 15:20:36 -07:00
2005-04-16 15:20:36 -07:00
2008-07-20 17:12:38 -07:00
2010-08-10 13:47:40 -07:00
2010-08-10 13:47:43 -07:00
2005-04-16 15:20:36 -07:00
2005-04-16 15:20:36 -07:00
2009-10-14 17:36:53 +02:00
2010-01-04 12:31:21 -08:00
2010-12-09 13:32:42 -08:00
2010-12-09 13:32:41 -08:00