]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
clk: Fix clk_core_get NULL dereference
authorBryan O'Donoghue <bryan.odonoghue@linaro.org>
Sat, 2 Mar 2024 00:52:14 +0000 (00:52 +0000)
committerSasha Levin <sashal@kernel.org>
Tue, 26 Mar 2024 22:21:32 +0000 (18:21 -0400)
commit0efb9ef6fb95384ba631d6819e66f10392aabfa2
tree55986ff252f9741b583799ea06535c435cd94552
parentd83d70b25d2d5f255bbb40843467507c590cd308
clk: Fix clk_core_get NULL dereference

[ Upstream commit e97fe4901e0f59a0bfd524578fe3768f8ca42428 ]

It is possible for clk_core_get to dereference a NULL in the following
sequence:

clk_core_get()
    of_clk_get_hw_from_clkspec()
        __of_clk_get_hw_from_provider()
            __clk_get_hw()

__clk_get_hw() can return NULL which is dereferenced by clk_core_get() at
hw->core.

Prior to commit dde4eff47c82 ("clk: Look for parents with clkdev based
clk_lookups") the check IS_ERR_OR_NULL() was performed which would have
caught the NULL.

Reading the description of this function it talks about returning NULL but
that cannot be so at the moment.

Update the function to check for hw before dereferencing it and return NULL
if hw is NULL.

Fixes: dde4eff47c82 ("clk: Look for parents with clkdev based clk_lookups")
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Link: https://lore.kernel.org/r/20240302-linux-next-24-03-01-simple-clock-fixes-v1-1-25f348a5982b@linaro.org
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/clk/clk.c