From: sashiko-bot@kernel.org
To: "Sasha Levin" <sashal@kernel.org>
Cc: linux-modules@vger.kernel.org
Subject: Re: [PATCH v8 4/4] kallsyms: add KUnit tests for lineinfo feature
Date: Sat, 01 Aug 2026 14:45:53 +0000 [thread overview]
Message-ID: <20260801144553.817111F00AC4@smtp.kernel.org> (raw)
In-Reply-To: <20260801143219.3975824-5-sashal@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Medium] The KUnit test `test_sprint_symbol_format` unconditionally fails because it mistakenly expects `+0x` for a zero offset.
Pre-existing issues:
- [High] kallsyms_lookup_buildid() can return negative error codes like -E2BIG, leading to a stack buffer underflow in __sprint_symbol().
--
--- Patch [4]: [PATCH v8 4/4] kallsyms: add KUnit tests for lineinfo feature ---
commit 337c29ff08b7b23d898a00240203617a93c2c906
Author: Sasha Levin <sashal@kernel.org>
kallsyms: add KUnit tests for lineinfo feature
Add a KUnit test module (CONFIG_LINEINFO_KUNIT_TEST) that verifies the
kallsyms lineinfo feature produces correct source file:line annotations
in stack traces.
> diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
> index b5eff2ba8e5d7..b0475f1e7f791 100644
> --- a/kernel/kallsyms.c
> +++ b/kernel/kallsyms.c
[Severity: High]
This is a pre-existing issue, but could this lead to a stack buffer underflow?
In kernel/kallsyms.c:__sprint_symbol():
len = kallsyms_lookup_buildid(address, &size, &offset, &modname, &buildid,
buffer);
if (!len)
return sprintf(buffer, "0x%lx", address - symbol_offset);
...
if (add_offset)
len += sprintf(buffer + len, "+%#lx/%#lx", offset, size);
If a loadable module or BPF program contains a symbol name that exceeds
KSYM_NAME_LEN, functions like module_address_lookup() return -E2BIG (-7).
This negative value propagates up through kallsyms_lookup_buildid() and
bypasses the 'if (!len)' check.
Would 'buffer + len' then point before the allocated buffer, causing an
out-of-bounds write during the subsequent sprintf?
[ ... ]
> diff --git a/lib/tests/lineinfo_kunit.c b/lib/tests/lineinfo_kunit.c
> new file mode 100644
> index 0000000000000..2e66e8ebb3124
> --- /dev/null
> +++ b/lib/tests/lineinfo_kunit.c
> @@ -0,0 +1,1040 @@
[ ... ]
> +static void test_sprint_symbol_format(struct kunit *test)
> +{
> + char *buf = alloc_sym_buf(test);
> + unsigned long addr = target_addr(lineinfo_target_normal);
> +
> + sprint_symbol(buf, addr);
> +
> + /* Should contain +0x and /0x for offset/size */
> + KUNIT_EXPECT_NOT_NULL_MSG(test, strstr(buf, "+0x"),
> + "Missing offset in: %s", buf);
[Severity: Medium]
Will this assertion fail unconditionally due to standard C formatting rules?
Since test_sprint_symbol_format() passes the exact start address of
lineinfo_target_normal, the resulting offset is 0.
When __sprint_symbol() formats a zero offset using '+%#lx/%#lx', the '%#lx'
specifier omits the '0x' prefix for a zero value, resulting in '+0/' instead
of '+0x0/'.
Does this cause strstr(buf, "+0x") to always return NULL and break the test?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260801143219.3975824-1-sashal@kernel.org?part=4
prev parent reply other threads:[~2026-08-01 14:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-01 14:32 [PATCH v8 0/4] kallsyms: embed source file:line info in kernel stack traces Sasha Levin
2026-08-01 14:32 ` [PATCH v8 1/4] " Sasha Levin
2026-08-01 14:45 ` sashiko-bot
2026-08-01 14:32 ` [PATCH v8 2/4] kallsyms: extend lineinfo to loadable modules Sasha Levin
2026-08-01 14:42 ` sashiko-bot
2026-08-01 14:32 ` [PATCH v8 3/4] kallsyms: delta-compress lineinfo tables for ~2.7x size reduction Sasha Levin
2026-08-01 14:39 ` sashiko-bot
2026-08-01 14:32 ` [PATCH v8 4/4] kallsyms: add KUnit tests for lineinfo feature Sasha Levin
2026-08-01 14:45 ` sashiko-bot [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=20260801144553.817111F00AC4@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=sashal@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox