* [PATCH v2] selftests/bpf: Fix kallsyms parsing with long Rust symbols
@ 2026-11-25 11:03 Ricardo B. Marlière (SUSE)
2026-11-26 21:00 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Ricardo B. Marlière (SUSE) @ 2026-11-25 11:03 UTC (permalink / raw)
To: Andrii Nakryiko, Eduard Zingerman, Ihor Solodrai,
Alexei Starovoitov, Daniel Borkmann, Kumar Kartikeya Dwivedi,
Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
Emil Tsalapatis, Shuah Khan, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan
Cc: bpf, linux-kselftest, linux-kernel, rust-for-linux,
Ricardo B. Marlière (SUSE),
Alexei Starovoitov
load_kallsyms_local_common() reads /proc/kallsyms with a 256-byte line
buffer and stops parsing at the first line sscanf() cannot handle. Since
commit b8a94bfb3395 ("kallsyms: increase maximum kernel symbol length to
512"), symbols may be up to 511 characters, and on CONFIG_RUST=y kernels
some mangled Rust symbols (e.g. drm_panic_qr helpers) overflow the buffer.
fgets() splits such a line, the remainder fails to parse and every symbol
after it is silently dropped.
As a result ksym_get_addr() returns 0 for symbols like bpf_fentry_test1 and
bpf_testmod_*, address lookups resolve to the last loaded symbol, and
bpf_get_ksyms() fails with -EINVAL. This breaks bpf_cookie, fill_link_info,
kprobe_multi_test, kprobe_multi_testmod_test, kprobe_multi_bench_attach,
tracing_multi_bench_attach and stacktrace_ips.
Parse the file with fscanf() instead, bounding the symbol name to
KSYM_NAME_LEN and discarding the rest of the line, as kallsyms_find()
already does.
Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Signed-off-by: Ricardo B. Marlière (SUSE) <ricardo@marliere.net>
---
Changes in v2:
- Took Alexei's suggestion to drop buf and use fscanf() directly
- Link to v1: https://patch.msgid.link/20261124-selftests-bpf-rust_sym-v1-1-32c450d0c4ee@marliere.net
---
tools/testing/selftests/bpf/trace_helpers.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c
index 6d7a4b8c4ab8..5f558280856f 100644
--- a/tools/testing/selftests/bpf/trace_helpers.c
+++ b/tools/testing/selftests/bpf/trace_helpers.c
@@ -64,7 +64,7 @@ void free_kallsyms_local(struct ksyms *ksyms)
static struct ksyms *load_kallsyms_local_common(ksym_cmp_t cmp_cb)
{
FILE *f;
- char func[256], buf[256];
+ char func[512];
char symbol;
void *addr;
int ret;
@@ -80,9 +80,7 @@ static struct ksyms *load_kallsyms_local_common(ksym_cmp_t cmp_cb)
return NULL;
}
- while (fgets(buf, sizeof(buf), f)) {
- if (sscanf(buf, "%p %c %s", &addr, &symbol, func) != 3)
- break;
+ while (fscanf(f, "%p %c %511s%*[^\n]\n", &addr, &symbol, func) == 3) {
if (!addr)
continue;
---
base-commit: 81c6c8c608b6075846d3bd5b6f57958300a56eda
change-id: 20261124-selftests-bpf-rust_sym-e9b50bb2a39a
Best regards,
--
Ricardo B. Marlière (SUSE) <ricardo@marliere.net>
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] selftests/bpf: Fix kallsyms parsing with long Rust symbols
2026-11-25 11:03 [PATCH v2] selftests/bpf: Fix kallsyms parsing with long Rust symbols Ricardo B. Marlière (SUSE)
@ 2026-11-26 21:00 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-11-26 21:00 UTC (permalink / raw)
To: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re_=28SUSE=29_=3Cricardo=40marliere=2Enet?=,
=?utf-8?q?=3E?=
Cc: andrii, eddyz87, ihor.solodrai, ast, daniel, memxor, martin.lau,
song, yonghong.song, jolsa, emil, shuah, ojeda, boqun, gary,
bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, dakr,
daniel.almeida, tamird, acourbot, work, bpf, linux-kselftest,
linux-kernel, rust-for-linux
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Wed, 25 Nov 2026 08:03:18 -0300 you wrote:
> load_kallsyms_local_common() reads /proc/kallsyms with a 256-byte line
> buffer and stops parsing at the first line sscanf() cannot handle. Since
> commit b8a94bfb3395 ("kallsyms: increase maximum kernel symbol length to
> 512"), symbols may be up to 511 characters, and on CONFIG_RUST=y kernels
> some mangled Rust symbols (e.g. drm_panic_qr helpers) overflow the buffer.
> fgets() splits such a line, the remainder fails to parse and every symbol
> after it is silently dropped.
>
> [...]
Here is the summary with links:
- [v2] selftests/bpf: Fix kallsyms parsing with long Rust symbols
https://git.kernel.org/bpf/bpf-next/c/dc0049f3860a
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-26 21:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 11:03 [PATCH v2] selftests/bpf: Fix kallsyms parsing with long Rust symbols Ricardo B. Marlière (SUSE)
2026-11-26 21:00 ` patchwork-bot+netdevbpf
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®