linux-stable/tools/lib
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
..
api tools api: Add io__getline 2023-04-04 13:23:59 -03:00
bpf libbpf: Fix realloc API handling in zero-sized edge cases 2023-09-13 09:48:00 +02:00
perf libperf rc_check: Enable implicitly with sanitizers 2023-04-20 15:12:02 -03:00
subcmd tools lib subcmd: Add dependency test to install_headers 2022-12-14 11:16:12 -03:00
symbol tools lib symbol: Add dependency test to install_headers 2022-12-14 11:16:12 -03:00
thermal tools/lib/thermal: Fix include path for libnl3 in pkg-config file. 2023-02-15 17:29:40 +01:00
argv_split.c
bitmap.c Bitmap patches for v6.0-rc1 2022-08-07 17:52:35 -07:00
ctype.c
find_bit.c tools: sync find_bit() implementation 2022-09-21 12:21:44 -07:00
hweight.c
list_sort.c tools lib: Adopt list_sort() from the kernel sources 2021-10-20 10:30:59 -03:00
rbtree.c
slab.c tools: Move gfp.h and slab.h from radix-tree to lib 2022-02-20 08:44:37 +02:00
str_error_r.c
string.c tools lib: Adopt memchr_inv() from kernel 2020-11-27 08:34:52 -03:00
vsprintf.c
zalloc.c