linux/tools/lib/bpf
Kumar Kartikeya Dwivedi b4e875d397 libbpf: Reject truncated ldimm64 CO-RE relocations
CO-RE relocation of an ldimm64 instruction operates on two instruction
slots. A malformed BPF ELF can end a function after the first slot and
attach a CO-RE relocation to it. libbpf allocates the instruction array
according to the function symbol size, so the shared relocation code would
then access beyond the allocation.

Reject a terminal ldimm64 in libbpf's relocation loop, where the program
length is available, before resolving or applying the relocation. Both
resolved and unresolved relocations validate the absent second slot, and
unresolved relocation poisoning would additionally write past the array.

The in-kernel caller is protected by the verifier's early instruction-stream
check before it applies CO-RE relocations.

Fixes: eacaaed784 ("libbpf: Implement enum value-based CO-RE relocations")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/20260914140852.03DA21F0089B@smtp.kernel.org
Link: https://patch.msgid.link/20260917233222.2542500-11-memxor@gmail.com
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
2026-09-17 18:01:43 -07:00
..
.gitignore tools build: Correct bpf fixdep dependencies 2024-08-05 12:19:48 -03:00
bpf_core_read.h bpf: Fix uninitialized values in BPF_{CORE,PROBE}_READ 2025-05-05 14:20:28 -07:00
bpf_endian.h
bpf_gen_internal.h libbpf: Add support for global percpu data 2026-08-13 10:27:40 -07:00
bpf_helpers.h libbpf: Remove extern declaration of bpf_stream_vprintk() 2026-02-18 14:58:47 -08:00
bpf_prog_linfo.c libbpf: Streamline error reporting for high-level APIs 2021-05-25 17:32:35 -07:00
bpf_tracing.h libbpf: Fix powerpc's stack register definition in bpf_tracing.h 2025-10-23 11:25:16 -07:00
bpf.c libbpf: Add path_fd to struct bpf_link_create_opts 2026-06-14 17:24:25 -07:00
bpf.h libbpf: Add path_fd to struct bpf_link_create_opts 2026-06-14 17:24:25 -07:00
btf_dump.c libbpf: fix -Wformat warnings from format/argument type mismatches 2026-06-25 17:56:22 -07:00
btf_iter.c libbpf,bpf: Share BTF relocate-related code with kernel 2024-06-21 14:45:07 -07:00
btf_relocate.c libbpf: fix -Wformat warnings from format/argument type mismatches 2026-06-25 17:56:22 -07:00
btf.c libbpf: Fix double-free of distilled base BTF on .BTF.ext parse error 2026-07-10 14:53:29 -07:00
btf.h libbpf: Export btf__find_by_name_kind_own() 2026-07-30 12:48:08 -07:00
Build libbpf: move libbpf_errstr() into libbpf_utils.c 2025-10-01 15:27:25 -07:00
elf.c libbpf: fix -Wformat warnings from format/argument type mismatches 2026-06-25 17:56:22 -07:00
features.c Major changes: 2026-08-20 07:36:20 -07:00
gen_loader.c libbpf: Add support for global percpu data 2026-08-13 10:27:40 -07:00
hashmap.c libbpf: Hashmap interface update to allow both long and void* keys/values 2022-11-09 20:45:14 -08:00
hashmap.h libbpf: Fix possible compiler warnings in hashmap 2024-10-11 12:36:59 -07:00
libbpf_common.h libbpf: Fix potential uninitialized tail padding with LIBBPF_OPTS_RESET 2023-11-09 19:07:51 -08:00
libbpf_internal.h libbpf: Probe percpu data feature 2026-08-13 10:27:40 -07:00
libbpf_legacy.h libbpf: Fix some typos in comments 2024-09-09 16:05:40 -07:00
libbpf_probes.c libbpf: Support resizable hashtable 2026-06-05 08:00:08 -07:00
libbpf_utils.c libbpf: Fix undefined behavior in {get,put}_unaligned_be32() 2025-10-06 09:16:29 -07:00
libbpf_version.h libbpf: Start v1.8 development cycle 2026-03-16 14:15:15 -07:00
libbpf.c libbpf: Reject truncated ldimm64 CO-RE relocations 2026-09-17 18:01:43 -07:00
libbpf.h libbpf: Add support to create tracing multi link 2026-06-07 10:03:02 -07:00
libbpf.map libbpf: Export btf__find_by_name_kind_own() 2026-07-30 12:48:08 -07:00
libbpf.pc.template
linker.c libbpf: Fix invalid write loop logic in bpf_linker__add_buf() 2026-02-13 14:14:27 -08:00
Makefile tools/build: Allow versioning LLVM readelf 2026-07-25 22:25:00 -07:00
netlink.c bpftool: Fix truncated netlink dumps 2026-02-17 16:54:03 -08:00
nlattr.c libbpf: fix -Wformat warnings from format/argument type mismatches 2026-06-25 17:56:22 -07:00
nlattr.h libbpf: add API to get XDP/XSK supported features 2023-02-02 20:48:24 -08:00
relo_core.c bpf: Restrict CO-RE poisoning to relocatable instructions 2026-09-17 18:01:42 -07:00
relo_core.h bpf, libbpf: Add type match support 2022-07-05 21:14:25 -07:00
ringbuf.c libbpf: Fix ring buffer consumer loop on 32-bit position wrap 2026-08-14 15:21:09 -07:00
skel_internal.h bpftool: Generate skeleton for global percpu data 2026-08-13 10:27:40 -07:00
strset.c libbpf: Fix UAF in strset__add_str() 2026-05-28 14:25:55 -07:00
strset.h libbpf: Extract internal set-of-strings datastructure APIs 2021-03-18 16:14:22 -07:00
usdt.bpf.h libbpf: Fix USDT SIB argument handling causing unrecognized register error 2025-08-27 15:44:25 -07:00
usdt.c Major changes: 2026-08-20 07:36:20 -07:00
zip.c libbpf: Remove unneeded semicolon 2024-10-03 17:47:35 -07:00
zip.h libbpf: Implement basic zip archive parsing support 2023-03-01 16:05:34 -08:00