Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

serial: arc_uart: Fix out-of-bounds access through DT alias

The arc_uart_ports[] array is indexed using a value derived from the
"serialN" alias in DT, which may lead to an out-of-bounds access.

Fix this by adding a range check.

Note that the array size is defined by a Kconfig symbol
(CONFIG_SERIAL_ARC_NR_PORTS), so this can even be triggered using a
legitimate DTB.

Fixes: ea28fd56fcde69af ("serial/arc-uart: switch to devicetree based probing")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Geert Uytterhoeven and committed by
Greg Kroah-Hartman
f9f57869 42afa627

+5
+5
drivers/tty/serial/arc_uart.c
··· 593 593 if (dev_id < 0) 594 594 dev_id = 0; 595 595 596 + if (dev_id >= ARRAY_SIZE(arc_uart_ports)) { 597 + dev_err(&pdev->dev, "serial%d out of range\n", dev_id); 598 + return -EINVAL; 599 + } 600 + 596 601 uart = &arc_uart_ports[dev_id]; 597 602 port = &uart->port; 598 603