Skip to content

Commit 73df93c

Browse files
yonghong-songborkmann
authored andcommitted
tools/bpftool: fix a bug in bpftool perf
Commit b04df40 ("tools/bpftool: add perf subcommand") introduced bpftool subcommand perf to query bpf program kuprobe and tracepoint attachments. The perf subcommand will first test whether bpf subcommand BPF_TASK_FD_QUERY is supported in kernel or not. It does it by opening a file with argv[0] and feeds the file descriptor and current task pid to the kernel for querying. Such an approach won't work if the argv[0] cannot be opened successfully in the current directory. This is especially true when bpftool is accessible through PATH env variable. The error below reflects the open failure for file argv[0] at home directory. [yhs@localhost ~]$ which bpftool /usr/local/sbin/bpftool [yhs@localhost ~]$ bpftool perf Error: perf_query_support: No such file or directory To fix the issue, let us open root directory ("/") which exists in every linux system. With the fix, the error message will correctly reflect the permission issue. [yhs@localhost ~]$ which bpftool /usr/local/sbin/bpftool [yhs@localhost ~]$ bpftool perf Error: perf_query_support: Operation not permitted HINT: non root or kernel doesn't support TASK_FD_QUERY Fixes: b04df40 ("tools/bpftool: add perf subcommand") Reported-by: Alexei Starovoitov <[email protected]> Signed-off-by: Yonghong Song <[email protected]> Reviewed-by: Jakub Kicinski <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 5d90237 commit 73df93c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tools/bpf/bpftool/perf.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ static bool has_perf_query_support(void)
2929
if (perf_query_supported)
3030
goto out;
3131

32-
fd = open(bin_name, O_RDONLY);
32+
fd = open("/", O_RDONLY);
3333
if (fd < 0) {
34-
p_err("perf_query_support: %s", strerror(errno));
34+
p_err("perf_query_support: cannot open directory \"/\" (%s)",
35+
strerror(errno));
3536
goto out;
3637
}
3738

0 commit comments

Comments
 (0)