From: sashiko-bot@kernel.org
To: "Pengpeng Hou" <pengpeng@iscas.ac.cn>
Cc: nvdimm@lists.linux.dev
Subject: Re: [PATCH v2 1/5] ACPI: NFIT: validate subtable extents before dispatch
Date: Thu, 13 Aug 2026 15:41:54 +0000 [thread overview]
Message-ID: <20260813154155.4C5271F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260813151111.18434-1-pengpeng@iscas.ac.cn>
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
Pre-existing issues:
- [High] sizeof_spa() accesses spa->flags before validating the subtable length, causing an out-of-bounds read.
- [High] add_platform_cap() reads capability fields without verifying the subtable length, causing an out-of-bounds read.
- [High] Early termination in acpi_nfit_init() leaves internal device lists stranded on the stack, corrupting the device state and leaking resources.
- [High] sizeof_idt() calculates a size that can exceed the verified subtable length, causing an out-of-bounds read in add_idt().
- [High] sizeof_dcr() can return a size exceeding the verified subtable length when dcr->windows is set, causing an out-of-bounds read.
- [Medium] Bitwise shift operation in add_platform_cap() can cause undefined behavior if highest_capability >= 31.
--
--- Patch [1]: [PATCH v2 1/5] ACPI: NFIT: validate subtable extents before dispatch ---
commit 7124d3c49e2df0b214c3037c798664d5e4c0f3d3
Author: Pengpeng Hou <pengpeng@iscas.ac.cn>
ACPI: NFIT: validate subtable extents before dispatch
This commit strengthens NFIT table parsing by requiring a complete header and
validating that the advertised subtable length fits within the remaining bytes
in the NFIT before dispatching it.
> diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
> --- a/drivers/acpi/nfit/core.c
> +++ b/drivers/acpi/nfit/core.c
> @@ -963,14 +963,18 @@ static void *add_table(struct acpi_nfit_desc *acpi_desc,
> struct device *dev = acpi_desc->dev;
> struct acpi_nfit_header *hdr;
> void *err = ERR_PTR(-ENOMEM);
> + size_t table_len;
>
> if (table >= end)
> return NULL;
> + table_len = end - table;
> + if (table_len < sizeof(*hdr))
> + return NULL;
>
[Severity: High]
This isn't a bug introduced by this patch, but returning NULL here can cause
device state corruption during runtime updates.
If add_table() returns NULL early while parsing an ACPI update in
acpi_nfit_init(), the function jumps to out_unlock:
drivers/acpi/nfit/core.c:acpi_nfit_init() {
...
goto out_unlock;
...
}
At that point, it exits without restoring nodes from the stack list prev back
to acpi_desc, which permanently empties the device's operational lists.
Does acpi_nfit_init() need to be updated to handle this early return safely?
> hdr = table;
> - if (!hdr->length) {
> - dev_warn(dev, "found a zero length table '%d' parsing nfit\n",
> - hdr->type);
> + if (hdr->length < sizeof(*hdr) || hdr->length > table_len) {
> + dev_warn(dev, "invalid table length %u for type %u parsing nfit\n",
> + hdr->length, hdr->type);
> return NULL;
> }
[Severity: High]
This is a pre-existing issue, but while we are strengthening generic table
length checks here, does sizeof_spa() also need bounds checking?
If a malformed table provides a System Physical Address (SPA) subtable with a
length of 4 or 5, add_table() will accept it because hdr->length >= 4. However,
sizeof_spa() in drivers/acpi/nfit/core.c reads spa->flags before verifying the
subtable length is at least 8 bytes:
drivers/acpi/nfit/core.c:sizeof_spa() {
if (spa->flags & ACPI_NFIT_LOCATION_COOKIE_VALID)
...
}
Can this lead to an out-of-bounds read if the table length is too small?
[Severity: High]
This is a pre-existing issue, but does add_platform_cap() similarly need
length validation?
A capabilities subtable might pass the generic length check here, but
add_platform_cap() in drivers/acpi/nfit/core.c reads capabilities without
verifying the subtable length is at least 16 bytes:
drivers/acpi/nfit/core.c:add_platform_cap() {
mask = (1 << (pcap->highest_capability + 1)) - 1;
acpi_desc->platform_cap = pcap->capabilities & mask;
}
Could this result in an out-of-bounds read?
[Severity: Medium]
This is also a pre-existing issue, but in the same code snippet above, if
highest_capability is 31 or greater, would the bitwise shift:
drivers/acpi/nfit/core.c:add_platform_cap() {
mask = (1 << (pcap->highest_capability + 1)) - 1;
}
invoke undefined behavior by shifting a 32-bit signed integer by 32 or more?
[Severity: High]
This is a pre-existing issue, but does sizeof_idt() also need length bounds
checking to prevent out-of-bounds reads?
If a malformed table has a small hdr->length but a large line_count,
sizeof_idt() in drivers/acpi/nfit/core.c calculates a required size ignoring
hdr->length:
drivers/acpi/nfit/core.c:sizeof_idt() {
return sizeof(*idt) + sizeof(u32) * idt->line_count;
}
Then add_idt() passes this unvalidated size to memcpy:
drivers/acpi/nfit/core.c:add_idt() {
memcpy(nfit_idt->idt, idt, sizeof_idt(idt));
}
Could this copy past the mapped ACPI table boundary?
[Severity: High]
This is a pre-existing issue, but could sizeof_dcr() return a size exceeding
the verified subtable length?
If dcr->windows is set, sizeof_dcr() in drivers/acpi/nfit/core.c blindly
returns 80 bytes:
drivers/acpi/nfit/core.c:sizeof_dcr() {
if (dcr->windows)
return sizeof(*dcr);
}
Then add_dcr() copies the memory:
drivers/acpi/nfit/core.c:add_dcr() {
memcpy(nfit_dcr->dcr, dcr, sizeof_dcr(dcr));
}
If the firmware provided less than 80 bytes for the control region table, does
this cause an out-of-bounds read?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260813150948.17239-1-pengpeng@iscas.ac.cn?part=1
next prev parent reply other threads:[~2026-08-13 15:41 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 15:09 [PATCH v2 0/5] ACPI: NFIT: harden subtable extent validation Pengpeng Hou
2026-08-13 15:11 ` [PATCH v2 1/5] ACPI: NFIT: validate subtable extents before dispatch Pengpeng Hou
2026-08-13 15:41 ` sashiko-bot [this message]
2026-08-13 15:13 ` [PATCH v2 2/5] ACPI: NFIT: accept SPA structures with an unused location cookie Pengpeng Hou
2026-08-13 15:35 ` sashiko-bot
2026-08-13 15:16 ` [PATCH v2 3/5] ACPI: NFIT: validate interleave and flush array extents Pengpeng Hou
2026-08-13 15:38 ` sashiko-bot
2026-08-13 15:18 ` [PATCH v2 4/5] ACPI: NFIT: validate control region extent Pengpeng Hou
2026-08-13 15:38 ` sashiko-bot
2026-08-13 15:20 ` [PATCH v2 5/5] ACPI: NFIT: bound the platform capability mask Pengpeng Hou
2026-08-13 15:33 ` sashiko-bot
2026-08-13 22:51 ` [PATCH v2 0/5] ACPI: NFIT: harden subtable extent validation Alison Schofield
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=20260813154155.4C5271F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=nvdimm@lists.linux.dev \
--cc=pengpeng@iscas.ac.cn \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.