deepin-kernel/tools/lib
Adin Scannell 1fe72f1273 libbpf: Fix possible use-after-free for externs
[ Upstream commit fa6f092cc0a02d0fcee37e9e8172eda372a03d33 ]

The `name` field in `obj->externs` points into the BTF data at initial
open time. However, some functions may invalidate this after opening and
before loading (e.g. `bpf_map__set_value_size`), which results in
pointers into freed memory and undefined behavior.

The simplest solution is to simply `strdup` these strings, similar to
the `essent_name`, and free them at the same time.

In order to test this path, the `global_map_resize` BPF selftest is
modified slightly to ensure the presence of an extern, which causes this
test to fail prior to the fix. Given there isn't an obvious API or error
to test against, I opted to add this to the existing test as an aspect
of the resizing feature rather than duplicate the test.

Fixes: 9d0a23313b ("libbpf: Add capability for resizing datasec maps")
Signed-off-by: Adin Scannell <amscanne@meta.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250625050215.2777374-1-amscanne@meta.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit ad9c4941d32e1c35d878b50a2e7036282b8a213a)
2025-07-09 09:50:00 +08:00
..
api libapi: Add missing linux/types.h header to get the __u64 type on io.h 2024-01-25 15:35:51 -08:00
bpf libbpf: Fix possible use-after-free for externs 2025-07-09 09:50:00 +08:00
perf perf/traceevent: Support asciidoctor for documentation 2024-12-31 11:42:52 +08:00
subcmd libsubcmd: Don't free the usage string 2024-12-10 20:42:41 +08:00
symbol tools lib symbol: Add dependency test to install_headers 2022-12-14 11:16:12 -03:00
thermal thermal/lib: Fix memory leak on error in thermal_genl_auto() 2024-12-10 20:44:27 +08: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
vsprintf.c
zalloc.c