Message ID | 20231209125836.16294-5-l.sanfilippo@kunbus.com |
---|---|
State | New |
Headers | show |
Series | Fixes and improvements for RS485 | expand |
On 11.12.23 11:53, Ilpo Järvinen wrote: > On Sat, 9 Dec 2023, Lino Sanfilippo wrote: > >> Some uart drivers specify a rs485_config() function and then decide later >> to disable RS485 support for some reason (e.g. imx and ar933). >> >> In these cases userspace may be able to activate RS485 via TIOCSRS485 >> nevertheless, since in uart_set_rs485_config() an existing rs485_config() >> function indicates that RS485 is supported. >> >> Make sure that this is not longer possible by checking the uarts >> rs485_supported.flags instead and bailing out if SER_RS485_ENABLED is not >> set. >> >> Furthermore instead of returning an empty structure return -ENOTTY if the >> RS485 configuration is requested via TIOCGRS485 but RS485 is not supported. >> This has a small impact on userspace visibility but it is consistent with >> the -ENOTTY error for TIOCGRS485. >> >> Fixes: e849145e1fdd ("serial: ar933x: Fill in rs485_supported") >> Fixes: 55e18c6b6d42 ("serial: imx: Remove serial_rs485 sanitization") >> Cc: Shawn Guo <shawnguo@kernel.org> >> Cc: Sascha Hauer <s.hauer@pengutronix.de> >> Cc: stable@vger.kernel.org >> Signed-off-by: Lino Sanfilippo <l.sanfilippo@kunbus.com> >> --- >> drivers/tty/serial/serial_core.c | 5 ++++- >> 1 file changed, 4 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c >> index 4eae1406cb6c..661074ab8edb 100644 >> --- a/drivers/tty/serial/serial_core.c >> +++ b/drivers/tty/serial/serial_core.c >> @@ -1448,6 +1448,9 @@ static int uart_get_rs485_config(struct uart_port *port, >> unsigned long flags; >> struct serial_rs485 aux; >> >> + if (!(port->rs485_supported.flags & SER_RS485_ENABLED)) >> + return -ENOTTY; >> + >> uart_port_lock_irqsave(port, &flags); >> aux = port->rs485; >> uart_port_unlock_irqrestore(port, flags); >> @@ -1465,7 +1468,7 @@ static int uart_set_rs485_config(struct tty_struct *tty, struct uart_port *port, >> int ret; >> unsigned long flags; >> >> - if (!port->rs485_config) >> + if (!(port->rs485_supported.flags & SER_RS485_ENABLED)) >> return -ENOTTY; >> >> if (copy_from_user(&rs485, rs485_user, sizeof(*rs485_user))) > > Looking through debian code search entries for TIOCGRS485, this might > actually fly... I'd suggest splitting this into two patches though. Ok. I will split this into two patches or maybe even leave the change for uart_get_rs485_config() completely out of this series (which is only about bug fixes) for now. Thanks!
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 4eae1406cb6c..661074ab8edb 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1448,6 +1448,9 @@ static int uart_get_rs485_config(struct uart_port *port, unsigned long flags; struct serial_rs485 aux; + if (!(port->rs485_supported.flags & SER_RS485_ENABLED)) + return -ENOTTY; + uart_port_lock_irqsave(port, &flags); aux = port->rs485; uart_port_unlock_irqrestore(port, flags); @@ -1465,7 +1468,7 @@ static int uart_set_rs485_config(struct tty_struct *tty, struct uart_port *port, int ret; unsigned long flags; - if (!port->rs485_config) + if (!(port->rs485_supported.flags & SER_RS485_ENABLED)) return -ENOTTY; if (copy_from_user(&rs485, rs485_user, sizeof(*rs485_user)))
Some uart drivers specify a rs485_config() function and then decide later to disable RS485 support for some reason (e.g. imx and ar933). In these cases userspace may be able to activate RS485 via TIOCSRS485 nevertheless, since in uart_set_rs485_config() an existing rs485_config() function indicates that RS485 is supported. Make sure that this is not longer possible by checking the uarts rs485_supported.flags instead and bailing out if SER_RS485_ENABLED is not set. Furthermore instead of returning an empty structure return -ENOTTY if the RS485 configuration is requested via TIOCGRS485 but RS485 is not supported. This has a small impact on userspace visibility but it is consistent with the -ENOTTY error for TIOCGRS485. Fixes: e849145e1fdd ("serial: ar933x: Fill in rs485_supported") Fixes: 55e18c6b6d42 ("serial: imx: Remove serial_rs485 sanitization") Cc: Shawn Guo <shawnguo@kernel.org> Cc: Sascha Hauer <s.hauer@pengutronix.de> Cc: stable@vger.kernel.org Signed-off-by: Lino Sanfilippo <l.sanfilippo@kunbus.com> --- drivers/tty/serial/serial_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)