All of lore.kernel.org
 help / color / mirror / Atom feed
From: Prasanna Kumar T S M <ptsm@linux.microsoft.com>
To: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>,
	sboyd@kernel.org, bmasney+clk@redhat.com,
	jbrunet+clk@baylibre.com, michal.simek@amd.com,
	shubhrajyoti.datta@amd.com
Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	git@amd.com, Beesam Sridhar Sagar <sagar.beesamsridhar@amd.com>
Subject: Re: [PATCH 2/3] clk: zynqmp: Fix unbounded parent array overflow in clock parent lookup
Date: Tue, 1 Dec 2026 19:04:08 +0530	[thread overview]
Message-ID: <eec74723-5625-4506-a784-72aea593ffb3@linux.microsoft.com> (raw)
In-Reply-To: <20261201064353.238312-3-radhey.shyam.pandey@amd.com>



On 01-12-2026 12:13, Radhey Shyam Pandey wrote:
> From: Beesam Sridhar Sagar <sagar.beesamsridhar@amd.com>
> 
> zynqmp_clock_get_parents() used a do/while loop keyed off *num_parents,
> which counts only successfully resolved parents and can lag behind the
> write index j. This allowed __zynqmp_clock_get_parents() to keep
> writing into parents[] beyond MAX_PARENT entries. Bound the write
> index directly against MAX_PARENT and pass the remaining capacity into
> __zynqmp_clock_get_parents() so it never writes past the caller's
> buffer.
> 
> Fixes: 3fde0e16d016 ("drivers: clk: Add ZynqMP clock driver")
> Signed-off-by: Beesam Sridhar Sagar <sagar.beesamsridhar@amd.com>
> Signed-off-by: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
> ---
>   drivers/clk/zynqmp/clkc.c | 16 ++++++++++------
>   1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/clk/zynqmp/clkc.c b/drivers/clk/zynqmp/clkc.c
> index 9650c67336e6..5d827b2bb0ad 100644
> --- a/drivers/clk/zynqmp/clkc.c
> +++ b/drivers/clk/zynqmp/clkc.c
> @@ -469,18 +469,20 @@ static int zynqmp_clock_get_topology(u32 clk_id,
>    *				   response data
>    * @parents:		Clock parents
>    * @response:		Clock parents data received from firmware
> + * @max_write:		Maximum number of entries that may be written to @parents
>    * @nparent:		Number of parent
>    *
>    * Return: 0 on success else error+reason
>    */
>   static int __zynqmp_clock_get_parents(struct clock_parent *parents,
>   				      struct parents_resp *response,
> -				      u32 *nparent)
> +				      u32 max_write, u32 *nparent)
>   {
>   	int i;
>   	struct clock_parent *parent;
>   
> -	for (i = 0; i < ARRAY_SIZE(response->parents); i++) {
> +	/* Never write past the caller-provided capacity of the parents[] array */
> +	for (i = 0; i < ARRAY_SIZE(response->parents) && i < max_write; i++) {

The max_write should be less than ARRAY_SIZE(response->parents). Isn't 
it? If so "i < max_write" => "i < ARRAY_SIZE(response->parents)", 
checking "i < max_write" should be sufficient.

>   		if (response->parents[i] == NA_PARENT)
>   			return END_OF_PARENTS;
>   
> @@ -512,11 +514,13 @@ static int __zynqmp_clock_get_parents(struct clock_parent *parents,
>   static int zynqmp_clock_get_parents(u32 clk_id, struct clock_parent *parents,
>   				    u32 *num_parents)
>   {
> -	int j = 0, ret;
>   	struct parents_resp response = { };
> +	u32 j = 0;
> +	int ret;
>   
>   	*num_parents = 0;
> -	do {
> +	/* Bound the loop by the write index so parents[] is never overrun */
> +	while (j < MAX_PARENT) {
>   		/* Get parents from firmware */
>   		ret = zynqmp_pm_clock_get_parents(clock[clk_id].clk_id, j,
>   						  &response);
> @@ -524,11 +528,11 @@ static int zynqmp_clock_get_parents(u32 clk_id, struct clock_parent *parents,
>   			return ret;
>   
>   		ret = __zynqmp_clock_get_parents(&parents[j], &response,
> -						 num_parents);
> +						 MAX_PARENT - j, num_parents);
>   		if (ret == END_OF_PARENTS)
>   			return 0;
>   		j += ARRAY_SIZE(response.parents);
> -	} while (*num_parents <= MAX_PARENT);
> +	}
>   
>   	return 0;
>   }

  reply	other threads:[~2026-12-01 13:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  6:43 [PATCH 0/3] clk: zynqmp: fix out-of-bounds accesses in firmware clock parsing Radhey Shyam Pandey
2026-12-01  6:43 ` [PATCH 1/3] clk: zynqmp: Fix off-by-one loop bound in zynqmp_clock_get_topology() Radhey Shyam Pandey
2026-12-01 13:21   ` Prasanna Kumar T S M
2026-12-01  6:43 ` [PATCH 2/3] clk: zynqmp: Fix unbounded parent array overflow in clock parent lookup Radhey Shyam Pandey
2026-12-01 13:34   ` Prasanna Kumar T S M [this message]
2026-12-01  6:43 ` [PATCH 3/3] clk: zynqmp: Fix unchecked type index into clock topology tables Radhey Shyam Pandey
2026-12-01  6:54   ` sashiko-bot
2026-12-01 13:21   ` Prasanna Kumar T S M

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=eec74723-5625-4506-a784-72aea593ffb3@linux.microsoft.com \
    --to=ptsm@linux.microsoft.com \
    --cc=bmasney+clk@redhat.com \
    --cc=git@amd.com \
    --cc=jbrunet+clk@baylibre.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=michal.simek@amd.com \
    --cc=radhey.shyam.pandey@amd.com \
    --cc=sagar.beesamsridhar@amd.com \
    --cc=sboyd@kernel.org \
    --cc=shubhrajyoti.datta@amd.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.