[lvc-project] [PATCH] clk: renesas: cpg-mssr: Fix use after free if cpg_mssr_common_init() failed
Geert Uytterhoeven
geert at linux-m68k.org
Fri Dec 23 12:45:03 MSK 2022
Hi Alexey,
On Thu, Dec 22, 2022 at 11:23 PM Alexey Khoroshilov
<khoroshilov at ispras.ru> wrote:
> If cpg_mssr_common_init() fails after assigning priv to global variable
> cpg_mssr_priv, it deallocates priv, but cpg_mssr_priv keeps dangling
> pointer that potentially can be used later.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 1f7db7bbf031 ("clk: renesas: cpg-mssr: Add early clock support")
> Signed-off-by: Alexey Khoroshilov <khoroshilov at ispras.ru>
Thanks for your patch!
> --- a/drivers/clk/renesas/renesas-cpg-mssr.c
> +++ b/drivers/clk/renesas/renesas-cpg-mssr.c
> @@ -1025,6 +1025,7 @@ static int __init cpg_mssr_common_init(struct device *dev,
> if (priv->base)
> iounmap(priv->base);
> kfree(priv);
> + cpg_mssr_priv = NULL;
While this is correct, I think it would be better to just postpone
the initial assignment to cpg_mssr_priv until everything in
cpg_mssr_common_init() has succeeded, i.e. just below the
"return 0;" above.
>
> return error;
> }
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at 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
More information about the lvc-project
mailing list