Skip to content

Commit f0b9d97

Browse files
Andi Shytigregkh
authored andcommitted
serial: ma35d1: Validate console index before assignment
The console is immediately assigned to the ma35d1 port without checking its index. This oversight can lead to out-of-bounds errors when the index falls outside the valid '0' to MA35_UART_NR range. Such scenario trigges ran error like the following: UBSAN: array-index-out-of-bounds in drivers/tty/serial/ma35d1_serial.c:555:51 index -1 is out of range for type 'uart_ma35d1_port [17] Check the index before using it and bail out with a warning. Fixes: 930cbf9 ("tty: serial: Add Nuvoton ma35d1 serial driver support") Signed-off-by: Andi Shyti <[email protected]> Cc: Jacky Huang <[email protected]> Cc: <[email protected]> # v6.5+ Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 58ac1b3 commit f0b9d97

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

drivers/tty/serial/ma35d1_serial.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,11 +552,19 @@ static void ma35d1serial_console_putchar(struct uart_port *port, unsigned char c
552552
*/
553553
static void ma35d1serial_console_write(struct console *co, const char *s, u32 count)
554554
{
555-
struct uart_ma35d1_port *up = &ma35d1serial_ports[co->index];
555+
struct uart_ma35d1_port *up;
556556
unsigned long flags;
557557
int locked = 1;
558558
u32 ier;
559559

560+
if ((co->index < 0) || (co->index >= MA35_UART_NR)) {
561+
pr_warn("Failed to write on ononsole port %x, out of range\n",
562+
co->index);
563+
return;
564+
}
565+
566+
up = &ma35d1serial_ports[co->index];
567+
560568
if (up->port.sysrq)
561569
locked = 0;
562570
else if (oops_in_progress)

0 commit comments

Comments
 (0)