From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=13.77.154.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796132053; b=ccGYY6Lfz0SIhUHfZ7U/Wxn7ztq3nRrFJNDoQox4XEY7xojqbW2niXsk/32htepE20UR lAdp5T4D/zUYL7STbJTuWqYbSRbU9JZbxdkVJki19rc3sydwxZ3I+YaBzuL5T5K+AYaDn DfSfnVU4IvMKTuH82sw2DbGaG9Vsp6wqYdt43ncP63f32H8DX/7uho/D06n2Nziq/2kGU bS6+KCGUA9AQIsURXcD/Q1DEoUBt6xm9MA+WF8Bb+y6xoBKvglZbycrftHbVrzy6eSo5L TvHsfQXZZqhMCbuOhTTcUJ9fqRzLsZJF8wc21A26fE3do5fPAiFpeCjbQqEfzirZx5g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796132053; h=DMARC-Filter:Received:DKIM-Filter:DKIM-Signature:Message-ID:Date: MIME-Version:User-Agent:Subject:To:Cc:References:Content-Language: From:In-Reply-To:Content-Type:Content-Transfer-Encoding:X-Spam-Status: X-Spam-Checker-Version; bh=UeejvFVyR7PIvbHhmQ1TDedH8DmDJygVxG3k9SYbqfQ=; b=Z+cMka1UUd65HtZBA4vZYCROOpD+t6yNAzEOKBiRbdCpZDGhJSeGjN/lqC/7ZXHVTapc rpeSr07wHa8jbfwMYud7x5XjP13RNynQp0A2eTWDCjRtAUroSEM9TlY4XopTOUsCXCZiG GW+a/98gbeZ5rtXoAldN5L6J10/FWvjHSbndsotDelKaUMULCpoZyzzwATEPChFOPUq+l p5U3zmt8Ch9wbjOvCAm3ANr/s9D7dJ4zGAjiUcV6fRku5vbvcfpISgl1n6TZ6rD9avw3S zk9s/EnMskco6x/6KPhLRxBfvf6piUPDKOF/GZndgPBxTbQJi8mhMnd+x7f0xC0GlwQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass header.d=linux.microsoft.com header.i=@linux.microsoft.com header.a=rsa-sha256 header.s=default header.b=aPR83g97; arc=none smtp.remote-ip=13.77.154.182 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7724D606A32D for ; Tue, 1 Dec 2026 13:34:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7724D606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; 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 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-Mailing-List: linux-clk@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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; > }