]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
clk: renesas: cpg-mssr: Fix use after free if cpg_mssr_common_init() failed
authorAlexey Khoroshilov <khoroshilov@ispras.ru>
Fri, 23 Dec 2022 14:40:17 +0000 (17:40 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 1 Mar 2024 12:21:50 +0000 (13:21 +0100)
[ Upstream commit fbfd614aeaa2853c2c575299dfe2458db8eff67e ]

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@ispras.ru>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/1671806417-32623-1-git-send-email-khoroshilov@ispras.ru
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/clk/renesas/renesas-cpg-mssr.c

index 21f762aa213135d474c02eed7ea7649977fcee1f..ed67b90fc1b0cfc776dfdd6a7fb26dcda71336ce 100644 (file)
@@ -957,7 +957,6 @@ static int __init cpg_mssr_common_init(struct device *dev,
                goto out_err;
        }
 
-       cpg_mssr_priv = priv;
        priv->num_core_clks = info->num_total_core_clks;
        priv->num_mod_clks = info->num_hw_mod_clks;
        priv->last_dt_core_clk = info->last_dt_core_clk;
@@ -987,6 +986,8 @@ static int __init cpg_mssr_common_init(struct device *dev,
        if (error)
                goto out_err;
 
+       cpg_mssr_priv = priv;
+
        return 0;
 
 out_err: