Skip to content

Commit bc16355

Browse files
lategoodbyebebarino
authored andcommitted
clk: bcm: rpi: Prevent out-of-bounds access
The while loop in raspberrypi_discover_clocks() relies on the assumption that the id of the last clock element is zero. Because this data comes from the Videocore firmware and it doesn't guarantuee such a behavior this could lead to out-of-bounds access. So fix this by providing a sentinel element. Fixes: 93d2725 ("clk: bcm: rpi: Discover the firmware clocks") Link: raspberrypi/firmware#1688 Suggested-by: Phil Elwell <[email protected]> Signed-off-by: Stefan Wahren <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Florian Fainelli <[email protected]> Reviewed-by: Ivan T. Ivanov <[email protected]> Signed-off-by: Stephen Boyd <[email protected]>
1 parent 35f73cc commit bc16355

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/clk/bcm/clk-raspberrypi.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,13 @@ static int raspberrypi_discover_clocks(struct raspberrypi_clk *rpi,
344344
struct rpi_firmware_get_clocks_response *clks;
345345
int ret;
346346

347+
/*
348+
* The firmware doesn't guarantee that the last element of
349+
* RPI_FIRMWARE_GET_CLOCKS is zeroed. So allocate an additional
350+
* zero element as sentinel.
351+
*/
347352
clks = devm_kcalloc(rpi->dev,
348-
RPI_FIRMWARE_NUM_CLK_ID, sizeof(*clks),
353+
RPI_FIRMWARE_NUM_CLK_ID + 1, sizeof(*clks),
349354
GFP_KERNEL);
350355
if (!clks)
351356
return -ENOMEM;

0 commit comments

Comments
 (0)