]> git.baikalelectronics.ru Git - kernel.git/commit
TTY: n_tty, do not dereference user buffer
authorJiri Slaby <jslaby@suse.cz>
Thu, 26 Apr 2012 18:13:00 +0000 (20:13 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 30 Apr 2012 02:13:54 +0000 (22:13 -0400)
commit7865fbd6bd9bf795be273ce88be7df86f96a9fdc
treee583b1cafbf3b1ad5a5bab1ad481a2925b7e3742
parenta1d572ea24fb6ef58164dbab5a281663094e187a
TTY: n_tty, do not dereference user buffer

copy_from_read_buf currently copies data to a user buffer and then
checks if the data is single EOF. But it checks it by accessing the
user buffer. First, the buffer may be changed by other threads of the
user program already. Second, it accesses the buffer without any
checks. It might be write-only for example.

Fix this by inspecting contents of the tty (kernel) buffer instead.
Note that "n == 1" is necessary, but not sufficient. But we check
later that there is nothing left by "!tty->read_cnt" condition.

There is still an issue with the current code that EOF being wrapped
to the start of the circular buffer will result in an inappropriate
losing of the EOF character. But this is not intended to be fixed by
this patch.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Reported-by: Emil Goode <emilgoode@gmail.com>
Cc: Howard Chu <hyc@symas.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/n_tty.c