Bpftrace: Better non-root error

Created on 24 Dec 2018  路  4Comments  路  Source: iovisor/bpftrace

As non-root:

# ./src/bpftrace -e 'k:do_nanosleep { printf("hi\n"); }'
Warning: couldn't set RLIMIT for bpftrace. If your program is not loading, you can try "ulimit -l 8192" to fix the problem
Attaching 1 probe...
perf_event_open: Permission denied
   (check your kernel for PERF_COUNT_SW_BPF_OUTPUT support, 4.4 or newer)
Failed to open perf buffer

This is pretty confusing, and may be a bad first experience for newcomers.

I'd add a check for either geteuid() == 0, or whatever is the equivalent privileges/capabilities (CAP_SYS_ADMIN), and print a message that simply said:

"ERROR: bpftrace currently only supports running as the root user."

and then exiting, before we hit the rlimit errors.

Most helpful comment

@rlarrabe try running snap connect bpftrace:system-trace to enable bpftrace to access system tracing (see http://smackerelofopinion.blogspot.com/2018/11/high-level-tracing-with-bpftrace.html).

(We should probably document that somewhere...)

All 4 comments

I'm having similar problems running bpftrace on Ubuntu 18.04 with updates.

uname -a
Linux ip-172-31-23-145 4.15.0-1031-aws #33-Ubuntu SMP Fri Dec 7 09:32:27 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

I installed bcc with the following command:

sudo apt install bcc bpfcc-tools

And bpftrace with the following command:

sudo snap install bpftrace

When attempting to run any of the examples I receive the following output.

root@ip-0000:~# bpftrace -e 'kprobe:do_nanosleep { printf("PID %d sleeping...\n", pid); }'
Warning: couldn't set RLIMIT for bpftrace. If your program is not loading, you can try "ulimit -l 8192" to fix the problem
Error creating perf event map (-1)
Attaching 1 probe...
perf_event_open: Operation not permitted
   (check your kernel for PERF_COUNT_SW_BPF_OUTPUT support, 4.4 or newer)
Failed to open perf buffer

When attempting to execute the "Hello world" example I received the following:

root@ip-0000:~# bpftrace -e 'BEGIN { printf("hello world\n"); }'
Warning: couldn't set RLIMIT for bpftrace. If your program is not loading, you can try "ulimit -l 8192" to fix the problem
Error creating perf event map (-1)
Attaching 1 probe...
Error loading program: BEGIN (try -v)

What is the issue here? Please point me to the right location to raise this issue.

Thanks,

Rich

@rlarrabe are you running as root? This issue solves only the error message when you try to run bpftrace wichout root privilege. About the error you are getting I recomend you try the ubuntu and compilation sections of the install guide here: https://github.com/iovisor/bpftrace/blob/master/INSTALL.md

Hi Willi, Yes I am running as root. But it failed with the same message in either case. So are you writing that the snap installation is not valid.

Thanks,

Rich

@rlarrabe try running snap connect bpftrace:system-trace to enable bpftrace to access system tracing (see http://smackerelofopinion.blogspot.com/2018/11/high-level-tracing-with-bpftrace.html).

(We should probably document that somewhere...)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shish picture shish  路  5Comments

alejandrox1 picture alejandrox1  路  4Comments

danobi picture danobi  路  8Comments

fbs picture fbs  路  8Comments

Brother-Lal picture Brother-Lal  路  6Comments