]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
serial: fsl_lpuart: Fix out-of-bounds access through DT alias
authorGeert Uytterhoeven <geert+renesas@glider.be>
Fri, 23 Feb 2018 13:38:30 +0000 (14:38 +0100)
committerStefan Bader <stefan.bader@canonical.com>
Tue, 14 Aug 2018 10:29:48 +0000 (12:29 +0200)
BugLink: http://bugs.launchpad.net/bugs/1783418
[ Upstream commit ffab87fdecc655cc676f8be8dd1a2c5e22bd6d47 ]

The lpuart_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.

Fixes: c9e2e946fb0ba5d2 ("tty: serial: add Freescale lpuart driver support")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/tty/serial/fsl_lpuart.c

index 1c4d3f38713863f2ebc2e5e7f13ff5f38ac0715d..6a3df7ff8f4ff46b177c4124d2c17c5dd5bf63c7 100644 (file)
@@ -2145,6 +2145,10 @@ static int lpuart_probe(struct platform_device *pdev)
                dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret);
                return ret;
        }
+       if (ret >= ARRAY_SIZE(lpuart_ports)) {
+               dev_err(&pdev->dev, "serial%d out of range\n", ret);
+               return -EINVAL;
+       }
        sport->port.line = ret;
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        sport->port.membase = devm_ioremap_resource(&pdev->dev, res);