From: "jiale yao" <19888972804@163.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
"Len Brown" <lenb@kernel.org>,
linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re:[PATCH] ACPI: processor: validate CPU mapping entries
Date: Sat, 17 Oct 2026 15:33:39 +0800 (CST) [thread overview]
Message-ID: <7192d240.1879.1a148c7d925.Coremail.19888972804@163.com> (raw)
In-Reply-To: <20261016141440.2794000-1-yaojiale02@163.com>
At 2026-10-16 22:14:40, "Jiale Yao" <yaojiale02@163.com> wrote:
>CPU physical ID lookup walks MADT subtables directly and also accepts
>records returned by _MAT. Both paths can pass a truncated typed record
>to a CPU-specific mapper, and the MADT walker can be stalled or moved
>outside the table by an invalid length.
>
>Validate generic record bounds and the minimum size required by each
>supported CPU record before dispatching it on both provider paths.
>
Fixes: 78ed8bd2944b ("ACPI: processor: move acpi_get_cpuid into processor_core.c")
>Signed-off-by: Jiale Yao <yaojiale02@163.com>
>---
> drivers/acpi/processor_core.c | 48 ++++++++++++++++++++++++++++++++++-
> 1 file changed, 47 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
>index 3bf076c150fa..4d5ff53f27ab 100644
>--- a/drivers/acpi/processor_core.c
>+++ b/drivers/acpi/processor_core.c
>@@ -157,6 +157,47 @@ static int map_core_pic_id(struct acpi_subtable_header *entry,
> return -EINVAL;
> }
>
>+static bool madt_cpu_entry_is_valid(struct acpi_subtable_header *entry,
>+ unsigned long end)
>+{
>+ unsigned long start = (unsigned long)entry;
>+ size_t length, min_length;
>+
>+ if (start >= end || end - start < sizeof(*entry))
>+ return false;
>+
>+ length = entry->length;
>+ if (length < sizeof(*entry) || length > end - start)
>+ return false;
>+
>+ switch (entry->type) {
>+ case ACPI_MADT_TYPE_LOCAL_APIC:
>+ min_length = sizeof(struct acpi_madt_local_apic);
>+ break;
>+ case ACPI_MADT_TYPE_LOCAL_X2APIC:
>+ min_length = sizeof(struct acpi_madt_local_x2apic);
>+ break;
>+ case ACPI_MADT_TYPE_LOCAL_SAPIC:
>+ min_length = sizeof(struct acpi_madt_local_sapic);
>+ break;
>+ case ACPI_MADT_TYPE_GENERIC_INTERRUPT:
>+ min_length = offsetofend(struct acpi_madt_generic_interrupt,
>+ arm_mpidr);
>+ break;
>+ case ACPI_MADT_TYPE_RINTC:
>+ min_length = offsetofend(struct acpi_madt_rintc, uid);
>+ break;
>+ case ACPI_MADT_TYPE_CORE_PIC:
>+ min_length = sizeof(struct acpi_madt_core_pic);
>+ break;
>+ default:
>+ min_length = sizeof(*entry);
>+ break;
>+ }
>+
>+ return length >= min_length;
>+}
>+
> static phys_cpuid_t map_madt_entry(struct acpi_table_madt *madt,
> int type, u32 acpi_id)
> {
>@@ -172,7 +213,8 @@ static phys_cpuid_t map_madt_entry(struct acpi_table_madt *madt,
> /* Parse all entries looking for a match. */
>
> entry += sizeof(struct acpi_table_madt);
>- while (entry + sizeof(struct acpi_subtable_header) < madt_end) {
>+ while (madt_cpu_entry_is_valid((struct acpi_subtable_header *)entry,
>+ madt_end)) {
> struct acpi_subtable_header *header =
> (struct acpi_subtable_header *)entry;
> if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
>@@ -251,6 +293,10 @@ static phys_cpuid_t map_mat_entry(acpi_handle handle, int type, u32 acpi_id)
> }
>
> header = (struct acpi_subtable_header *)obj->buffer.pointer;
>+ if (!madt_cpu_entry_is_valid(header,
>+ (unsigned long)header + obj->buffer.length))
>+ goto exit;
>+
> if (header->type == ACPI_MADT_TYPE_LOCAL_APIC)
> map_lapic_id(header, acpi_id, &phys_id);
> else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC)
>--
>2.34.1
prev parent reply other threads:[~2026-10-17 7:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 14:14 [PATCH] " Jiale Yao
2026-10-17 7:33 ` jiale yao [this message]
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=7192d240.1879.1a148c7d925.Coremail.19888972804@163.com \
--to=19888972804@163.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@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®