lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 21 Mar 2022 17:30:54 +0100
From:   Pali Rohár <pali@...nel.org>
To:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Jiri Slaby <jirislaby@...nel.org>,
        Johan Hovold <johan@...nel.org>,
        Marek Behún <kabel@...nel.org>
Cc:     linux-serial@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH 2/3] serial: core: Fix function uart_update_timeout() to handle UPF_SPD_CUST flag

Function uart_update_timeout() currently handles UPF_SPD_HI, UPF_SPD_VHI,
UPF_SPD_SHI and UPF_SPD_WARP flags thanks to how uart_get_baud_rate()
works and how should be used. uart_get_baud_rate() already translates these
4 special flags to real baud rate value and therefore uart_update_timeout()
is called with the correct baud rate argument.

What is not handled in this function is the last remaining flag
UPF_SPD_CUST. It is because uart_get_baud_rate() returns hardcoded value
38400 when UPF_SPD_CUST is set and in use.

Implement support for UPF_SPD_CUST in uart_update_timeout(), so
port->timeout is calculated also when UPF_SPD_CUST flag is set.

For calculation use base uart clock and custom divisor. This calculation
does not have to be precise for all UART hardware but this the best
approximation which can be done. It is for sure better than hardcoded baud
rate value 38400.

Signed-off-by: Pali Rohár <pali@...nel.org>
---
 drivers/tty/serial/serial_core.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index d8fc2616d62b..34e085a038fe 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -343,6 +343,16 @@ uart_update_timeout(struct uart_port *port, unsigned int cflag,
 {
 	unsigned int size;
 
+	/*
+	 * Old custom speed handling. See function uart_get_divisor()
+	 * and description in uart_get_baud_rate() function.
+	 * This calculation does not have to be precise for all UART
+	 * hardware but it is the best approximation which we can do here
+	 * as we do not know the exact baud rate.
+	 */
+	if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST)
+		baud = DIV_ROUND_CLOSEST(port->uartclk, 16 * port->custom_divisor);
+
 	size = tty_get_frame_size(cflag) * port->fifosize;
 
 	/*
-- 
2.20.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