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

serial: samsung: Fix out-of-bounds access through serial port index

The s3c24xx_serial_ports[] array is indexed using a value derived from
the "serialN" alias in DT, or from an incrementing probe index, 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_SAMSUNG_UARTS), so this can even be triggered using
a legitimate DTB or legitimate board code.

Fixes: 13a9f6c64fdc55eb ("serial: samsung: Consider DT alias when probing ports")
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
49ee23b7 afc7851f

+4
+4
drivers/tty/serial/samsung.c
··· 1818 1818 1819 1819 dbg("s3c24xx_serial_probe(%p) %d\n", pdev, index); 1820 1820 1821 + if (index >= ARRAY_SIZE(s3c24xx_serial_ports)) { 1822 + dev_err(&pdev->dev, "serial%d out of range\n", index); 1823 + return -EINVAL; 1824 + } 1821 1825 ourport = &s3c24xx_serial_ports[index]; 1822 1826 1823 1827 ourport->drv_data = s3c24xx_get_driver_data(pdev);