From: Leizhen Zhang <lzsx618@gmail.com>
To: nathan@kernel.org, nsc@kernel.org
Cc: rostedt@goodmis.org, linux-kbuild@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 4/8] modpost: fix stack out-of-bounds read for unterminated PNP ids
Date: Thu, 8 Oct 2026 11:40:31 -0500 [thread overview]
Message-ID: <20261008164035.3668885-5-lzsx618@gmail.com> (raw)
In-Reply-To: <20261008164035.3668885-1-lzsx618@gmail.com>
do_pnp_device_entry() and do_pnp_card_entry() copy the PNP id into a
local acpi_id[PNP_ID_LEN] buffer to upper-case it, and then print it with
"%s". A PNP id that uses all PNP_ID_LEN characters, e.g. "PNP0C0F1", is
accepted by the compiler without a terminating NUL (the kernel is built
with -Wno-unterminated-string-initialization), so the local copy is not
NUL-terminated and printing it reads past the end of the stack buffer:
AddressSanitizer: stack-buffer-overflow ... in printf_common
... do_pnp_device_entry scripts/mod/file2alias.c
Limit the printed length to the size of the id buffers.
Found by fuzzing modpost with ASan/UBSan.
Fixes: 72638f598ec9 ("PNP: fix broken pnp lowercasing for acpi module aliases")
Assisted-by: Claude:claude-opus-5-5 ASan UBSan
Signed-off-by: Leizhen Zhang <lzsx618@gmail.com>
---
v2:
- Use my real name in the From and Signed-off-by lines. No code
changes.
v1: https://lore.kernel.org/r/20261005104050.1786222-6-lzsx618@gmail.com
scripts/mod/file2alias.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 61a831c187..7685fb5135 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -573,8 +573,9 @@ static void do_pnp_device_entry(struct module *mod, void *symval)
/* fix broken pnp bus lowercasing */
for (unsigned int i = 0; i < sizeof(acpi_id); i++)
acpi_id[i] = toupper((*id)[i]);
- module_alias_printf(mod, false, "pnp:d%s*", *id);
- module_alias_printf(mod, false, "acpi*:%s:*", acpi_id);
+ module_alias_printf(mod, false, "pnp:d%.*s*", (int)sizeof(*id), *id);
+ module_alias_printf(mod, false, "acpi*:%.*s:*",
+ (int)sizeof(acpi_id), acpi_id);
}
/* looks like: "pnp:dD" for every device of the card */
@@ -594,8 +595,9 @@ static void do_pnp_card_entry(struct module *mod, void *symval)
acpi_id[j] = toupper(id[j]);
/* add an individual alias for every device entry */
- module_alias_printf(mod, false, "pnp:d%s*", id);
- module_alias_printf(mod, false, "acpi*:%s:*", acpi_id);
+ module_alias_printf(mod, false, "pnp:d%.*s*", PNP_ID_LEN, id);
+ module_alias_printf(mod, false, "acpi*:%.*s:*",
+ PNP_ID_LEN, acpi_id);
}
}
--
2.34.1
next prev parent reply other threads:[~2026-10-08 16:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 16:40 [PATCH v2 0/8] kbuild: fix memory safety and UB bugs in host tools found by fuzzing Leizhen Zhang
2026-10-08 16:40 ` [PATCH v2 1/8] genksyms: fix infinite loop on declarations with parameter lists Leizhen Zhang
2026-10-08 16:40 ` [PATCH v2 2/8] fixdep: fix out-of-bounds read on a comment ending with a backslash Leizhen Zhang
2026-10-08 16:40 ` [PATCH v2 3/8] kallsyms: do not call qsort() with a NULL table Leizhen Zhang
2026-10-08 16:40 ` Leizhen Zhang [this message]
2026-10-08 16:40 ` [PATCH v2 5/8] modpost: fix handling of short reads in read_text_file() Leizhen Zhang
2026-10-08 16:40 ` [PATCH v2 6/8] modpost: fix pointer arithmetic on NULL in parse_source_files() Leizhen Zhang
2026-10-08 16:40 ` [PATCH v2 7/8] sorttable: avoid pointer arithmetic overflow when locating sort_needed Leizhen Zhang
2026-10-08 16:40 ` [PATCH v2 8/8] tools/include: fix signed shift overflow in 32-bit unaligned accessors Leizhen Zhang
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=20261008164035.3668885-5-lzsx618@gmail.com \
--to=lzsx618@gmail.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=nsc@kernel.org \
--cc=rostedt@goodmis.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®