<feed xmlns='http://www.w3.org/2005/Atom'>
<title>user/sven/linux.git/include/linux/tty.h, branch v3.0.51</title>
<subtitle>Linux Kernel
</subtitle>
<id>https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v3.0.51</id>
<link rel='self' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v3.0.51'/>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/'/>
<updated>2011-11-11T17:35:12Z</updated>
<entry>
<title>TTY: make tty_add_file non-failing</title>
<updated>2011-11-11T17:35:12Z</updated>
<author>
<name>Jiri Slaby</name>
<email>jslaby@suse.cz</email>
</author>
<published>2011-10-12T09:32:43Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=0c1f111ae7fcea822fd1c078ef48e88d93afc57a'/>
<id>urn:sha1:0c1f111ae7fcea822fd1c078ef48e88d93afc57a</id>
<content type='text'>
commit fa90e1c935472281de314e6d7c9a37db9cbc2e4e upstream.

If tty_add_file fails at the point it is now, we have to revert all
the changes we did to the tty. It means either decrease all refcounts
if this was a tty reopen or delete the tty if it was newly allocated.

There was a try to fix this in v3.0-rc2 using tty_release in 0259894c7
(TTY: fix fail path in tty_open). But instead it introduced a NULL
dereference. It's because tty_release dereferences
filp-&gt;private_data, but that one is set even in our tty_add_file. And
when tty_add_file fails, it's still NULL/garbage. Hence tty_release
cannot be called there.

To circumvent the original leak (and the current NULL deref) we split
tty_add_file into two functions, making the latter non-failing. In
that case we may do the former early in open, where handling failures
is easy. The latter stays as it is now. So there is no change in
functionality.

The original bug (leak) was introduced by f573bd176 (tty: Remove
__GFP_NOFAIL from tty_add_file()). Thanks Dan for reporting this.

Later, we may split tty_release into more functions and call only some
of them in this fail path instead. (If at all possible.)

Introduced-in: v2.6.37-rc2
Signed-off-by: Jiri Slaby &lt;jslaby@suse.cz&gt;
Reported-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Cc: Alan Cox &lt;alan@lxorguk.ukuu.org.uk&gt;
Cc: Pekka Enberg &lt;penberg@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>TTY: pty, fix pty counting</title>
<updated>2011-10-03T18:39:49Z</updated>
<author>
<name>Jiri Slaby</name>
<email>jslaby@suse.cz</email>
</author>
<published>2011-08-10T12:59:28Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=a38df1a01320298198c7cb2e3e8a61fc54459d6a'/>
<id>urn:sha1:a38df1a01320298198c7cb2e3e8a61fc54459d6a</id>
<content type='text'>
commit 24d406a6bf736f7aebdc8fa0f0ec86e0890c6d24 upstream.

tty_operations-&gt;remove is normally called like:
queue_release_one_tty
 -&gt;tty_shutdown
   -&gt;tty_driver_remove_tty
     -&gt;tty_operations-&gt;remove

However tty_shutdown() is called from queue_release_one_tty() only if
tty_operations-&gt;shutdown is NULL. But for pty, it is not.
pty_unix98_shutdown() is used there as -&gt;shutdown.

So tty_operations-&gt;remove of pty (i.e. pty_unix98_remove()) is never
called. This results in invalid pty_count. I.e. what can be seen in
/proc/sys/kernel/pty/nr.

I see this was already reported at:
  https://lkml.org/lkml/2009/11/5/370
But it was not fixed since then.

This patch is kind of a hackish way. The problem lies in -&gt;install. We
allocate there another tty (so-called tty-&gt;link). So -&gt;install is
called once, but -&gt;remove twice, for both tty and tty-&gt;link. The fix
here is to count both tty and tty-&gt;link and divide the count by 2 for
user.

And to have -&gt;remove called, let's make tty_driver_remove_tty() global
and call that from pty_unix98_shutdown() (tty_operations-&gt;shutdown).

