All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] serial: sh-sci: Fix use-after-free on subsequent port startup
@ 2018-07-17  8:58 Geert Uytterhoeven
  2018-07-17 10:35 ` Ulrich Hecht
  2018-07-17 12:17 ` Simon Horman
  0 siblings, 2 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2018-07-17  8:58 UTC (permalink / raw)
  To: Chris Brandt, Greg Kroah-Hartman, Jiri Slaby
  Cc: linux-serial, linux-renesas-soc, linux-kernel, Geert Uytterhoeven

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>
---
 drivers/tty/serial/sh-sci.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 5808edfe3f7be404..f8e53ac5c17dfb94 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -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
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] serial: sh-sci: Fix use-after-free on subsequent port startup
  2018-07-17  8:58 [PATCH] serial: sh-sci: Fix use-after-free on subsequent port startup Geert Uytterhoeven
@ 2018-07-17 10:35 ` Ulrich Hecht
  2018-07-17 12:17 ` Simon Horman
  1 sibling, 0 replies; 3+ messages in thread
From: Ulrich Hecht @ 2018-07-17 10:35 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Chris Brandt, Greg Kroah-Hartman, Jiri Slaby, linux-serial,
	Linux-Renesas, linux-kernel

On Tue, Jul 17, 2018 at 10:58 AM, Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
> 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>
> ---
>  drivers/tty/serial/sh-sci.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
> index 5808edfe3f7be404..f8e53ac5c17dfb94 100644
> --- a/drivers/tty/serial/sh-sci.c
> +++ b/drivers/tty/serial/sh-sci.c
> @@ -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
> --
> 2.17.1
>

Reviewed-by: Ulrich Hecht <ulrich.hecht+renesas@gmail.com>

CU
Uli

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] serial: sh-sci: Fix use-after-free on subsequent port startup
  2018-07-17  8:58 [PATCH] serial: sh-sci: Fix use-after-free on subsequent port startup Geert Uytterhoeven
  2018-07-17 10:35 ` Ulrich Hecht
@ 2018-07-17 12:17 ` Simon Horman
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2018-07-17 12:17 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Chris Brandt, Greg Kroah-Hartman, Jiri Slaby, linux-serial,
	linux-renesas-soc, linux-kernel

On Tue, Jul 17, 2018 at 10:58:10AM +0200, Geert Uytterhoeven wrote:
> 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: Simon Horman <horms+renesas@verge.net.au>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-07-17 12:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-17  8:58 [PATCH] serial: sh-sci: Fix use-after-free on subsequent port startup Geert Uytterhoeven
2018-07-17 10:35 ` Ulrich Hecht
2018-07-17 12:17 ` Simon Horman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.