serial: samsung: Fix out-of-bounds access through serial port index
authorGeert Uytterhoeven <geert+renesas@glider.be>
Fri, 23 Feb 2018 13:38:34 +0000 (14:38 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 28 Feb 2018 14:30:00 +0000 (15:30 +0100)
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>
drivers/tty/serial/samsung.c

index f9fecc5ed0cee82656e978f77938d5af7ff1f70a..3f2f8c118ce09d5686953b23c6a0a4e3de832793 100644 (file)
@@ -1818,6 +1818,10 @@ static int s3c24xx_serial_probe(struct platform_device *pdev)
 
        dbg("s3c24xx_serial_probe(%p) %d\n", pdev, index);
 
+       if (index >= ARRAY_SIZE(s3c24xx_serial_ports)) {
+               dev_err(&pdev->dev, "serial%d out of range\n", index);
+               return -EINVAL;
+       }
        ourport = &s3c24xx_serial_ports[index];
 
        ourport->drv_data = s3c24xx_get_driver_data(pdev);