BPF List
 help / color / mirror / Atom feed
From: "Thiébaud Weksteen" <tweek@google.com>
To: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	 Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	 Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Shuah Khan <shuah@kernel.org>,
	 Siddharth Nayyar <sidnayyar@google.com>
Cc: "Thiébaud Weksteen" <tweek@google.com>,
	bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	"Song Liu" <song@kernel.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"Ihor Solodrai" <ihor.solodrai@linux.dev>
Subject: [PATCH bpf-next v2 0/2] libbpf: Skip host /proc/kallsyms for typeless ksyms in gen_loader
Date: Thu,  3 Dec 2026 08:21:49 +1100	[thread overview]
Message-ID: <20261202212151.1288936-1-tweek@google.com> (raw)

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


             reply	other threads:[~2026-12-02 21:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 21:21 Thiébaud Weksteen [this message]
2026-12-02 21:21 ` [PATCH bpf-next v2 1/2] libbpf: Skip reading /proc/kallsyms for typeless ksyms in gen_loader 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

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=20261202212151.1288936-1-tweek@google.com \
    --to=tweek@google.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=jolsa@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=shuah@kernel.org \
    --cc=sidnayyar@google.com \
    --cc=song@kernel.org \
    --cc=yonghong.song@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