Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libbpf: Fix potential NULL dereference when parsing ELF

Fix if condition filtering empty ELF sections to prevent NULL
dereference.

Fixes: 47ea7417b074 ("libbpf: Skip empty sections in bpf_object__init_global_data_maps")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Hao Luo <haoluo@google.com>
Link: https://lore.kernel.org/bpf/20220816001929.369487-2-andrii@kernel.org

authored by

Andrii Nakryiko and committed by
Daniel Borkmann
d4e6d684 738a2f2f

+1 -1
+1 -1
tools/lib/bpf/libbpf.c
··· 1649 1649 sec_desc = &obj->efile.secs[sec_idx]; 1650 1650 1651 1651 /* Skip recognized sections with size 0. */ 1652 - if (sec_desc->data && sec_desc->data->d_size == 0) 1652 + if (!sec_desc->data || sec_desc->data->d_size == 0) 1653 1653 continue; 1654 1654 1655 1655 switch (sec_desc->sec_type) {