[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20211130085455.75537-1-zhou1615@umn.edu>
Date: Tue, 30 Nov 2021 16:54:54 +0800
From: Zhou Qingyang <zhou1615@....edu>
To: zhou1615@....edu
Cc: kjlu@....edu, Michael Turquette <mturquette@...libre.com>,
Stephen Boyd <sboyd@...nel.org>,
Matthias Brugger <matthias.bgg@...il.com>,
Shunli Wang <shunli.wang@...iatek.com>,
Erin Lo <erin.lo@...iatek.com>,
James Liao <jamesjj.liao@...iatek.com>,
linux-clk@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org,
linux-mediatek@...ts.infradead.org
Subject: [PATCH] clk: mediatek: mt2701: Fix a NULL pointer dereference in mtk_infrasys_init_early()
In mtk_infrasys_init_early(), the return value of mtk_alloc_clk_data()
is assigned to infra_clk_data and there is a dereference of it in
mtk_infrasys_init_early(), which could lead to a NULL pointer
dereference on failure of mtk_alloc_clk_data().
Fix this bug by adding a check of infra_clk_data.
This bug was found by a static analyzer. The analysis employs
differential checking to identify inconsistent security operations
(e.g., checks or kfrees) between two code paths and confirms that the
inconsistent operations are not recovered in the current function or
the callers, so they constitute bugs.
Note that, as a bug found by static analysis, it can be a false
positive or hard to trigger. Multiple researchers have cross-reviewed
the bug.
Builds with CONFIG_COMMON_CLK_MT2701=y show no new warnings, and our
static analyzer no longer warns about this code.
Fixes: e9862118272a ("clk: mediatek: Add MT2701 clock support")
Signed-off-by: Zhou Qingyang <zhou1615@....edu>
---
drivers/clk/mediatek/clk-mt2701.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/clk/mediatek/clk-mt2701.c b/drivers/clk/mediatek/clk-mt2701.c
index 695be0f77427..9ba30089cb9a 100644
--- a/drivers/clk/mediatek/clk-mt2701.c
+++ b/drivers/clk/mediatek/clk-mt2701.c
@@ -742,6 +742,11 @@ static void __init mtk_infrasys_init_early(struct device_node *node)
if (!infra_clk_data) {
infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR);
+ if (!infra_clk_data) {
+ pr_err("%s(): could not register clock provider: %d\n",
+ __func__, -ENOMEM);
+ return;
+ }
for (i = 0; i < CLK_INFRA_NR; i++)
infra_clk_data->clks[i] = ERR_PTR(-EPROBE_DEFER);
--
2.25.1
Powered by blists - more mailing lists