public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: Samuel Holland <samuel@sholland.org>
Cc: u-boot@lists.denx.de, Jagan Teki <jagan@amarulasolutions.com>,
	Lukasz Majewski <lukma@denx.de>,
	Sean Anderson <seanga2@gmail.com>, Bin Meng <bmeng.cn@gmail.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Maxime Ripard <maxime.ripard@bootlin.com>
Subject: Re: [PATCH 2/7] clk: sunxi: Prevent out-of-bounds gate array access
Date: Sun, 26 Jun 2022 11:43:03 +0100	[thread overview]
Message-ID: <20220626114303.002c8d3a@slackpad.lan> (raw)
In-Reply-To: <20220509052937.42283-3-samuel@sholland.org>

On Mon,  9 May 2022 00:29:32 -0500
Samuel Holland <samuel@sholland.org> wrote:

> Because the gate arrays are not given explicit sizes, the arrays are
> only as large as the highest-numbered gate described in the driver.
> However, only a subset of the CCU clocks are needed by U-Boot. So there
> are valid clock specifiers with indexes greater than the size of the
> arrays. Referencing any of these clocks causes out-of-bounds access.
> Fix this by checking the identifier against the size of the array.
> 
> Fixes: 0d47bc705651 ("clk: Add Allwinner A64 CLK driver")
> Signed-off-by: Samuel Holland <samuel@sholland.org>

That's a good addition! Amended the patch to cover CCU_CLK_F_DUMMY_GATE.

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Cheers,
Andre

> ---
> 
>  drivers/clk/sunxi/clk_sunxi.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/sunxi/clk_sunxi.c b/drivers/clk/sunxi/clk_sunxi.c
> index 9673b58a49..3108e5b66d 100644
> --- a/drivers/clk/sunxi/clk_sunxi.c
> +++ b/drivers/clk/sunxi/clk_sunxi.c
> @@ -18,6 +18,9 @@
>  static const struct ccu_clk_gate *priv_to_gate(struct ccu_priv *priv,
>  					       unsigned long id)
>  {
> +	if (id >= priv->desc->num_gates)
> +		return NULL;
> +
>  	return &priv->desc->gates[id];
>  }
>  
> @@ -27,7 +30,7 @@ static int sunxi_set_gate(struct clk *clk, bool on)
>  	const struct ccu_clk_gate *gate = priv_to_gate(priv, clk->id);
>  	u32 reg;
>  
> -	if (!(gate->flags & CCU_CLK_F_IS_VALID)) {
> +	if (!gate || !(gate->flags & CCU_CLK_F_IS_VALID)) {
>  		printf("%s: (CLK#%ld) unhandled\n", __func__, clk->id);
>  		return 0;
>  	}


  reply	other threads:[~2022-06-27  0:48 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-09  5:29 [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup Samuel Holland
2022-05-09  5:29 ` [PATCH 1/7] clk: sunxi: Store the array sizes in the CCU descriptor Samuel Holland
2022-06-25 17:10   ` Andre Przywara
2022-05-09  5:29 ` [PATCH 2/7] clk: sunxi: Prevent out-of-bounds gate array access Samuel Holland
2022-06-26 10:43   ` Andre Przywara [this message]
2022-05-09  5:29 ` [PATCH 3/7] reset: sunxi: Get the reset count from the CCU descriptor Samuel Holland
2022-06-26 10:51   ` Andre Przywara
2022-05-09  5:29 ` [PATCH 4/7] clk: sunxi: Use a single driver for all variants Samuel Holland
2022-06-27  0:43   ` Andre Przywara
2022-05-09  5:29 ` [PATCH 5/7] clk: sunxi: Convert driver private data to platform data Samuel Holland
2022-06-27 19:34   ` Andre Przywara
2022-05-09  5:29 ` [PATCH 6/7] reset: " Samuel Holland
2022-06-27 19:41   ` Andre Przywara
2022-05-09  5:29 ` [PATCH 7/7] reset: sunxi: Reuse the platform data from the clock driver Samuel Holland
2022-06-27 23:45   ` Andre Przywara
2022-05-10 23:24 ` [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup Andre Przywara
2022-05-11 15:48 ` Sean Anderson
2022-06-28  0:40 ` Andre Przywara
2022-06-28  2:45   ` Samuel Holland

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=20220626114303.002c8d3a@slackpad.lan \
    --to=andre.przywara@arm.com \
    --cc=bmeng.cn@gmail.com \
    --cc=jagan@amarulasolutions.com \
    --cc=lukma@denx.de \
    --cc=maxime.ripard@bootlin.com \
    --cc=samuel@sholland.org \
    --cc=seanga2@gmail.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /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