From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 934FF606A33A for ; Tue, 1 Dec 2026 13:34:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=DKnvDLZV; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.a=rsa-sha256 header.s=default header.b=aPR83g97 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=UeejvFVyR7PIvbHhmQ1TDedH8DmDJygVxG3k9SYbqfQ=; b=DKnvDLZVUYsa2h GYKaFFpbvzxqhDsKPL0mB+gNT/Yi+QH8A0G6L/rDHRzZbtzSrjMxYYJAlG591bBNXh66l9hKP4IBg 1UIlKxUe4ArYh3ONwKUBaCATVmd6ZCAHe09a/ewK1BWtN5Z9XLBchAlu4v+LkPMJNNj3gEoKfdmaP rd++f5cwAfLyKoHL3cmhObnQR0R/LFCZlzi5UUq1NQiokKVR6wjR06u7uDJIxgAUsTsVj3Lllaklw bAM//CfHIR+cHVaj1jtdhYfVXqkl+s7gU3BgB/Q1XN0zZv7QH/sFXxM36s1ApxshSgBCnjj/QfKlk Ge9O1cz/kSCJ4zZSpEgg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYNzs-00000008Gv2-2OuV; Tue, 01 Dec 2026 13:34:16 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYNzp-00000008Gtw-3Cy7 for linux-arm-kernel@lists.infradead.org; Tue, 01 Dec 2026 13:34:15 +0000 Received: from [192.168.1.10] (unknown [52.172.102.219]) by linux.microsoft.com (Postfix) with ESMTPSA id 4E76720B7166; Tue, 1 Dec 2026 05:34:10 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4E76720B7166 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1796132052; bh=UeejvFVyR7PIvbHhmQ1TDedH8DmDJygVxG3k9SYbqfQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=aPR83g97IfRokjQWFqkTVRyL3csTDnp+gyZg8HC0UDI1Kpw8QBNmiv/fsaChFYlXf ycEgOqsRULDjuWoFXeeU9/m3jDI2zHBOis7Qm4A7CmfINQOt2UzMwU5sDpbRAplzaq t7w4zLyK+tkLaqxv9vPABwCdW8xWON1cCvy49KB4= Message-ID: Date: Tue, 1 Dec 2026 19:04:08 +0530 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/3] clk: zynqmp: Fix unbounded parent array overflow in clock parent lookup To: Radhey Shyam Pandey , 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 References: <20261201064353.238312-1-radhey.shyam.pandey@amd.com> <20261201064353.238312-3-radhey.shyam.pandey@amd.com> Content-Language: en-US From: Prasanna Kumar T S M In-Reply-To: <20261201064353.238312-3-radhey.shyam.pandey@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_053413_882541_805452A9 X-CRM114-Status: GOOD ( 19.96 ) X-Spam-Score: -4.4 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" On 01-12-2026 12:13, Radhey Shyam Pandey wrote: > From: Beesam Sridhar Sagar > > 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 > Signed-off-by: Radhey Shyam Pandey > --- > 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; > }