BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/2] libbpf: Skip host /proc/kallsyms for typeless ksyms in gen_loader
@ 2026-12-02 21:21 Thiébaud Weksteen
  2026-12-02 21:21 ` [PATCH bpf-next v2 1/2] libbpf: Skip reading " Thiébaud Weksteen
  2026-12-02 21:21 ` [PATCH bpf-next v2 2/2] selftests/bpf: Test missing strong typeless ksym in light skeleton Thiébaud Weksteen
  0 siblings, 2 replies; 4+ messages in thread
From: Thiébaud Weksteen @ 2026-12-02 21:21 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Shuah Khan,
	Siddharth Nayyar
  Cc: Thiébaud Weksteen, bpf, linux-kselftest, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai

When generating a light skeleton / loader program via
bpf_object__gen_loader(), libbpf is supposed to defer kernel symbol
resolution to the target kernel at load time rather than consulting the
build host. Typed ksyms and kfuncs already short-circuit on
obj->gen_loader in bpf_object__resolve_ksyms_btf_id(), but
bpf_object__resolve_externs() still reads the build host's
/proc/kallsyms for typeless ksyms.

This breaks offline loader generation in sandboxed environments, rejects
strong typeless ksyms that exist only on the target kernel, and leaks
host symbol addresses into the generated loader data blob even though
emit_relo_ksym_typeless() overwrites them at load time via
bpf_kallsyms_lookup_name().

Patch 1 short-circuits all EXT_KSYM entries in
bpf_object__resolve_externs() when obj->gen_loader is set (dropping the
now redundant obj->gen_loader check in
bpf_object__resolve_ksyms_btf_id()), and makes emit_relo_ksym_typeless()
ignore -ENOENT only for weak ksyms so missing strong typeless ksyms
still fail at load time on the target kernel.

Patch 2 adds a test_ksyms_strong_typeless light skeleton and
ksyms_btf/strong_typeless_lskel selftest verifying that light skeleton
generation succeeds for a missing strong typeless ksym and loading it
fails with -ENOENT on the target kernel.

Changes in v2:
 - Patch 1: Short-circuit all EXT_KSYM entries directly in
   bpf_object__resolve_externs() (removing the redundant check in
   bpf_object__resolve_ksyms_btf_id() and avoiding renaming
   bpf_object__read_kallsyms_file()), per Alexei's suggestion.
 - Patch 1: Drop the Fixes: tag.

Thiébaud Weksteen (2):
  libbpf: Skip reading /proc/kallsyms for typeless ksyms in gen_loader
  selftests/bpf: Test missing strong typeless ksym in light skeleton

 tools/lib/bpf/gen_loader.c                    |  6 ++++--
 tools/lib/bpf/libbpf.c                        | 11 ++++-------
 tools/testing/selftests/bpf/Makefile.skel     |  3 ++-
 .../selftests/bpf/prog_tests/ksyms_btf.c      | 19 +++++++++++++++++++
 .../bpf/progs/test_ksyms_strong_typeless.c    | 16 ++++++++++++++++
 5 files changed, 45 insertions(+), 10 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/test_ksyms_strong_typeless.c


base-commit: ac69c149f965b55e85798e516cb66e2bceb63f00
-- 
2.56.1.987.g2ec0ab4260-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-02 21:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 21:21 [PATCH bpf-next v2 0/2] libbpf: Skip host /proc/kallsyms for typeless ksyms in gen_loader Thiébaud Weksteen
2026-12-02 21:21 ` [PATCH bpf-next v2 1/2] libbpf: Skip reading " Thiébaud Weksteen
2026-12-02 21:56   ` bot+bpf-ci
2026-12-02 21:21 ` [PATCH bpf-next v2 2/2] selftests/bpf: Test missing strong typeless ksym in light skeleton Thiébaud Weksteen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox