diff options
author | Johan Hovold <johan@kernel.org> | 2017-11-03 10:30:52 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-11-28 10:00:50 -0500 |
commit | eb281683621b71ab9710d9dccbbef0c2e1769c97 (patch) | |
tree | e0c2fe0401613f425edf067490108a0519915a9f | |
parent | 0ff3ab701963a845d52337ded7eebf2d1a14fe00 (diff) |
serdev: ttyport: add missing receive_buf sanity checks
The receive_buf tty-port callback should return the number of bytes
accepted and must specifically never return a negative errno (or a value
larger than the buffer size) to the tty layer.
A serdev driver not providing a receive_buf callback would currently
cause the flush_to_ldisc() worker to spin in a tight loop when the tty
buffer pointers are incremented with -EINVAL (-22) after data has been
received.
A serdev driver occasionally returning a negative errno (or a too large
byte count) could cause information leaks or crashes when accessing
memory outside the tty buffers in consecutive callbacks.
Fixes: cd6484e1830b ("serdev: Introduce new bus for serial attached devices")
Cc: stable <stable@vger.kernel.org> # 4.11
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/tty/serdev/serdev-ttyport.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c index ce7ad0acee7a..09fbdd52a561 100644 --- a/drivers/tty/serdev/serdev-ttyport.c +++ b/drivers/tty/serdev/serdev-ttyport.c | |||
@@ -27,11 +27,22 @@ static int ttyport_receive_buf(struct tty_port *port, const unsigned char *cp, | |||
27 | { | 27 | { |
28 | struct serdev_controller *ctrl = port->client_data; | 28 | struct serdev_controller *ctrl = port->client_data; |
29 | struct serport *serport = serdev_controller_get_drvdata(ctrl); | 29 | struct serport *serport = serdev_controller_get_drvdata(ctrl); |
30 | int ret; | ||
30 | 31 | ||
31 | if (!test_bit(SERPORT_ACTIVE, &serport->flags)) | 32 | if (!test_bit(SERPORT_ACTIVE, &serport->flags)) |
32 | return 0; | 33 | return 0; |
33 | 34 | ||
34 | return serdev_controller_receive_buf(ctrl, cp, count); | 35 | ret = serdev_controller_receive_buf(ctrl, cp, count); |
36 | |||
37 | dev_WARN_ONCE(&ctrl->dev, ret < 0 || ret > count, | ||
38 | "receive_buf returns %d (count = %zu)\n", | ||
39 | ret, count); | ||
40 | if (ret < 0) | ||
41 | return 0; | ||
42 | else if (ret > count) | ||
43 | return count; | ||
44 | |||
45 | return ret; | ||
35 | } | 46 | } |
36 | 47 | ||
37 | static void ttyport_write_wakeup(struct tty_port *port) | 48 | static void ttyport_write_wakeup(struct tty_port *port) |