All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf 0/2] libbpf: Reject out-of-range linker relocation offsets
@ 2026-06-14  5:39 HyeongJun An
  2026-06-14  5:39 ` [PATCH bpf 1/2] " HyeongJun An
  2026-06-14  5:39 ` [PATCH bpf 2/2] selftests/bpf: Test linker rejects out-of-range relocation offset HyeongJun An
  0 siblings, 2 replies; 5+ messages in thread
From: HyeongJun An @ 2026-06-14  5:39 UTC (permalink / raw)
  To: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann
  Cc: Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Shuah Khan, bpf,
	linux-kselftest, linux-kernel, HyeongJun An

The libbpf static linker validates relocation type, symbol index and
instruction alignment in linker_sanity_check_elf_relos(), but does not
check that the relocation offset is inside the relocated section.  A
malformed BPF object processed by the static linker (e.g. via
"bpftool gen object") can therefore carry an out-of-range r_offset that
linker_append_elf_relos() then uses to index the section data, reading
and writing past the buffer.

The normal object-loading path already rejects such offsets (libbpf.c,
rel->r_offset >= scn_data->d_size); the static linker path is the
missing sibling.  Patch 1 adds the same bound.  Patch 2 adds a selftest
that builds a tiny object with an out-of-range relocation offset and
checks that the linker now rejects it, with a valid relocation as a
positive control.

Reproduced with ASAN: before patch 1 the out-of-range relocation is
accepted (and triggers a heap-buffer-overflow); after, it is rejected
with -EINVAL.

HyeongJun An (2):
  libbpf: Reject out-of-range linker relocation offsets
  selftests/bpf: Test linker rejects out-of-range relocation offset

 tools/lib/bpf/linker.c                        |   6 +
 .../selftests/bpf/prog_tests/libbpf_linker.c  | 212 ++++++++++++++++++
 2 files changed, 218 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/libbpf_linker.c

-- 
2.43.0


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

end of thread, other threads:[~2026-06-14  7:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-14  5:39 [PATCH bpf 0/2] libbpf: Reject out-of-range linker relocation offsets HyeongJun An
2026-06-14  5:39 ` [PATCH bpf 1/2] " HyeongJun An
2026-06-14  7:50   ` sashiko-bot
2026-06-14  5:39 ` [PATCH bpf 2/2] selftests/bpf: Test linker rejects out-of-range relocation offset HyeongJun An
2026-06-14  5:53   ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.