While at it, let's document that when -&gt;shutdown is defined,
tty_shutdown() is not called.

Signed-off-by: Jiri Slaby &lt;jslaby@suse.cz&gt;
Cc: Alan Cox &lt;alan@linux.intel.com&gt;
Cc: "H. Peter Anvin" &lt;hpa@zytor.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>n_tracerouter and n_tracesink ldisc additions.</title>
<updated>2011-05-13T23:31:00Z</updated>
<author>
<name>J Freyensee</name>
<email>james_p_freyensee@linux.intel.com</email>
</author>
<published>2011-05-06T23:56:50Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=ee4f6b4b89665b92ead67deaa2e5d2ffa1af2b5f'/>
<id>urn:sha1:ee4f6b4b89665b92ead67deaa2e5d2ffa1af2b5f</id>
<content type='text'>
The n_tracerouter and n_tracesink line discpline drivers use the
Linux tty line discpline framework to route trace data coming
from a tty port (say UART for example) to the trace sink line
discipline driver and to another tty port(say USB).  Those
these two line discipline drivers can be used together,
independently from pti.c, they are part of the original
implementation solution of the MIPI P1149.7, compact JTAG, PTI
solution for Intel mobile platforms starting with the
Medfield platform.

Signed-off-by: J Freyensee &lt;james_p_freyensee@linux.intel.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;
</content>
</entry>
<entry>
<title>TTY: introduce deinit helpers for proper ldisc shutdown</title>
<updated>2011-04-19T21:43:01Z</updated>
<author>
<name>Jiri Slaby</name>
<email>jslaby@suse.cz</email>
</author>
<published>2011-03-23T09:48:35Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=6716671d8c1c07a8072098764d1b7cbfef7412ad'/>
<id>urn:sha1:6716671d8c1c07a8072098764d1b7cbfef7412ad</id>
<content type='text'>
Introduce deinitialize_tty_struct which should be called after
initialize_tty_struct and before successfull tty_ldisc_setup.

It calls tty_ldisc_deinit which is opposite of tty_ldisc_init. It only
puts a reference to ldisc and assigns NULL to tty-&gt;ldisc.

It will be used to shut down ldisc when tty_release cannot be called
yet.

Signed-off-by: Jiri Slaby &lt;jslaby@suse.cz&gt;
Cc: Alan Cox &lt;alan@lxorguk.ukuu.org.uk&gt;
Cc: Julian Anastasov &lt;ja@ssi.bg&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;
</content>
</entry>
<entry>
<title>tty: stop using "delayed_work" in the tty layer</title>
<updated>2011-03-22T23:17:32Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2011-03-22T23:17:32Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=f23eb2b2b28547fc70df82dd5049eb39bec5ba12'/>
<id>urn:sha1:f23eb2b2b28547fc70df82dd5049eb39bec5ba12</id>
<content type='text'>
Using delayed-work for tty flip buffers ends up causing us to wait for
the next tick to complete some actions.  That's usually not all that
noticeable, but for certain latency-critical workloads it ends up being
totally unacceptable.

As an extreme case of this, passing a token back-and-forth over a pty
will take two ticks per iteration, so even just a thousand iterations
will take 8 seconds assuming a common 250Hz configuration.

Avoiding the whole delayed work issue brings that ping-pong test-case
down to 0.009s on my machine.

In more practical terms, this latency has been a performance problem for
things like dive computer simulators (simulating the serial interface
using the ptys) and for other environments (Alan mentions a CP/M emulator).

