Skip to content

Commit 02670de

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
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 <[email protected]> Reviewed-by: Arnaldo Carvalho de Melo <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Fixes: 3c0421c ("libbpf: Use mmap to parse vmlinux BTF from sysfs") Cc: Lorenz Bauer <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 7a912d0 commit 02670de

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

tools/lib/bpf/btf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,20 +1384,20 @@ static struct btf *btf_parse_raw_mmap(const char *path, struct btf *base_btf)
13841384

13851385
fd = open(path, O_RDONLY);
13861386
if (fd < 0)
1387-
return libbpf_err_ptr(-errno);
1387+
return ERR_PTR(-errno);
13881388

13891389
if (fstat(fd, &st) < 0) {
13901390
err = -errno;
13911391
close(fd);
1392-
return libbpf_err_ptr(err);
1392+
return ERR_PTR(err);
13931393
}
13941394

13951395
data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
13961396
err = -errno;
13971397
close(fd);
13981398

13991399
if (data == MAP_FAILED)
1400-
return libbpf_err_ptr(err);
1400+
return ERR_PTR(err);
14011401

14021402
btf = btf_new(data, st.st_size, base_btf, true);
14031403
if (IS_ERR(btf))

0 commit comments

Comments
 (0)