From: Stepan Ionichev <sozdayvek@gmail.com>
To: daniel@thingy.jp
Cc: romain.perier@gmail.com, mturquette@baylibre.com,
sboyd@kernel.org, linux-arm-kernel@lists.infradead.org,
linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
Stepan Ionichev <sozdayvek@gmail.com>
Subject: [PATCH] clk: mstar: msc313-mpll: fix one-element shadow array overrun
Date: Sat, 9 May 2026 15:42:54 +0500 [thread overview]
Message-ID: <20260509104255.15479-1-sozdayvek@gmail.com> (raw)
msc313_mpll_probe() defines
#define NUMOUTPUTS (ARRAY_SIZE(output_dividers) + 1)
and uses NUMOUTPUTS for the clock provider's clk_hw count
(clk_data->num = NUMOUTPUTS) and writes that many entries:
mpll->clk_data->hws[0] = &mpll->clk_hw; /* parent */
for (i = 0; i < ARRAY_SIZE(output_dividers); i++) /* dividers */
mpll->clk_data->hws[i + 1] = divhw;
So the function legitimately needs NUMOUTPUTS slots in the
flexible 'hws' array. However the array is allocated for only
ARRAY_SIZE(output_dividers) (== NUMOUTPUTS - 1) slots:
mpll->clk_data = devm_kzalloc(dev, struct_size(mpll->clk_data, hws,
ARRAY_SIZE(output_dividers)), GFP_KERNEL);
The last loop iteration therefore writes one element past the
allocation, and clk_data->num advertises a slot that does not
exist to of_clk_hw_onecell_get().
smatch flags the underflow:
drivers/clk/mstar/clk-msc313-mpll.c:134 msc313_mpll_probe()
error: buffer overflow 'mpll->clk_data->hws' 7 <= 7
Use NUMOUTPUTS in struct_size() so the allocation matches the
declared count and the loop's last write.
Signed-off-by: Stepan Ionichev <sozdayvek@gmail.com>
---
drivers/clk/mstar/clk-msc313-mpll.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/clk/mstar/clk-msc313-mpll.c b/drivers/clk/mstar/clk-msc313-mpll.c
index 61beb4e87..71bedb7e9 100644
--- a/drivers/clk/mstar/clk-msc313-mpll.c
+++ b/drivers/clk/mstar/clk-msc313-mpll.c
@@ -105,7 +105,7 @@ static int msc313_mpll_probe(struct platform_device *pdev)
return PTR_ERR(mpll->loop_div_second);
mpll->clk_data = devm_kzalloc(dev, struct_size(mpll->clk_data, hws,
- ARRAY_SIZE(output_dividers)), GFP_KERNEL);
+ NUMOUTPUTS), GFP_KERNEL);
if (!mpll->clk_data)
return -ENOMEM;
--
2.43.0
reply other threads:[~2026-05-09 17:58 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260509104255.15479-1-sozdayvek@gmail.com \
--to=sozdayvek@gmail.com \
--cc=daniel@thingy.jp \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=romain.perier@gmail.com \
--cc=sboyd@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox