foniod / redbpf

Rust library for building and running BPF/eBPF modules
Apache License 2.0
1.71k stars 136 forks source link

bpf_create_map_xattr. is failing to load map. #309

Closed bs5ntnx closed 2 years ago

bs5ntnx commented 2 years ago

Am using the latest ubuntu 21.04 docker image but cargo run is failing with error. I followed the steps mentioned. ghcr.io/foniod/redbpf-build:latest-x86_64-ubuntu21.04

Followed the steps provided in the install document but cargo run is failing with the following error:

` root@ba7a8dcf2f3e:~/ws/redbpf-tutorial# cargo run Finished dev [unoptimized + debuginfo] target(s) in 0.06s Running target/debug/redbpf-tutorial Apr 03 07:15:07.613 ERROR redbpf::btf: error on bpf_load_btf: Apr 03 07:15:07.613 WARN redbpf: Failed to load BTF but BTF is optional. Ignore it Apr 03 07:15:07.613 ERROR redbpf: error on bpf_create_map_xattr. failed to load map .rodata: Operation not permitted (os error 1) thread 'main' panicked at 'error on Loader::load: ParseError(Map)', src/main.rs:24:49 stack backtrace: 0: 0x55c79503a41c - std::backtrace_rs::backtrace::libunwind::trace::h667de636fd16ec22 at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5 1: 0x55c79503a41c - std::backtrace_rs::backtrace::trace_unsynchronized::hb6272615657d5744 at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x55c79503a41c - std::sys_common::backtrace::_print_fmt::h85b0a9a3797c535d at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/sys_common/backtrace.rs:67:5 3: 0x55c79503a41c - ::fmt::h33e1fc29f9141885 at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/sys_common/backtrace.rs:46:22 4: 0x55c79506613f - core::fmt::write::h3b0ec0911656cf8a at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/core/src/fmt/mod.rs:1094:17 5: 0x55c795035da5 - std::io::Write::write_fmt::h015d8bf6ff8e54cc at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/io/mod.rs:1584:15 6: 0x55c79504b90b - std::sys_common::backtrace::_print::hac8aff4fe690f889 at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/sys_common/backtrace.rs:49:5 7: 0x55c79504b90b - std::sys_common::backtrace::print::hcf7ce53748cfb74f at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/sys_common/backtrace.rs:36:9 8: 0x55c79504b90b - std::panicking::default_hook::{{closure}}::h8e3df13515f3fd66 at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/panicking.rs:208:50 9: 0x55c79504b4ef - std::panicking::default_hook::h468fd6be1a9a88b4 at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/panicking.rs:225:9 10: 0x55c79504be13 - std::panicking::rust_panic_with_hook::h37bd253c0dc6b3b6 at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/panicking.rs:591:17 11: 0x55c79503a927 - std::panicking::begin_panic_handler::{{closure}}::hff24a561569e53dd at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/panicking.rs:497:13 12: 0x55c79503a55c - std::sys_common::backtrace::rust_end_short_backtrace::h1e26e0dfac5e461e at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/sys_common/backtrace.rs:141:18 13: 0x55c79504ba12 - rust_begin_unwind at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/panicking.rs:493:5 14: 0x55c794e5e0f1 - core::panicking::panic_fmt::h134fc7184a83985e at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/core/src/panicking.rs:92:14 15: 0x55c794e5e463 - core::result::unwrap_failed::hb0f1baf5c1816d17 at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/core/src/result.rs:1355:5 16: 0x55c794e65ef4 - core::result::Result<T,E>::expect::h270d861414695eb7 at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/core/src/result.rs:997:23 17: 0x55c794e61644 - redbpf_tutorial::main::{{closure}}::h5f426c5c40341628 at /root/ws/redbpf-tutorial/src/main.rs:24:22 18: 0x55c794e658eb - <core::future::from_generator::GenFuture as core::future::future::Future>::poll::hec01e3199382136f at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/core/src/future/mod.rs:80:19 19: 0x55c794e6288f - <core::pin::Pin

as core::future::future::Future>::poll::h849e6fcd7c03ef1f at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/core/src/future/future.rs:120:9 20: 0x55c794e603f0 - tokio::runtime::basic_scheduler::CoreGuard::block_on::{{closure}}::{{closure}}::{{closure}}::habbae41b748a1031 at /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/basic_scheduler.rs:498:48 21: 0x55c794e64a0c - tokio::coop::with_budget::{{closure}}::hc133780c55719cbc at /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/coop.rs:102:9 22: 0x55c794e6079c - std::thread::local::LocalKey::try_with::h4569009beaf61aa7 at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/thread/local.rs:376:16 23: 0x55c794e6043d - std::thread::local::LocalKey::with::h1f703c302d256419 at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/thread/local.rs:352:9 24: 0x55c794e6032b - tokio::coop::with_budget::h143b98390ccec554 at /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/coop.rs:95:5 25: 0x55c794e6032b - tokio::coop::budget::ha645f689c572e369 at /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/coop.rs:72:5 26: 0x55c794e6032b - tokio::runtime::basic_scheduler::CoreGuard::block_on::{{closure}}::{{closure}}::h4de271c6abee084c at /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/basic_scheduler.rs:498:25 27: 0x55c794e5ef98 - tokio::runtime::basic_scheduler::Context::enter::h1455229b0644e912 at /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/basic_scheduler.rs:356:19 28: 0x55c794e5fc87 - tokio::runtime::basic_scheduler::CoreGuard::block_on::{{closure}}::h72b3fdd033c8952e at /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/basic_scheduler.rs:497:36 29: 0x55c794e5fa4b - tokio::runtime::basic_scheduler::CoreGuard::enter::{{closure}}::h85d0f963d9dc20e9 at /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/basic_scheduler.rs:555:57 30: 0x55c794e6500d - tokio::macros::scoped_tls::ScopedKey::set::h66ad097209f8d380 at /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/macros/scoped_tls.rs:61:9 31: 0x55c794e5f7a3 - tokio::runtime::basic_scheduler::CoreGuard::enter::h5b2f190bcc45e9da at /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/basic_scheduler.rs:555:27 32: 0x55c794e5faa0 - tokio::runtime::basic_scheduler::CoreGuard::block_on::h23fce39239520433 at /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/basic_scheduler.rs:488:9 33: 0x55c794e5ea63 - tokio::runtime::basic_scheduler::BasicScheduler::block_on::h74853dff2f33612e at /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/basic_scheduler.rs:168:24 34: 0x55c794e65185 - tokio::runtime::Runtime::block_on::h4d093c1888144ee4 at /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/mod.rs:475:46 35: 0x55c794e61405 - redbpf_tutorial::main::hcf5e447dca06fbf9 at /root/ws/redbpf-tutorial/src/main.rs:33:5 36: 0x55c794e60e1b - core::ops::function::FnOnce::call_once::h8fe798fc0e676d43 at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/core/src/ops/function.rs:227:5 37: 0x55c794e629be - std::sys_common::backtrace::rust_begin_short_backtrace::h013fb39392fd7f89 at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/sys_common/backtrace.rs:125:18 38: 0x55c794e61e21 - std::rt::lang_start::{{closure}}::h7f7124fdd8c0a468 at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/rt.rs:49:18 39: 0x55c79504d169 - core::ops::function::impls::<impl core::ops::function::FnOnce for &F>::call_once::hca2171a860994cbf at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/core/src/ops/function.rs:259:13 40: 0x55c79504d169 - std::panicking::try::do_call::h38495b97646f9e9e at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/panicking.rs:379:40 41: 0x55c79504d169 - std::panicking::try::h95d99d6934f79bf7 at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/panicking.rs:343:19 42: 0x55c79504d169 - std::panic::catch_unwind::hbe9d48fc95558ef2 at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/panic.rs:431:14 43: 0x55c79504d169 - std::rt::lang_start_internal::h3d3a104e20e64476 at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/rt.rs:34:21 44: 0x55c794e61e00 - std::rt::lang_start::h956e030a88afcb70 at /build/rustc-pMmQ1I/rustc-1.53.0+dfsg1+llvm/library/std/src/rt.rs:48:5 45: 0x55c794e61dcc - main 46: 0x7f2f3fa53565 - __libc_start_main 47: 0x55c794e5e89e - _start 48: 0x0 -

`

rhdxmr commented 2 years ago

Hi @bs5ntnx bpf_create_map_xattr eventually calls bpf syscall. It is possible that your host kernel does not support bpf syscall if it is old or it is not configured to support bpf. Can you check this issue?

For example, What kernel version do you use? Which distro do you use? Does your kernel support bpf?

nbaksalyar commented 2 years ago

To me this seems like a problem with permissions. @bs5ntnx could you please try to run the same command with sudo? e.g.

$ sudo target/debug/redbpf-tutorial
bs5ntnx commented 2 years ago

Hi @rhdxmr ,

Am using 5.10 ubuntu and using the docker container to build and run redbpf tutorial program. 5.10 kernel seems to have bpf enabled.

@nbaksalyar , Am running as root user in my container. I dont need to run with sudo right ?

rsdy commented 2 years ago

@bs5ntnx Docker containers have some security features which prevents eBPF from working. Try starting the container with --privileged to disable security.

bs5ntnx commented 2 years ago

Thanks @rsdy for the workaround. Will try it and let you know.

bs5ntnx commented 2 years ago

Running the docker container with privileged mode solved the problem. Thanks @rsdy