From 34475e3c87019712b4b4591d47235718fccf4228 Mon Sep 17 00:00:00 2001 From: Etienne Carriere Date: Thu, 23 Nov 2023 17:22:21 +0100 Subject: [PATCH] drivers: clk: limit print_clock_subtree() recursive calls Limit print_clock_subtree() recursive calls to 32. Reported-by: Jens Wiklander Link: https://github.com/OP-TEE/optee_os/pull/6481#discussion_r1403208798 Signed-off-by: Etienne Carriere --- core/drivers/clk/clk.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/drivers/clk/clk.c b/core/drivers/clk/clk.c index 0d605ad3b6a..2c641737fa2 100644 --- a/core/drivers/clk/clk.c +++ b/core/drivers/clk/clk.c @@ -14,6 +14,9 @@ #include #include +/* Max number of recursive calls to print_clock_subtree() */ +#define CLK_PRINT_TREE_MAX_RECURSION 32 + /* Global clock tree lock */ static unsigned int clk_lock = SPINLOCK_UNLOCK; @@ -392,6 +395,12 @@ static void print_clock_subtree(struct clk *clk_root __maybe_unused, #ifdef CFG_DRIVERS_CLK_PRINT_TREE struct clk *clk = NULL; + if (indent == CLK_PRINT_TREE_MAX_RECURSION) { + EMSG("Abort clk subtree loop, %d recursive calls reached", + CLK_PRINT_TREE_MAX_RECURSION); + return; + } + STAILQ_FOREACH(clk, &clock_list, link) { if (clk_get_parent(clk) == clk_root) { print_clock(clk, indent + 1);