linux/tools/lib/bpf
Shung-Hsi Yu 6706135577 libbpf: Fix null-pointer dereference in find_prog_by_sec_insn()
[ Upstream commit d0d382f95a ]

When there are no program sections, obj->programs is left unallocated,
and find_prog_by_sec_insn()'s search lands on &obj->programs[0] == NULL,
and will cause null-pointer dereference in the following access to
prog->sec_idx.

Guard the search with obj->nr_programs similar to what's being done in
__bpf_program__iter() to prevent null-pointer access from happening.

Fixes: db2b8b0642 ("libbpf: Support CO-RE relocations for multi-prog sections")
Signed-off-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20221012022353.7350-4-shung-hsi.yu@suse.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-12-31 13:14:06 +01:00
..
.gitignore libbpf: Stop using feature-detection Makefiles 2021-02-04 01:22:00 +01:00
bpf_core_read.h libbpf: Fix endianness detection in BPF_CORE_READ_BITFIELD_PROBED() 2021-11-18 19:16:41 +01:00
bpf_endian.h libbpf: Make bpf_endian co-exist with vmlinux.h 2020-07-01 09:06:12 +02:00
bpf_gen_internal.h libbpf: Cleanup temp FDs when intermediate sys_bpf fails. 2021-05-19 00:40:44 +02:00
bpf_helpers.h libbpf: Move BPF_SEQ_PRINTF and BPF_SNPRINTF to bpf_helpers.h 2021-05-26 10:45:41 -07: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: Fail compilation if target arch is missing 2021-06-16 20:15:30 -07:00
bpf.c libbpf: Fix lookup_and_delete_elem_flags error reporting 2021-11-18 19:17:09 +01:00
bpf.h libbpf: Add bpf_cookie support to bpf_link_create() API 2021-08-17 00:45:08 +02:00
btf_dump.c libbpf: Fix use-after-free in btf_dump_name_dups 2022-12-31 13:14:06 +01:00
btf.c libbpf: Accommodate DWARF/compiler bug with duplicated structs 2022-01-27 11:04:28 +01:00
btf.h libbpf: Fix potential misaligned memory access in btf_ext__new() 2022-01-27 11:03:16 +01:00
Build libbpf: Split CO-RE logic into relo_core.c. 2021-07-26 12:29:14 -07:00
gen_loader.c libbpf: fix an snprintf() overflow check 2022-08-17 14:23:32 +02:00
hashmap.c libbpf: Centralize poisoning and poison reallocarray() 2020-08-18 18:38:25 -07:00
hashmap.h libbpf, hashmap: Fix undefined behavior in hash_bits 2020-11-02 23:33:51 +01:00
libbpf_common.h libbpf: Implement generalized .BTF.ext func/line info adjustment 2020-09-03 17:14:40 -07:00
libbpf_errno.c libbpf: Streamline error reporting for high-level APIs 2021-05-25 17:32:35 -07:00
libbpf_internal.h libbpf: Add bpf_cookie support to bpf_link_create() API 2021-08-17 00:45:08 +02:00
libbpf_legacy.h libbpf: Streamline error reporting for low-level APIs 2021-05-25 17:32:35 -07:00
libbpf_probes.c libbpf: Use page size as max_entries when probing ring buffer map 2022-12-19 12:36:41 +01:00
libbpf.c libbpf: Fix null-pointer dereference in find_prog_by_sec_insn() 2022-12-31 13:14:06 +01:00
libbpf.h libbpf: Add uprobe ref counter offset support for USDT semaphores 2021-08-17 00:45:08 +02:00
libbpf.map libbpf: Add bpf_cookie to perf_event, kprobe, uprobe, and tp attach APIs 2021-08-17 00:45:08 +02:00
libbpf.pc.template libbpf: Add zlib as a dependency in pkg-config template 2019-12-16 14:55:29 -08:00
linker.c libbpf: Fix using invalidated memory in bpf_linker 2022-01-27 11:03:16 +01:00
Makefile libbpf: Fix build issue with llvm-readelf 2022-04-13 20:59:03 +02:00
netlink.c libbpf: Fix memleak in libbpf_netlink_recv() 2022-04-08 14:23:31 +02:00
nlattr.c libbpf: Switch to void * casting in netlink helpers 2021-06-22 17:04:02 +02:00
nlattr.h libbpf: Switch to void * casting in netlink helpers 2021-06-22 17:04:02 +02:00
relo_core.c libbpf: Split CO-RE logic into relo_core.c. 2021-07-26 12:29:14 -07:00
relo_core.h libbpf: Split CO-RE logic into relo_core.c. 2021-07-26 12:29:14 -07:00
ringbuf.c libbpf: Handle size overflow for ringbuf mmap 2022-12-08 11:28:39 +01:00
skel_internal.h libbpf: Fix skel_internal.h to set errno on loader retval < 0 2021-11-18 19:16:27 +01:00
str_error.c libbpf: Poison kernel-only integer types 2020-01-10 10:38:00 -08:00
str_error.h
strset.c libbpf: Fix memory leak in strset 2021-10-01 22:54:38 +02:00
strset.h libbpf: Extract internal set-of-strings datastructure APIs 2021-03-18 16:14:22 -07:00
xsk.c selftests/xsk: Avoid use-after-free on ctx 2022-10-26 12:34:41 +02:00
xsk.h libbpf: xsk: Move barriers from libbpf_util.h to xsk.h 2021-03-10 13:45:16 -08:00