mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiale Yao <yaojiale02@163.com>
To: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	linux-kernel@vger.kernel.org
Cc: Jiale Yao <yaojiale02@163.com>
Subject: [PATCH] x86/boot: validate SRAT subtables before parsing
Date: Fri, 16 Oct 2026 22:14:24 +0800	[thread overview]
Message-ID: <20261016141424.2793636-1-yaojiale02@163.com> (raw)

The compressed boot SRAT walker only rejects zero-length subtables. It
can advance beyond the table or read memory-affinity fields from a
truncated record when firmware supplies an invalid length.

Validate the SRAT header, each generic subtable range, and the fixed
memory-affinity record before accessing typed fields.

Signed-off-by: Jiale Yao <yaojiale02@163.com>
---
 arch/x86/boot/compressed/acpi.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/arch/x86/boot/compressed/acpi.c b/arch/x86/boot/compressed/acpi.c
index aed27604c11f..310ddb9243b8 100644
--- a/arch/x86/boot/compressed/acpi.c
+++ b/arch/x86/boot/compressed/acpi.c
@@ -289,14 +289,22 @@ int count_immovable_mem_regions(void)
 		return 0;
 
 	table_header = (struct acpi_table_header *)table_addr;
+	if (table_header->length < sizeof(struct acpi_table_srat))
+		return 0;
+
 	table_end = table_addr + table_header->length;
 	table = table_addr + sizeof(struct acpi_table_srat);
 
-	while (table + sizeof(struct acpi_subtable_header) < table_end) {
+	while (table < table_end) {
+		if (table_end - table < sizeof(struct acpi_subtable_header)) {
+			debug_putstr("Invalid truncated SRAT subtable header.\n");
+			return 0;
+		}
 
 		sub_table = (struct acpi_subtable_header *)table;
-		if (!sub_table->length) {
-			debug_putstr("Invalid zero length SRAT subtable.\n");
+		if (sub_table->length < sizeof(*sub_table) ||
+		    sub_table->length > table_end - table) {
+			debug_putstr("Invalid SRAT subtable length.\n");
 			return 0;
 		}
 
@@ -304,6 +312,11 @@ int count_immovable_mem_regions(void)
 			struct acpi_srat_mem_affinity *ma;
 
 			ma = (struct acpi_srat_mem_affinity *)sub_table;
+			if (sub_table->length < sizeof(*ma)) {
+				debug_putstr("Invalid memory affinity subtable.\n");
+				return 0;
+			}
+
 			if (!(ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) && ma->length) {
 				immovable_mem[num].start = ma->base_address;
 				immovable_mem[num].size = ma->length;
-- 
2.34.1


             reply	other threads:[~2026-10-16 14:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16 14:14 Jiale Yao [this message]
2026-10-17  7:33 ` jiale yao

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=20261016141424.2793636-1-yaojiale02@163.com \
    --to=yaojiale02@163.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®