From: Peter Hurley Date: Tue, 12 Jan 2016 23:14:46 +0000 (-0800) Subject: serial: omap: Prevent DoS using unprivileged ioctl(TIOCSRS485) X-Git-Tag: v4.1.12-92~150^2~217 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=076832a6f51a552c28a2fed5852452365b10845b;p=users%2Fjedix%2Flinux-maple.git serial: omap: Prevent DoS using unprivileged ioctl(TIOCSRS485) Orabug: 23330842 [ Upstream commit 308bbc9ab838d0ace0298268c7970ba9513e2c65 ] The omap-serial driver emulates RS485 delays using software timers, but neglects to clamp the input values from the unprivileged ioctl(TIOCSRS485). Because the software implementation busy-waits, malicious userspace could stall the cpu for ~49 days. Clamp the input values to < 100ms. Fixes: 4a0ac0f55b18 ("OMAP: add RS485 support") Cc: # 3.12+ Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin (cherry picked from commit 56819934d6148c68c85eb181f6153b36f028f99c) Signed-off-by: Dan Duval --- diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c index 7f49172ccd867..0a88693cd8ca0 100644 --- a/drivers/tty/serial/omap-serial.c +++ b/drivers/tty/serial/omap-serial.c @@ -1368,7 +1368,7 @@ static inline void serial_omap_add_console_port(struct uart_omap_port *up) /* Enable or disable the rs485 support */ static int -serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) +serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485) { struct uart_omap_port *up = to_uart_omap_port(port); unsigned int mode; @@ -1381,8 +1381,12 @@ serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) up->ier = 0; serial_out(up, UART_IER, 0); + /* Clamp the delays to [0, 100ms] */ + rs485->delay_rts_before_send = min(rs485->delay_rts_before_send, 100U); + rs485->delay_rts_after_send = min(rs485->delay_rts_after_send, 100U); + /* store new config */ - port->rs485 = *rs485conf; + port->rs485 = *rs485; /* * Just as a precaution, only allow rs485