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

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

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

Fix this by adding a range check.

Fixes: 699c20f3e6310aa2 ("serial: pxa: add OF support")
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
afc7851f dd345a31

+4
+4
drivers/tty/serial/pxa.c
··· 885 885 sport->port.line = dev->id; 886 886 else if (ret < 0) 887 887 goto err_clk; 888 + if (sport->port.line >= ARRAY_SIZE(serial_pxa_ports)) { 889 + dev_err(&dev->dev, "serial%d out of range\n", sport->port.line); 890 + return -EINVAL; 891 + } 888 892 snprintf(sport->name, PXA_NAME_LEN - 1, "UART%d", sport->port.line + 1); 889 893 890 894 sport->port.membase = ioremap(mmres->start, resource_size(mmres));