serial: samsung: Fix possible out of bounds access on non-DT platform
authorKrzysztof Kozlowski <>
Thu, 16 Jun 2016 06:27:36 +0000 (08:27 +0200)
committerBen Hutchings <>
Sun, 20 Nov 2016 01:01:23 +0000 (01:01 +0000)
commit 926b7b5122c96e1f18cd20e85a286c7ec8d18c97 upstream.

On non-DeviceTree platforms, the index of serial device is a static
variable incremented on each probe.  It is incremented even if deferred
probe happens when getting the clock in s3c24xx_serial_init_port().

This index is used for referencing elements of statically allocated
s3c24xx_serial_ports array.  In case of re-probe, the index will point
outside of this array leading to memory corruption.

Increment the index only on successful probe.

Reported-by: Bartlomiej Zolnierkiewicz <>
Fixes: b497549a035c ("[ARM] S3C24XX: Split serial driver into core and per-cpu drivers")
Signed-off-by: Krzysztof Kozlowski <>
Signed-off-by: Greg Kroah-Hartman <>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <>

index 626e75b..808d171 100644 (file)
@@ -1237,8 +1237,6 @@ int s3c24xx_serial_probe(struct platform_device *dev,
        dbg("s3c24xx_serial_probe(%p, %p) %d\n", dev, info, probe_index);
        ourport = &s3c24xx_serial_ports[probe_index];
-       probe_index++;
        dbg("%s: initialising port %p...\n", __func__, ourport);
        ret = s3c24xx_serial_init_port(ourport, info, dev);
@@ -1275,6 +1273,8 @@ int __devexit s3c24xx_serial_remove(struct platform_device *dev)
                uart_remove_one_port(&s3c24xx_uart_drv, port);
+       probe_index++;
        return 0;