mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-18 17:54:13 +08:00
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: cd6484e183
("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>
This commit is contained in:
parent
0ff3ab7019
commit
eb28168362
@ -27,11 +27,22 @@ static int ttyport_receive_buf(struct tty_port *port, const unsigned char *cp,
|
||||
{
|
||||
struct serdev_controller *ctrl = port->client_data;
|
||||
struct serport *serport = serdev_controller_get_drvdata(ctrl);
|
||||
int ret;
|
||||
|
||||
if (!test_bit(SERPORT_ACTIVE, &serport->flags))
|
||||
return 0;
|
||||
|
||||
return serdev_controller_receive_buf(ctrl, cp, count);
|
||||
ret = serdev_controller_receive_buf(ctrl, cp, count);
|
||||
|
||||
dev_WARN_ONCE(&ctrl->dev, ret < 0 || ret > count,
|
||||
"receive_buf returns %d (count = %zu)\n",
|
||||
ret, count);
|
||||
if (ret < 0)
|
||||
return 0;
|
||||
else if (ret > count)
|
||||
return count;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void ttyport_write_wakeup(struct tty_port *port)
|
||||
|
Loading…
Reference in New Issue
Block a user