From: Leizhen Zhang <lzsx618@gmail.com>
To: nathan@kernel.org, nsc@kernel.org
Cc: masahiroy@kernel.org, ardb@kernel.org, rostedt@goodmis.org,
hpa@zytor.com, linux-kbuild@vger.kernel.org,
linux-kernel@vger.kernel.org, Leizhen Zhang <lzsx618@gmail.com>
Subject: [PATCH v3 0/6] kbuild: fix UB hit by normal builds in host tools
Date: Mon, 9 Nov 2026 17:59:57 -0600 [thread overview]
Message-ID: <20261110000003.1719966-1-lzsx618@gmail.com> (raw)
This is v3 of the host tool fixes. The main change is what is left in
it: following the feedback on my elf-parse series, I went back over
every patch and kept only the ones a normal build or valid source can
trigger. Each of the six below was re-checked on mainline as of
b23545529c21 (the rc1 rebase changed no code) by doing a plain x86_64
defconfig build (MODVERSIONS and MODULE_SRCVERSION_ALL enabled, 12
modules) with the host tools built with sanitizers, and then rerunning
the same step with the patch applied:
1/6 genksyms 'int a, f(int);' is valid C and makes genksyms loop
forever; 'int a; int f(int);' is fine.
2/6 kallsyms link-vmlinux.sh hands kallsyms an empty .syms file on
every build (the .tmp_vmlinux0 pass), and both qsort()
calls then get a NULL table. 2 UBSan reports -> 0, the
generated tables are byte-identical.
3/6 modpost read_text_file() rereads into the start of the buffer
after a short read. Not something a local filesystem
does in practice; shown with an LD_PRELOAD shim that
caps read() at 64 bytes, under which modpost rejects a
valid Module.symvers.
4/6 modpost parse_source_files() does arithmetic on the NULL that
strstr() returns for dependencies outside the module's
directory. Reported on the build's own modpost
invocation; Module.symvers is identical with the fix.
5/6 sorttable the sort_needed address is computed by adding a kernel
virtual address to a host pointer first. Reported on
the real vmlinux.
6/6 tools __get_unaligned_le32() shifts a byte >= 0x80 into the
sign bit. Hit 4 times during the defconfig link, by
sorttable.
The 4/6 and 5/6 reports need clang's -fsanitize=undefined; GCC 12 does
not instrument those two pointer-arithmetic cases, so they are silent
with a GCC host build.
The 2/6 and 6/6 reports reproduce unchanged on v7.4-rc2 (GCC host
build, same config).
Changes in v3:
- Rebased onto v7.4-rc1. No code changes in the patches that remain.
- Dropped "fixdep: fix out-of-bounds read on a comment ending with a
backslash": it needs a hand-written .d file; the compiler never
produces one.
- Dropped "modpost: fix stack out-of-bounds read for unterminated PNP
ids": all 699 PNP ids in the tree are 7 characters, and the overflow
needs an 8-character one, which is not a well-formed PNP id.
- Replaced the Assisted-by trailers, which checkpatch no longer
accepts, with a sentence in each changelog saying how the problem was
found and that an AI coding assistant helped prepare the fix.
v2: https://lore.kernel.org/r/20261008164035.3668885-1-lzsx618@gmail.com
Leizhen Zhang (6):
genksyms: fix infinite loop on declarations with parameter lists
kallsyms: do not call qsort() with a NULL table
modpost: fix handling of short reads in read_text_file()
modpost: fix pointer arithmetic on NULL in parse_source_files()
sorttable: avoid pointer arithmetic overflow when locating sort_needed
tools/include: fix signed shift overflow in 32-bit unaligned accessors
scripts/genksyms/parse.y | 23 +++++++++++++++++++----
scripts/kallsyms.c | 6 ++++--
scripts/mod/modpost.c | 6 +++++-
scripts/mod/sumversion.c | 3 ++-
scripts/sorttable.c | 2 +-
tools/include/tools/be_byteshift.h | 2 +-
tools/include/tools/le_byteshift.h | 2 +-
7 files changed, 33 insertions(+), 11 deletions(-)
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
--
2.34.1
next reply other threads:[~2026-11-10 0:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 23:59 Leizhen Zhang [this message]
2026-11-09 23:59 ` [PATCH v3 1/6] genksyms: fix infinite loop on declarations with parameter lists Leizhen Zhang
2026-11-09 23:59 ` [PATCH v3 2/6] kallsyms: do not call qsort() with a NULL table Leizhen Zhang
2026-11-10 0:00 ` [PATCH v3 3/6] modpost: fix handling of short reads in read_text_file() Leizhen Zhang
2026-11-10 0:00 ` [PATCH v3 4/6] modpost: fix pointer arithmetic on NULL in parse_source_files() Leizhen Zhang
2026-11-10 0:00 ` [PATCH v3 5/6] sorttable: avoid pointer arithmetic overflow when locating sort_needed Leizhen Zhang
2026-11-10 0:00 ` [PATCH v3 6/6] 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=20261110000003.1719966-1-lzsx618@gmail.com \
--to=lzsx618@gmail.com \
--cc=ardb@kernel.org \
--cc=hpa@zytor.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masahiroy@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®