linux-stable/tools/lib/bpf
Andrii Nakryiko 179a2a8a7b libbpf: Fix realloc API handling in zero-sized edge cases
[ Upstream commit 8a0260dbf6 ]

realloc() and reallocarray() can either return NULL or a special
non-NULL pointer, if their size argument is zero. This requires a bit
more care to handle NULL-as-valid-result situation differently from
NULL-as-error case. This has caused real issues before ([0]), and just
recently bit again in production when performing bpf_program__attach_usdt().

This patch fixes 4 places that do or potentially could suffer from this
mishandling of NULL, including the reported USDT-related one.

There are many other places where realloc()/reallocarray() is used and
NULL is always treated as an error value, but all those have guarantees
that their size is always non-zero, so those spot don't need any extra
handling.

  [0] d08ab82f59 ("libbpf: Fix double-free when linker processes empty sections")

Fixes: 999783c8bb ("libbpf: Wire up spec management and other arch-independent USDT logic")
Fixes: b63b3c490e ("libbpf: Add bpf_program__set_insns function")
Fixes: 697f104db8 ("libbpf: Support custom SEC() handlers")
Fixes: b126882672 ("libbpf: Change the order of data and text relocations.")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20230711024150.1566433-1-andrii@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-09-13 09:48:00 +02:00
..
.gitignore libbpf: Make libbpf_version.h non-auto-generated 2021-09-13 15:36:47 -07:00
Build libbpf: Implement basic zip archive parsing support 2023-03-01 16:05:34 -08:00
Makefile Merge remote-tracking branch 'torvalds/master' into perf/core 2022-12-16 09:53:53 -03:00
bpf.c libbpf: Wire through log_true_size for bpf_btf_load() API 2023-04-11 18:05:44 +02:00
bpf.h libbpf: Wire through log_true_size for bpf_btf_load() API 2023-04-11 18:05:44 +02:00
bpf_core_read.h libbpf: Fix BPF_PROBE_READ{_STR}_INTO() on s390x 2023-01-28 12:45:14 -08:00
bpf_endian.h
bpf_gen_internal.h libbpf: Support kfunc detection in light skeleton. 2023-03-22 09:31:05 -07:00
bpf_helpers.h libbpf: fix offsetof() and container_of() to work with CO-RE 2023-07-19 16:35:23 +02:00
bpf_prog_linfo.c
bpf_tracing.h libbpf: Fix arm syscall regs spec in bpf_tracing.h 2023-02-27 11:58:24 -08:00
btf.c libbpf: Remove several dead assignments 2023-03-01 11:13:11 -08:00
btf.h libbpf: Don't require full struct enum64 in UAPI headers 2022-09-27 20:45:17 +02:00
btf_dump.c libbpf: btf_dump_type_data_check_overflow needs to consider BTF_MEMBER_BITFIELD_SIZE 2023-07-19 16:35:21 +02:00
gen_loader.c libbpf: Support kfunc detection in light skeleton. 2023-03-22 09:31:05 -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: Hashmap.h update to fix build issues using LLVM14 2022-11-11 10:24:23 -08:00
libbpf.c libbpf: Fix realloc API handling in zero-sized edge cases 2023-09-13 09:48:00 +02:00
libbpf.h libbpf: Ensure print callback usage is thread-safe 2023-03-27 11:33:43 -07:00
libbpf.map libbpf: Update a bpf_link with another struct_ops. 2023-03-22 22:53:02 -07:00
libbpf.pc.template
libbpf_common.h libbpf: cleanup LIBBPF_DEPRECATED_SINCE supporting macros for v0.x 2022-06-28 13:13:33 -07:00
libbpf_errno.c libbpf: Optimized return value in libbpf_strerror when errno is libbpf errno 2022-12-14 18:39:33 +01:00
libbpf_internal.h libbpf: Revert poisoning of strlcpy 2023-03-10 10:19:25 -08:00
libbpf_legacy.h libbpf: Clean up deprecated and legacy aliases 2022-08-17 22:42:56 +02:00
libbpf_probes.c bpf: netfilter: Add BPF_NETFILTER bpf_attach_type 2023-06-05 15:01:43 -07:00
libbpf_version.h libbpf: start v1.2 development cycle 2022-12-21 11:18:50 -08:00
linker.c libbpf: Fix double-free when linker processes empty sections 2023-03-27 20:02:15 -07:00
netlink.c libbpf: Fix bpf_xdp_query() in old kernels 2023-02-27 15:26:12 -08:00
nlattr.c libbpf: Fix alen calculation in libbpf_nla_dump_errormsg() 2023-02-10 15:27:22 -08:00
nlattr.h libbpf: add API to get XDP/XSK supported features 2023-02-02 20:48:24 -08:00
relo_core.c libbpf: Remove several dead assignments 2023-03-01 11:13:11 -08:00
relo_core.h bpf, libbpf: Add type match support 2022-07-05 21:14:25 -07:00
ringbuf.c libbpf: Use bpf_{btf,link,map,prog}_get_info_by_fd() 2023-02-16 15:32:45 -08:00
skel_internal.h libbpf: add map_get_fd_by_id and map_delete_elem in light skeleton 2022-08-25 18:52:29 -07:00
str_error.c
str_error.h
strset.c libbpf: Hashmap interface update to allow both long and void* keys/values 2022-11-09 20:45:14 -08:00
strset.h
usdt.bpf.h libbpf: Fix unbounded memory access in bpf_usdt_arg() 2023-01-28 12:45:14 -08:00
usdt.c libbpf: Fix realloc API handling in zero-sized edge cases 2023-09-13 09:48:00 +02:00
zip.c libbpf: Ignore warnings about "inefficient alignment" 2023-03-16 18:20:08 +01:00
zip.h libbpf: Implement basic zip archive parsing support 2023-03-01 16:05:34 -08:00