• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Révision6827aba3482d214afea3b3bc4cb2f5bddb606929 (tree)
l'heure2022-07-18 17:37:49
AuteurSamuel Holland <samuel@shol...>
CommiterAndre Przywara

Message de Log

clk: sunxi: Prevent out-of-bounds gate array access

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>
Reviewed-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Andre Przywara <andre.przywara@arm.com>

Change Summary

Modification

--- a/drivers/clk/sunxi/clk_sunxi.c
+++ b/drivers/clk/sunxi/clk_sunxi.c
@@ -18,6 +18,9 @@
1818 static const struct ccu_clk_gate *priv_to_gate(struct ccu_priv *priv,
1919 unsigned long id)
2020 {
21+ if (id >= priv->desc->num_gates)
22+ return NULL;
23+
2124 return &priv->desc->gates[id];
2225 }
2326
@@ -27,10 +30,10 @@ static int sunxi_set_gate(struct clk *clk, bool on)
2730 const struct ccu_clk_gate *gate = priv_to_gate(priv, clk->id);
2831 u32 reg;
2932
30- if ((gate->flags & CCU_CLK_F_DUMMY_GATE))
33+ if (gate && (gate->flags & CCU_CLK_F_DUMMY_GATE))
3134 return 0;
3235
33- if (!(gate->flags & CCU_CLK_F_IS_VALID)) {
36+ if (!gate || !(gate->flags & CCU_CLK_F_IS_VALID)) {
3437 printf("%s: (CLK#%ld) unhandled\n", __func__, clk->id);
3538 return 0;
3639 }