Reported-by: Jef Driesen &lt;jefdriesen@telenet.be&gt;
Acked-by: Greg KH &lt;gregkh@suse.de&gt;
Acked-by: Alan Cox &lt;alan@lxorguk.ukuu.org.uk&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>tty: add a helper for setting termios data from kernel side</title>
<updated>2011-02-17T20:03:52Z</updated>
<author>
<name>Alan Cox</name>
<email>alan@linux.intel.com</email>
</author>
<published>2011-02-14T16:27:53Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=8d075b199b9a66ad90296f898f1f15c0ae1511b8'/>
<id>urn:sha1:8d075b199b9a66ad90296f898f1f15c0ae1511b8</id>
<content type='text'>
This basically encapsulates the small bit of locking knowledge needed. While
we are at it make sure we blow up on any more abusers and unsafe misuses of
ioctl for this kind of stuff.

We change the function to return an argument as at some point it needs to
honour the POSIX 'I asked for changes but got none of them' error reporting
corner case.

Signed-off-by: Alan Cox &lt;alan@linux.intel.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;
</content>
</entry>
<entry>
<title>tty: fix build error in vt_ioctl.c if CONFIG_COMPAT is enabled</title>
<updated>2011-02-17T20:02:51Z</updated>
<author>
<name>Greg Kroah-Hartman</name>
<email>gregkh@suse.de</email>
</author>
<published>2011-02-17T20:02:51Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=94c2273d6c1b65eaaf2a6446c7147bdf6e5ae924'/>
<id>urn:sha1:94c2273d6c1b65eaaf2a6446c7147bdf6e5ae924</id>
<content type='text'>
This was caused by the previous patch to remove the file pointer
from the tty ioctl handler.

Cc: Alan Cox &lt;alan@linux.intel.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;
</content>
</entry>
<entry>
<title>tty: now phase out the ioctl file pointer for good</title>
<updated>2011-02-17T19:59:56Z</updated>
<author>
<name>Alan Cox</name>
<email>alan@linux.intel.com</email>
</author>
<published>2011-02-14T16:27:22Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=6caa76b7786891b42b66a0e61e2c2fff2c884620'/>
<id>urn:sha1:6caa76b7786891b42b66a0e61e2c2fff2c884620</id>
<content type='text'>
Only oddities here are a couple of drivers that bogusly called the ldisc
helpers instead of returning -ENOIOCTLCMD. Fix the bug and the rest goes
away.

Signed-off-by: Alan Cox &lt;alan@linux.intel.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;
</content>
</entry>
<entry>
<title>Merge branch 'tty-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty-2.6</title>
<updated>2010-12-02T20:58:16Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2010-12-02T20:58:16Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=eed5ee1a3ab3020168cd67fdde2500452b0628c9'/>
<id>urn:sha1:eed5ee1a3ab3020168cd67fdde2500452b0628c9</id>
<content type='text'>
* 'tty-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty-2.6:
  serial: mfd: adjust the baud rate setting
  TTY: open/hangup race fixup
  TTY: don't allow reopen when ldisc is changing
  NET: wan/x25, fix ldisc-&gt;open retval
  TTY: ldisc, fix open flag handling
  serial8250: Mark console as CON_ANYTIME
</content>
</entry>
<entry>
<title>TTY: open/hangup race fixup</title>
<updated>2010-11-29T22:52:48Z</updated>
<author>
<name>Jiri Slaby</name>
<email>jslaby@suse.cz</email>
</author>
<published>2010-11-29T09:16:54Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=acfa747baf73922021a047f2d87a2d866f5dbab5'/>
<id>urn:sha1:acfa747baf73922021a047f2d87a2d866f5dbab5</id>
<content type='text'>
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-&gt;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 &lt; 0) continue;
		if (ioctl(fd, TIOCSCTTY)) continue;
		if (vhangup()) continue;
		close(fd);
	}
	exit(0);
}

Signed-off-by: Jiri Slaby &lt;jslaby@suse.cz&gt;
Reported-by: &lt;Valdis.Kletnieks@vt.edu&gt;
Reported-by: Kyle McMartin &lt;kyle@mcmartin.ca&gt;
Cc: Alan Cox &lt;alan@lxorguk.ukuu.org.uk&gt;
Cc: stable &lt;stable@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;
</content>
</entry>
</feed>
