-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running BCC tools in CoreOS toolbox #1532
Comments
Typically, map creation failure with permission denied is caused by either
capability (e.g., you need root) or the limited locked memory.
Could you run this command `ulimit -l unlimited` to see whether it may
resolve your issue?
…On Mon, Jan 15, 2018 at 10:31 PM, Facetoe ***@***.***> wrote:
I'm trying to run the tools in CoreOS toolbox, but keep getting the
following error:
***@***.*** tools]# ./execsnoop
/virtual/main.c:21:1: error: could not open bpf map: Operation not permitted
is maps/perf_output map type enabled in your kernel?
BPF_PERF_OUTPUT(events);
^
/virtual/include/bcc/helpers.h:88:4: note: expanded from macro 'BPF_PERF_OUTPUT'
}; \
^
/virtual/main.c:26:5: error: bpf_table events failed to open
events.perf_submit(ctx, data, sizeof(struct data_t));
^
/virtual/main.c:74:5: error: bpf_table events failed to open
events.perf_submit(ctx, &data, sizeof(data));
^
3 errors generated.
Traceback (most recent call last):
File "./execsnoop", line 132, in <module>
b = BPF(text=bpf_text.replace("MAXARG", args.max_args))
File "/usr/lib/python2.7/site-packages/bcc/__init__.py", line 301, in __init__
raise Exception("Failed to compile BPF module %s" % src_file)
Exception: Failed to compile BPF module
I followed the instructions to install from source here
https://github.com/iovisor/bcc/blob/master/INSTALL.md#fedora---source.
That all worked fine, and the tools compile and install. First I had this
error:
chdir(/lib/modules/4.13.9-coreos/build): No such file or directory
So I symlinked the required directory:
ln -s /media/root/lib/modules/ /lib/modules
When I strace the process I can see the bpf call it is returning EPERM:
***@***.*** tools]# strace ./execsnoop 2>&1 | grep -i permi
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERF_EVENT_ARRAY, key_size=4, value_size=4, max_entries=15, map_flags=0, inner_map_fd=0, ...}, 72) = -1 EPERM (Operation not permitted)
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERF_EVENT_ARRAY, key_size=4, value_size=4, max_entries=15, map_flags=0, inner_map_fd=0, ...}, 72) = -1 EPERM (Operation not permitted)
I think the BPF stuff is enabled in the kernel:
***@***.*** tools]# zgrep -i bpf /proc/config.gz
# CONFIG_CGROUP_BPF is not set
CONFIG_BPF=y
CONFIG_BPF_SYSCALL=y
CONFIG_NETFILTER_XT_MATCH_BPF=m
CONFIG_NET_CLS_BPF=m
# CONFIG_NET_ACT_BPF is not set
CONFIG_BPF_JIT=y
CONFIG_LWTUNNEL_BPF=y
CONFIG_HAVE_EBPF_JIT=y
CONFIG_BPF_EVENTS=y
# CONFIG_TEST_BPF is not set
The man page for bpf says the following:
EPERM The call was made without sufficient privilege (without the
CAP_SYS_ADMIN capability).
but it looks like toolbox includes this:
sudo systemd-nspawn \
--directory="${machinepath}" \
--capability=all \
--share-system \
${TOOLBOX_BIND} \
${TOOLBOX_ENV} \
--user="${TOOLBOX_USER}" "$@"
I'm running toolbox as root.
System details:
~ $ uname -a
Linux ip-10-224-55-200 4.13.9-coreos #1 SMP Thu Oct 26 03:21:00 UTC 2017 x86_64 Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz GenuineIntel GNU/Linux
Any idea why this is not working? Should it even work?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1532>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALq6olF96Gi0vLNNDAkmBP44bNLdnyxoks5tLEJLgaJpZM4RfTtH>
.
|
Unfortunately, I still get the same error after running |
I appear to have the CAP_SYS_ADMIN capability in the container:
|
Maybe some security enforcement inside the container which blocks bpf syscalls?
In a different window, run your command like "execsnoop.py" or "biosnoop.py". |
Aha, I think you might be on to something. When I execute the above (outside the container), and then execute "execsnoop.py" (inside the container), I see no output from the To verify that tracing was working, I executed (outside the container):
Jumped in the container and opened some files. Sure enough, there is lots of output. SELinux exists on the system and is set to
Perhaps this is what is preventing BPF execution? I have managed to get the tools working in the following Docker container https://github.com/zlim/bcc-docker, so there must be something that Docker is doing to enable execution that systemd-nspawn does not. |
in the recent kernels BPF syscall got its own LSM hook. |
Thanks @4ast, I don't know much about SELinux, but from what I was reading I followed the steps here https://coreos.com/os/docs/latest/selinux.html, to enable SELinux logging and tried running "execsnoop.py" in the container, however no output was generated. I thought I could just disable SELinux completely and see if that worked, however I don't seem to have the option to disable it:
I'm a bit stuck as to where to go from here, any suggestions? |
|
Yep, tried that. No change unfortunately. |
The same is happening to me.
|
also hit this error on both fedora 27/28, rpm or source build. [root@suse tools]# ./tcptop cat /boot/config-4.18.5-200.fc28.x86_64 |grep BPFCONFIG_CGROUP_BPF=y CONFIG_BPFILTER is not setCONFIG_NET_CLS_BPF=m CONFIG_BPF_KPROBE_OVERRIDE is not setCONFIG_TEST_BPF is not set |
Same on Fedora 28 with the default 4.18.7-200.fc28.x86_64 kernel. selinux is disabled, running as root.
|
Could you try use debugfs kretprobe to trace kernel function security_bpf? If the return value is not 0, it will be still related to selinux. |
@facetoe Did you manage to figure this out in the end? I ran into a very similar issue trying to run an eBPF program with a minimal capability set, avoiding I came across this gem: https://stackoverflow.com/questions/40837181/how-to-raise-ulimit-hard-limit-for-real-time-priority-programmatically-with-setu. Apparently having Can't immediately find the script you linked, but I assume it creates a bind mount from a partition with To the other posters in this thread: consider user namespace remapping as a factor, UID0 in the container != UID0 in the host namespace, so those containers will have to rely on assuming capabilities, even with |
I'm running into the same issue, selinux is definitely turned off, but I'm not sure how to use |
@facetoe I'd also love to understand whether or not you found a resolution to this. Thanks for reporting in detail about the debugging work you did, already super helpful. |
Nope, never found a solution unfortunately. I ended up pulling Docker containers for the BPF stuff. |
For Fedora 30, the problem is not selinux but kernel-lockdown. If you leave selinux in enforcing mode but disable kernel lockdown, you can then use bcc tools as root. To disable kernel lockdown: echo 1 > /proc/sys/kernel/sysrq ( just verified on a fresh FC30 upgrade ) |
@deg00 Great! Do you mind adding it to the FAQ? |
Thank you so much @deg00 -- this resolved the issue described in #2525. For the issue described here it's not entirely clear if kernel lockdown is the problem. This was reported with kernel version 4.13 which probably does not have kernel lockdown code, right? I have created a quick FAQ patch for this a minute ago...: #2532 |
Note that various versions of the lockdown patches have been backported by distros into older kernel versions. See bpftrace/bpftrace#853 for the ubuntu variant I ran into. |
@deg00 what option does I get the following in
|
x mapped to disable kernel_lockdown on x86 ( https://lore.kernel.org/patchwork/patch/1046899/ ). I haven't had time to see if the recent merge of kernel lockdown in to the Linus kernel has changed behavior, but that might be it. Or it might be that your kernel does not have the kernel lockdown patch ( and so does not have the sysrq trigger ). Not helpful, I know, but the best I can do at the moment. |
Actually it was super helpful. Thank you! |
Encounter similar issue in docker env. And I find there is an "SELinux: mount invalid" log in dmesg.
|
Thanks @4ast for this info - I stumbled upon your comment and it helped. Would you know where this was added to the kernel? I'm guessing it was this? torvalds/linux@ec27c35 |
@simar7 Yes, the above patch is one in the original patch series. |
I'm trying to run the tools in CoreOS toolbox, but keep getting the following error:
I followed the instructions to install from source here https://github.com/iovisor/bcc/blob/master/INSTALL.md#fedora---source. That all worked fine, and the tools compile and install. First I had this error:
So I symlinked the required directory:
When I strace the process I can see the
bpf
call it is returningEPERM
:I think the BPF stuff is enabled in the kernel:
The man page for
bpf
says the following:but it looks like
toolbox
includes this:I'm running
toolbox
as root.System details:
Any idea why this is not working? Should it even work?
The text was updated successfully, but these errors were encountered: