* [PATCH v2 0/9] serial: Fix out-of-bounds accesses through DT aliases
@ 2018-02-23 13:38 Geert Uytterhoeven
2018-02-23 13:38 ` [PATCH v2 1/9] serial: arc_uart: Fix out-of-bounds access through DT alias Geert Uytterhoeven
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: Geert Uytterhoeven @ 2018-02-23 13:38 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: devicetree, Barry Song, Geert Uytterhoeven, Vineet Gupta,
Michal Simek, linux-kernel, linux-renesas-soc, linux-serial,
Jiri Slaby, linux-snps-arc, linux-arm-kernel
Hi all,
Serial drivers used on DT platforms use the "serialN" alias in DT to
obtain the serial port index for a specific port. Drivers typically use
a fixed-size array for keeping track of all available serial ports.
However, several drivers do not perform any validation on the index
obtained from DT, which may lead to out-of-bounds accesses of these
fixed-size arrays.
While the DTB passed to the kernel might be considered trusted, some of
these out-of-bounds accesses can be triggered by a legitimate DTB:
- In some drivers the size of the array is defined by a Kconfig
symbol, so a user who doesn't need all serial ports may lower this
value rightfully,
- Tomorrow's new SoC may have more serial ports than the fixed-size
array in today's driver can accommodate, which the user may forget
to enlarge.
Hence this series fixes that by adding checks for out-of-range aliases,
logging an error message when triggered.
Changes compared to v1:
- Fix Fixes references,
- Use ARRAY_SIZE(),
- Fix off-by-one error in patch [5/9],
- Document where the non-DT case is also fixed by a patch.
Tested on r8a7791/koelsch (sh-sci), all other drivers were
compile-tested only.
Thanks for your comments!
Geert Uytterhoeven (9):
serial: arc_uart: Fix out-of-bounds access through DT alias
serial: fsl_lpuart: Fix out-of-bounds access through DT alias
serial: imx: Fix out-of-bounds access through serial port index
serial: mxs-auart: Fix out-of-bounds access through serial port index
serial: pxa: Fix out-of-bounds access through serial port index
serial: samsung: Fix out-of-bounds access through serial port index
serial: sh-sci: Fix out-of-bounds access through DT alias
serial: sirf: Fix out-of-bounds access through DT alias
serial: xuartps: Fix out-of-bounds access through DT alias
drivers/tty/serial/arc_uart.c | 5 +++++
drivers/tty/serial/fsl_lpuart.c | 4 ++++
drivers/tty/serial/imx.c | 6 ++++++
drivers/tty/serial/mxs-auart.c | 4 ++++
drivers/tty/serial/pxa.c | 4 ++++
drivers/tty/serial/samsung.c | 4 ++++
drivers/tty/serial/sh-sci.c | 4 ++++
drivers/tty/serial/sirfsoc_uart.c | 5 +++++
drivers/tty/serial/xilinx_uartps.c | 2 +-
9 files changed, 37 insertions(+), 1 deletion(-)
--
2.7.4
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/9] serial: arc_uart: Fix out-of-bounds access through DT alias
2018-02-23 13:38 [PATCH v2 0/9] serial: Fix out-of-bounds accesses through DT aliases Geert Uytterhoeven
@ 2018-02-23 13:38 ` Geert Uytterhoeven
2018-02-23 13:38 ` [PATCH v2 3/9] serial: imx: Fix out-of-bounds access through serial port index Geert Uytterhoeven
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Geert Uytterhoeven @ 2018-02-23 13:38 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: devicetree, Barry Song, Geert Uytterhoeven, Vineet Gupta,
Michal Simek, linux-kernel, linux-renesas-soc, linux-serial,
Jiri Slaby, linux-snps-arc, linux-arm-kernel
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>
---
v2:
- Fix Fixes reference,
- Use ARRAY_SIZE().
---
drivers/tty/serial/arc_uart.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/tty/serial/arc_uart.c b/drivers/tty/serial/arc_uart.c
index 2599f9ecccfe7769..d904a3a345e74785 100644
--- a/drivers/tty/serial/arc_uart.c
+++ b/drivers/tty/serial/arc_uart.c
@@ -593,6 +593,11 @@ static int arc_serial_probe(struct platform_device *pdev)
if (dev_id < 0)
dev_id = 0;
+ if (dev_id >= ARRAY_SIZE(arc_uart_ports)) {
+ dev_err(&pdev->dev, "serial%d out of range\n", dev_id);
+ return -EINVAL;
+ }
+
uart = &arc_uart_ports[dev_id];
port = &uart->port;
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/9] serial: imx: Fix out-of-bounds access through serial port index
2018-02-23 13:38 [PATCH v2 0/9] serial: Fix out-of-bounds accesses through DT aliases Geert Uytterhoeven
2018-02-23 13:38 ` [PATCH v2 1/9] serial: arc_uart: Fix out-of-bounds access through DT alias Geert Uytterhoeven
@ 2018-02-23 13:38 ` Geert Uytterhoeven
2018-02-23 13:51 ` Uwe Kleine-König
2018-02-23 13:38 ` [PATCH v2 4/9] serial: mxs-auart: " Geert Uytterhoeven
` (3 subsequent siblings)
5 siblings, 1 reply; 9+ messages in thread
From: Geert Uytterhoeven @ 2018-02-23 13:38 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: devicetree, Barry Song, Geert Uytterhoeven, Vineet Gupta,
Michal Simek, linux-kernel, linux-renesas-soc, linux-serial,
Jiri Slaby, linux-snps-arc, linux-arm-kernel
The imx_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: ff05967a07225ab6 ("serial/imx: add of_alias_get_id() reference back")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
- Fix Fixes reference,
- Add blank line,
- Use ARRAY_SIZE(),
- Update patch description for platform data.
---
drivers/tty/serial/imx.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 1d7ca382bc12b238..7c9bdc8e34ac9109 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -2042,6 +2042,12 @@ static int serial_imx_probe(struct platform_device *pdev)
else if (ret < 0)
return ret;
+ if (sport->port.line >= ARRAY_SIZE(imx_ports)) {
+ dev_err(&pdev->dev, "serial%d out of range\n",
+ sport->port.line);
+ return -EINVAL;
+ }
+
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(base))
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 4/9] serial: mxs-auart: Fix out-of-bounds access through serial port index
2018-02-23 13:38 [PATCH v2 0/9] serial: Fix out-of-bounds accesses through DT aliases Geert Uytterhoeven
2018-02-23 13:38 ` [PATCH v2 1/9] serial: arc_uart: Fix out-of-bounds access through DT alias Geert Uytterhoeven
2018-02-23 13:38 ` [PATCH v2 3/9] serial: imx: Fix out-of-bounds access through serial port index Geert Uytterhoeven
@ 2018-02-23 13:38 ` Geert Uytterhoeven
2018-02-23 13:38 ` [PATCH v2 6/9] serial: samsung: " Geert Uytterhoeven
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Geert Uytterhoeven @ 2018-02-23 13:38 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: devicetree, Barry Song, Geert Uytterhoeven, Vineet Gupta,
Michal Simek, linux-kernel, linux-renesas-soc, linux-serial,
Jiri Slaby, linux-snps-arc, linux-arm-kernel
The auart_port[] 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: 1ea6607d4cdc9179 ("serial: mxs-auart: Allow device tree probing")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
- Fix Fixes reference,
- Use ARRAY_SIZE(),
- Update patch description for platform data.
---
drivers/tty/serial/mxs-auart.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
index 079dc47aa142d8e1..caa8a41b6e71df9e 100644
--- a/drivers/tty/serial/mxs-auart.c
+++ b/drivers/tty/serial/mxs-auart.c
@@ -1663,6 +1663,10 @@ static int mxs_auart_probe(struct platform_device *pdev)
s->port.line = pdev->id < 0 ? 0 : pdev->id;
else if (ret < 0)
return ret;
+ if (s->port.line >= ARRAY_SIZE(auart_port)) {
+ dev_err(&pdev->dev, "serial%d out of range\n", s->port.line);
+ return -EINVAL;
+ }
if (of_id) {
pdev->id_entry = of_id->data;
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 6/9] serial: samsung: Fix out-of-bounds access through serial port index
2018-02-23 13:38 [PATCH v2 0/9] serial: Fix out-of-bounds accesses through DT aliases Geert Uytterhoeven
` (2 preceding siblings ...)
2018-02-23 13:38 ` [PATCH v2 4/9] serial: mxs-auart: " Geert Uytterhoeven
@ 2018-02-23 13:38 ` Geert Uytterhoeven
2018-02-23 13:38 ` [PATCH v2 7/9] serial: sh-sci: Fix out-of-bounds access through DT alias Geert Uytterhoeven
2018-02-23 13:38 ` [PATCH v2 9/9] serial: xuartps: " Geert Uytterhoeven
5 siblings, 0 replies; 9+ messages in thread
From: Geert Uytterhoeven @ 2018-02-23 13:38 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: devicetree, Barry Song, Geert Uytterhoeven, Vineet Gupta,
Michal Simek, linux-kernel, linux-renesas-soc, linux-serial,
Jiri Slaby, linux-snps-arc, linux-arm-kernel
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>
---
v2:
- Fix Fixes reference,
- Use ARRAY_SIZE(),
- Update patch description for non-DT case.
---
drivers/tty/serial/samsung.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
index f9fecc5ed0cee826..3f2f8c118ce09d56 100644
--- a/drivers/tty/serial/samsung.c
+++ b/drivers/tty/serial/samsung.c
@@ -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);
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 7/9] serial: sh-sci: Fix out-of-bounds access through DT alias
2018-02-23 13:38 [PATCH v2 0/9] serial: Fix out-of-bounds accesses through DT aliases Geert Uytterhoeven
` (3 preceding siblings ...)
2018-02-23 13:38 ` [PATCH v2 6/9] serial: samsung: " Geert Uytterhoeven
@ 2018-02-23 13:38 ` Geert Uytterhoeven
2018-02-23 13:38 ` [PATCH v2 9/9] serial: xuartps: " Geert Uytterhoeven
5 siblings, 0 replies; 9+ messages in thread
From: Geert Uytterhoeven @ 2018-02-23 13:38 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: devicetree, Barry Song, Geert Uytterhoeven, Vineet Gupta,
Michal Simek, linux-kernel, linux-renesas-soc, linux-serial,
Jiri Slaby, linux-snps-arc, linux-arm-kernel
The sci_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_SH_SCI_NR_UARTS), so this can even be triggered using a
legitimate DTB.
Fixes: 97ed9790c514066b ("serial: sh-sci: Remove unused platform data capabilities field")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
- Fix Fixes reference,
- Use ARRAY_SIZE().
---
drivers/tty/serial/sh-sci.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 4d14f321cbec95e0..f6a6610d434efc33 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -3096,6 +3096,10 @@ static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev,
dev_err(&pdev->dev, "failed to get alias id (%d)\n", id);
return NULL;
}
+ if (id >= ARRAY_SIZE(sci_ports)) {
+ dev_err(&pdev->dev, "serial%d out of range\n", id);
+ return NULL;
+ }
sp = &sci_ports[id];
*dev_id = id;
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 9/9] serial: xuartps: Fix out-of-bounds access through DT alias
2018-02-23 13:38 [PATCH v2 0/9] serial: Fix out-of-bounds accesses through DT aliases Geert Uytterhoeven
` (4 preceding siblings ...)
2018-02-23 13:38 ` [PATCH v2 7/9] serial: sh-sci: Fix out-of-bounds access through DT alias Geert Uytterhoeven
@ 2018-02-23 13:38 ` Geert Uytterhoeven
2018-02-23 13:41 ` Michal Simek
5 siblings, 1 reply; 9+ messages in thread
From: Geert Uytterhoeven @ 2018-02-23 13:38 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: devicetree, Barry Song, Geert Uytterhoeven, Vineet Gupta,
Michal Simek, linux-kernel, linux-renesas-soc, linux-serial,
Jiri Slaby, linux-snps-arc, linux-arm-kernel
The cdns_uart_port[] 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: 928e9263492069ee ("tty: xuartps: Initialize ports according to aliases")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
- Fix Fixes reference.
---
drivers/tty/serial/xilinx_uartps.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c
index b9b2bc76bcac606c..abcb4d09a2d866d0 100644
--- a/drivers/tty/serial/xilinx_uartps.c
+++ b/drivers/tty/serial/xilinx_uartps.c
@@ -1110,7 +1110,7 @@ static struct uart_port *cdns_uart_get_port(int id)
struct uart_port *port;
/* Try the given port id if failed use default method */
- if (cdns_uart_port[id].mapbase != 0) {
+ if (id < CDNS_UART_NR_PORTS && cdns_uart_port[id].mapbase != 0) {
/* Find the next unused port */
for (id = 0; id < CDNS_UART_NR_PORTS; id++)
if (cdns_uart_port[id].mapbase == 0)
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 9/9] serial: xuartps: Fix out-of-bounds access through DT alias
2018-02-23 13:38 ` [PATCH v2 9/9] serial: xuartps: " Geert Uytterhoeven
@ 2018-02-23 13:41 ` Michal Simek
0 siblings, 0 replies; 9+ messages in thread
From: Michal Simek @ 2018-02-23 13:41 UTC (permalink / raw)
To: Geert Uytterhoeven, Greg Kroah-Hartman
Cc: devicetree, Barry Song, Vineet Gupta, Michal Simek, linux-kernel,
linux-renesas-soc, linux-serial, Jiri Slaby, linux-snps-arc,
linux-arm-kernel
On 23.2.2018 14:38, Geert Uytterhoeven wrote:
> The cdns_uart_port[] 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: 928e9263492069ee ("tty: xuartps: Initialize ports according to aliases")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> v2:
> - Fix Fixes reference.
> ---
> drivers/tty/serial/xilinx_uartps.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c
> index b9b2bc76bcac606c..abcb4d09a2d866d0 100644
> --- a/drivers/tty/serial/xilinx_uartps.c
> +++ b/drivers/tty/serial/xilinx_uartps.c
> @@ -1110,7 +1110,7 @@ static struct uart_port *cdns_uart_get_port(int id)
> struct uart_port *port;
>
> /* Try the given port id if failed use default method */
> - if (cdns_uart_port[id].mapbase != 0) {
> + if (id < CDNS_UART_NR_PORTS && cdns_uart_port[id].mapbase != 0) {
> /* Find the next unused port */
> for (id = 0; id < CDNS_UART_NR_PORTS; id++)
> if (cdns_uart_port[id].mapbase == 0)
>
Reviewed-by: Michal Simek <michal.simek@xilinx.com>
Thanks,
Michal
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/9] serial: imx: Fix out-of-bounds access through serial port index
2018-02-23 13:38 ` [PATCH v2 3/9] serial: imx: Fix out-of-bounds access through serial port index Geert Uytterhoeven
@ 2018-02-23 13:51 ` Uwe Kleine-König
0 siblings, 0 replies; 9+ messages in thread
From: Uwe Kleine-König @ 2018-02-23 13:51 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: devicetree, Barry Song, Greg Kroah-Hartman, Michal Simek,
linux-kernel, linux-renesas-soc, Vineet Gupta, linux-serial,
Jiri Slaby, linux-snps-arc, linux-arm-kernel
On Fri, Feb 23, 2018 at 02:38:31PM +0100, Geert Uytterhoeven wrote:
> The imx_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: ff05967a07225ab6 ("serial/imx: add of_alias_get_id() reference back")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Thanks for your time
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-02-23 13:51 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-23 13:38 [PATCH v2 0/9] serial: Fix out-of-bounds accesses through DT aliases Geert Uytterhoeven
2018-02-23 13:38 ` [PATCH v2 1/9] serial: arc_uart: Fix out-of-bounds access through DT alias Geert Uytterhoeven
2018-02-23 13:38 ` [PATCH v2 3/9] serial: imx: Fix out-of-bounds access through serial port index Geert Uytterhoeven
2018-02-23 13:51 ` Uwe Kleine-König
2018-02-23 13:38 ` [PATCH v2 4/9] serial: mxs-auart: " Geert Uytterhoeven
2018-02-23 13:38 ` [PATCH v2 6/9] serial: samsung: " Geert Uytterhoeven
2018-02-23 13:38 ` [PATCH v2 7/9] serial: sh-sci: Fix out-of-bounds access through DT alias Geert Uytterhoeven
2018-02-23 13:38 ` [PATCH v2 9/9] serial: xuartps: " Geert Uytterhoeven
2018-02-23 13:41 ` Michal Simek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).