public inbox for linuxppc-dev@ozlabs.org
 help / color / mirror / Atom feed
From: Pengpeng Hou <pengpeng@iscas.ac.cn>
To: Madhavan Srinivasan <maddy@linux.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>,
	Christophe Leroy <chleroy@kernel.org>,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	pengpeng@iscas.ac.cn
Subject: [PATCH] powerpc/pseries/energy: validate H_BEST_ENERGY list counts
Date: Tue, 7 Apr 2026 14:09:10 +0800	[thread overview]
Message-ID: <20260407153003.3-powerpc-pseries-energy-pengpeng@iscas.ac.cn> (raw)

get_best_energy_list() reads a one-page u32 array from H_BEST_ENERGY and
trusts retbuf[0] as the number of entry pairs stored there. Counts above
the number of pairs that fit in one page make the loop walk past the page
through buf_page[2 * i + 1].

Reject impossible entry counts before indexing the returned buffer.

Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
 arch/powerpc/platforms/pseries/pseries_energy.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/powerpc/platforms/pseries/pseries_energy.c b/arch/powerpc/platforms/pseries/pseries_energy.c
index 2c661b798235..575216989539 100644
--- a/arch/powerpc/platforms/pseries/pseries_energy.c
+++ b/arch/powerpc/platforms/pseries/pseries_energy.c
@@ -184,6 +184,7 @@ static int drc_index_to_cpu(u32 drc_index)
 #define FLAGS_MODE1	0x004E200000080E01UL
 #define FLAGS_MODE2	0x004E200000080401UL
 #define FLAGS_ACTIVATE  0x100
+#define BEST_ENERGY_LIST_MAX_ENTRIES	(PAGE_SIZE / (sizeof(u32) * 2))
 
 static ssize_t get_best_energy_list(char *page, int activate)
 {
@@ -208,6 +209,11 @@ static ssize_t get_best_energy_list(char *page, int activate)
 		return -EINVAL;
 	}
 
+	if (retbuf[0] > BEST_ENERGY_LIST_MAX_ENTRIES) {
+		free_page((unsigned long)buf_page);
+		return -EINVAL;
+	}
+
 	cnt = retbuf[0];
 	for (i = 0; i < cnt; i++) {
 		cpu = drc_index_to_cpu(buf_page[2*i+1]);
-- 
2.50.1 (Apple Git-155)




                 reply	other threads:[~2026-04-07  6:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260407153003.3-powerpc-pseries-energy-pengpeng@iscas.ac.cn \
    --to=pengpeng@iscas.ac.cn \
    --cc=chleroy@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox