Centos-kernel-stream-9/tools/bpf/bpftool
Jerome Marchand 4bc6786073 bpftool: Fix undefined behavior in qsort(NULL, 0, ...)
JIRA: https://issues.redhat.com/browse/RHEL-63880

commit f04e2ad394e2755d0bb2d858ecb5598718bf00d5
Author: Kuan-Wei Chiu <visitorckw@gmail.com>
Date:   Tue Sep 10 23:02:07 2024 +0800

    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

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
2025-01-21 11:27:04 +01:00
..
Documentation bpftool: Fix typos 2025-01-21 11:27:04 +01:00
bash-completion bpftool: Introduce btf c dump sorting 2024-11-26 08:57:39 +01:00
skeleton bpftool: Fix typo in MAX_NUM_METRICS macro name 2024-11-26 14:40:02 +01:00
.gitignore
Makefile bpftool: Fix make dependencies for vmlinux.h 2024-11-26 08:57:39 +01:00
btf.c bpftool: Improve btf c dump sorting stability 2025-01-21 11:27:04 +01:00
btf_dumper.c bpftool: Fix printing of pointer value 2024-03-27 10:27:54 +01:00
cfg.c bpftool: Support printing opcodes and source file references in CFG 2023-09-22 09:12:26 +02:00
cfg.h bpftool: Support printing opcodes and source file references in CFG 2023-09-22 09:12:26 +02:00
cgroup.c bpftool: Query only cgroup-related attach types 2024-11-26 14:40:06 +01:00
common.c bpftool: Un-const bpf_func_info to fix it for llvm 17 and newer 2024-11-26 08:57:39 +01:00
feature.c bpftool: fix some typos in bpftool 2025-01-21 11:27:03 +01:00
gen.c bpftool: improve skeleton backwards compat with old buggy libbpfs 2024-11-26 15:55:16 +01:00
iter.c bpftool: Mount bpffs on provided dir instead of parent dir 2024-11-07 13:58:44 +01:00
jit_disasm.c bpftool: Fix spelling mistake "disasembler" -> "disassembler" 2023-04-28 11:42:59 +02:00
json_writer.c tools: bpftool: json: Fix backslash escape typo in jsonw_puts 2023-09-22 09:12:24 +02:00
json_writer.h tools: bpftool: json: Fix backslash escape typo in jsonw_puts 2023-09-22 09:12:24 +02:00
link.c bpftool: Add link dump support for BPF_LINK_TYPE_SOCKMAP 2024-11-07 14:37:17 +01:00
main.c bpftool: clean-up usage of libbpf_get_error() 2023-04-28 11:43:09 +02:00
main.h bpftool: Mount bpffs on provided dir instead of parent dir 2024-11-07 13:58:44 +01:00
map.c bpftool: Recognize arena map type 2024-10-15 10:49:15 +02:00
map_perf_ring.c
net.c bpftool: Fix undefined behavior in qsort(NULL, 0, ...) 2025-01-21 11:27:04 +01:00
netlink_dumper.c
netlink_dumper.h bpftool: Extend net dump with tcx progs 2024-03-28 09:04:04 +01:00
perf.c bpftool: fix perf help message 2023-12-15 09:28:56 +01:00
pids.c bpftool: Enable libbpf logs when loading pid_iter in debug mode 2024-11-07 13:58:32 +01:00
prog.c bpftool: Fix typo in usage help 2024-11-26 15:55:18 +01:00
struct_ops.c bpftool: Mount bpffs on provided dir instead of parent dir 2024-11-07 13:58:44 +01:00
tracelog.c
xlated_dumper.c tools/bpf: Fix the wrong format specifier 2025-01-13 17:36:36 +01:00
xlated_dumper.h bpftool: Dump the kernel symbol's module name 2023-12-14 15:22:25 +01:00