linux/tools/bpf/bpftool
Kuan-Wei Chiu f04e2ad394 bpftool: Fix undefined behavior in qsort(NULL, 0, ...)
When netfilter has no entry to display, qsort is called with
qsort(NULL, 0, ...). This results in undefined behavior, as UBSan
reports:

net.c:827:2: runtime error: null pointer passed as argument 1, which is declared to never be null

Although the C standard does not explicitly state whether calling qsort
with a NULL pointer when the size is 0 constitutes undefined behavior,
Section 7.1.4 of the C standard (Use of library functions) mentions:

"Each of the following statements applies unless explicitly stated
otherwise in the detailed descriptions that follow: If an argument to a
function has an invalid value (such as a value outside the domain of
the function, or a pointer outside the address space of the program, or
a null pointer, or a pointer to non-modifiable storage when the
corresponding parameter is not const-qualified) or a type (after
promotion) not expected by a function with variable number of
arguments, the behavior is undefined."

To avoid this, add an early return when nf_link_info is NULL to prevent
calling qsort with a NULL pointer.

Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Quentin Monnet <qmo@kernel.org>
Link: https://lore.kernel.org/bpf/20240910150207.3179306-1-visitorckw@gmail.com
2024-09-10 11:40:55 -07:00
..
bash-completion bpftool: Add bash-completion for tcx subcommand 2024-07-29 12:54:04 -07:00
Documentation bpftool: Fix typos 2024-09-09 15:57:52 -07:00
skeleton bpftool: Fix typo in MAX_NUM_METRICS macro name 2024-06-03 16:58:27 +02:00
.gitignore bpftool: Fix SPDX tag for Makefiles and .gitignore 2021-11-10 09:00:52 -08:00
btf_dumper.c bpftool: Fix printing of pointer value 2023-10-19 16:29:36 +02:00
btf.c bpftool: Improve btf c dump sorting stability 2024-09-06 14:06:30 -07:00
cfg.c bpftool: Support printing opcodes and source file references in CFG 2023-04-05 21:27:27 -07:00
cfg.h bpftool: Support printing opcodes and source file references in CFG 2023-04-05 21:27:27 -07:00
cgroup.c bpftool: Query only cgroup-related attach types 2024-06-11 11:39:09 -07:00
common.c bpftool: Un-const bpf_func_info to fix it for llvm 17 and newer 2024-05-21 10:36:28 -07:00
feature.c bpftool: fix some typos in bpftool 2024-09-05 13:07:47 -07:00
gen.c bpftool: improve skeleton backwards compat with old buggy libbpfs 2024-07-09 19:03:05 -07:00
iter.c bpftool: Mount bpffs on provided dir instead of parent dir 2024-04-04 15:37:12 -07:00
jit_disasm.c bpftool: Fix spelling mistake "disasembler" -> "disassembler" 2022-10-26 18:20:22 -07:00
json_writer.c tools: bpftool: json: Fix backslash escape typo in jsonw_puts 2023-03-29 09:48:45 -07:00
json_writer.h tools: bpftool: json: Fix backslash escape typo in jsonw_puts 2023-03-29 09:48:45 -07:00
link.c bpftool: Add link dump support for BPF_LINK_TYPE_SOCKMAP 2024-04-10 19:52:25 -07:00
main.c bpftool: clean-up usage of libbpf_get_error() 2022-11-20 16:17:46 -08:00
main.h bpftool: Mount bpffs on provided dir instead of parent dir 2024-04-04 15:37:12 -07:00
Makefile bpftool: Fix make dependencies for vmlinux.h 2024-05-18 10:46:16 -07:00
map_perf_ring.c bpftool: Fix error message of strerror 2022-09-30 15:40:46 -07:00
map.c bpftool: Recognize arena map type 2024-03-11 15:37:24 -07:00
net.c bpftool: Fix undefined behavior in qsort(NULL, 0, ...) 2024-09-10 11:40:55 -07:00
netlink_dumper.c
netlink_dumper.h bpftool: Extend net dump with tcx progs 2023-07-19 10:07:28 -07:00
perf.c bpftool: fix perf help message 2023-08-11 20:54:29 -07:00
pids.c bpftool: Enable libbpf logs when loading pid_iter in debug mode 2024-03-19 23:12:22 -07:00
prog.c bpftool: Fix typo in usage help 2024-07-17 22:45:58 +02:00
struct_ops.c bpftool: Mount bpffs on provided dir instead of parent dir 2024-04-04 15:37:12 -07:00
tracelog.c bpftool, musl compat: Replace sys/fcntl.h by fcntl.h 2022-04-25 23:24:28 +02:00
xlated_dumper.c tools/bpf: Fix the wrong format specifier 2024-07-30 13:41:20 -07:00
xlated_dumper.h bpftool: Dump the kernel symbol's module name 2023-07-11 20:07:50 -07:00