serial: sh-sci: Fix use-after-free on subsequent port startup
authorGeert Uytterhoeven <geert+renesas@glider.be>
Tue, 17 Jul 2018 08:58:10 +0000 (10:58 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 21 Jul 2018 06:39:25 +0000 (08:39 +0200)
sci_request_irq() checks port->irqstr[j] for a NULL pointer, to decide
if a fallback interrupt name string should be allocated or not.

While this string is freed during port shutdown, the pointer is not
zeroed.  Hence on a subsequent startup of the port, it will still be
pointing to the freed memory, leading to e.g.

    WARNING: CPU: 0 PID: 404 at fs/proc/generic.c:388 __proc_create+0xbc/0x260
    name len 0

or to a crash (the latter is more likely with CONFIG_DEBUG_SLAB=y, due
to the poisoning of freed memory).

Instead of zeroeing the pointer at multiple places, preinitialize
port->irqstr[j] to zero to fix this.

Fixes: 8b0bbd956228ae87 ("serial: sh-sci: Add support for R7S9210")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Ulrich Hecht <ulrich.hecht+renesas@gmail.com>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/sh-sci.c

index 5808edf..f8e53ac 100644 (file)
@@ -1872,6 +1872,7 @@ static int sci_request_irq(struct sci_port *port)
                }
 
                desc = sci_irq_desc + i;
+               port->irqstr[j] = NULL;
                if (SCIx_TEIDRI_IRQ_EXISTS(port)) {
                        /*
                         * ERI and BRI are muxed, just register ERI and