Skip to content

Commit

Permalink
n_tty: Fix 4096-byte canonical reads
Browse files Browse the repository at this point in the history
Although the maximum allowable canonical line is specified to
be 255 bytes (MAX_CANON), the practical limit has actually been
the size of the line discipline read buffer (N_TTY_BUF_SIZE == 4096).

Commit 32f1352,
n_tty: Line copy to user buffer in canonical mode, limited the
line copy to 4095 bytes. With a completely full line discipline
read buffer and a userspace buffer > 4095, _no_ data was copied,
and the read() syscall returned 0, indicating EOF.

Fix the interval arithmetic to compute the correct number of bytes
to copy to userspace in the range [1..4096].

Cc: <stable@vger.kernel.org> # 3.12.x
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Peter Hurley authored and Greg Kroah-Hartman committed Nov 25, 2013
1 parent 6f22253 commit c77569d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/tty/n_tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,10 @@ static int canon_copy_from_read_buf(struct tty_struct *tty,
found = 1;

size = N_TTY_BUF_SIZE - tail;
n = (found + eol + size) & (N_TTY_BUF_SIZE - 1);
n = eol - tail;
if (n > 4096)
n += 4096;
n += found;
c = n;

if (found && read_buf(ldata, eol) == __DISABLED_CHAR) {
Expand Down

0 comments on commit c77569d

Please sign in to comment.