mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-08 09:39:07 +08:00
libbpf: Handle unsupported mmap-based /sys/kernel/btf/vmlinux correctly
libbpf_err_ptr() helpers are meant to return NULL and set errno, if there is an error. But btf_parse_raw_mmap() is meant to be used internally and is expected to return ERR_PTR() values. Because of this mismatch, when libbpf tries to mmap /sys/kernel/btf/vmlinux, we don't detect the error correctly with IS_ERR() check, and never fallback to old non-mmap-based way of loading vmlinux BTF. Fix this by using proper ERR_PTR() returns internally. Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com> Reviewed-by: Arnaldo Carvalho de Melo <acme@redhat.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Fixes: 3c0421c93ce4 ("libbpf: Use mmap to parse vmlinux BTF from sysfs") Cc: Lorenz Bauer <lmb@isovalent.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20250606202134.2738910-1-andrii@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
@@ -1384,12 +1384,12 @@ static struct btf *btf_parse_raw_mmap(const char *path, struct btf *base_btf)
|
|||||||
|
|
||||||
fd = open(path, O_RDONLY);
|
fd = open(path, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return libbpf_err_ptr(-errno);
|
return ERR_PTR(-errno);
|
||||||
|
|
||||||
if (fstat(fd, &st) < 0) {
|
if (fstat(fd, &st) < 0) {
|
||||||
err = -errno;
|
err = -errno;
|
||||||
close(fd);
|
close(fd);
|
||||||
return libbpf_err_ptr(err);
|
return ERR_PTR(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||||
@@ -1397,7 +1397,7 @@ static struct btf *btf_parse_raw_mmap(const char *path, struct btf *base_btf)
|
|||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if (data == MAP_FAILED)
|
if (data == MAP_FAILED)
|
||||||
return libbpf_err_ptr(err);
|
return ERR_PTR(err);
|
||||||
|
|
||||||
btf = btf_new(data, st.st_size, base_btf, true);
|
btf = btf_new(data, st.st_size, base_btf, true);
|
||||||
if (IS_ERR(btf))
|
if (IS_ERR(btf))
|
||||||
|
|||||||
Reference in New Issue
Block a user