lockc-project / lockc

Making containers more secure with eBPF and Linux Security Modules (LSM)
https://lockc-project.github.io/
Apache License 2.0
218 stars 19 forks source link

Build on openSUSE Leap: `vmlinux.h:1:1: error` #200

Closed tacerus closed 2 years ago

tacerus commented 2 years ago

Hi,

I was able to compile this successfully on openSUSE Tumbleweed, however on Leap 15.3 cargo build fails:

Caused by:
  process didn't exit successfully: `/home/georg/lockc-0.1.6/target/debug/build/lockc-878a95ed25893ef2/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-changed=src/bpf/compiler.h
  cargo:rerun-if-changed=src/bpf/limits.h
  cargo:rerun-if-changed=src/bpf/map_structs.h
  cargo:rerun-if-changed=src/bpf/maps.h
  cargo:rerun-if-changed=src/bpf/policy.h
  cargo:rerun-if-changed=src/bpf/strutils.h
  cargo:rerun-if-changed=src/bpf/lockc.bpf.c

  --- stderr
  Error: Failed to compile eBPF programs
   stdout=

   stderr=
   In file included from src/bpf/lockc.bpf.c:2:
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/vmlinux.h:1:1: error: expected identifier or '('
  404: Not Found
  ^
  In file included from src/bpf/lockc.bpf.c:4:
  In file included from /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helpers.h:11:
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:73:83: error: unknown type name '__u64'
  static long (*bpf_map_update_elem)(void *map, const void *key, const void *value, __u64 flags) = (void *) 2;
                                                                                    ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:97:42: error: unknown type name '__u32'
  static long (*bpf_probe_read)(void *dst, __u32 size, const void *unsafe_ptr) = (void *) 4;
                                           ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:109:16: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
  static __u64 (*bpf_ktime_get_ns)(void) = (void *) 5;
                 ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:109:8: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
  static __u64 (*bpf_ktime_get_ns)(void) = (void *) 5;
  ~~~~~~ ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:109:14: error: function cannot return function type 'int (void)'
  static __u64 (*bpf_ktime_get_ns)(void) = (void *) 5;
               ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:172:50: error: unknown type name '__u32'
  static long (*bpf_trace_printk)(const char *fmt, __u32 fmt_size, ...) = (void *) 6;
                                                   ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:188:16: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
  static __u32 (*bpf_get_prandom_u32)(void) = (void *) 7;
                 ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:188:8: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
  static __u32 (*bpf_get_prandom_u32)(void) = (void *) 7;
  ~~~~~~ ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:188:14: error: function cannot return function type 'int (void)'
  static __u32 (*bpf_get_prandom_u32)(void) = (void *) 7;
               ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:201:16: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
  static __u32 (*bpf_get_smp_processor_id)(void) = (void *) 8;
                 ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:201:8: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
  static __u32 (*bpf_get_smp_processor_id)(void) = (void *) 8;
  ~~~~~~ ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:201:14: error: function cannot return function type 'int (void)'
  static __u32 (*bpf_get_smp_processor_id)(void) = (void *) 8;
               ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:222:59: error: unknown type name '__u32'
  static long (*bpf_skb_store_bytes)(struct __sk_buff *skb, __u32 offset, const void *from, __u32 len, __u64 flags) = (void *) 9;
                                                            ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:222:91: error: unknown type name '__u32'
  static long (*bpf_skb_store_bytes)(struct __sk_buff *skb, __u32 offset, const void *from, __u32 len, __u64 flags) = (void *) 9;
                                                                                            ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:222:102: error: unknown type name '__u64'
  static long (*bpf_skb_store_bytes)(struct __sk_buff *skb, __u32 offset, const void *from, __u32 len, __u64 flags) = (void *) 9;
                                                                                                       ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:251:59: error: unknown type name '__u32'
  static long (*bpf_l3_csum_replace)(struct __sk_buff *skb, __u32 offset, __u64 from, __u64 to, __u64 size) = (void *) 10;
                                                            ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:251:73: error: unknown type name '__u64'
  static long (*bpf_l3_csum_replace)(struct __sk_buff *skb, __u32 offset, __u64 from, __u64 to, __u64 size) = (void *) 10;
                                                                          ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:251:85: error: unknown type name '__u64'
  static long (*bpf_l3_csum_replace)(struct __sk_buff *skb, __u32 offset, __u64 from, __u64 to, __u64 size) = (void *) 10;
                                                                                      ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:251:95: error: unknown type name '__u64'
  static long (*bpf_l3_csum_replace)(struct __sk_buff *skb, __u32 offset, __u64 from, __u64 to, __u64 size) = (void *) 10;
                                                                                                ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:287:59: error: unknown type name '__u32'
  static long (*bpf_l4_csum_replace)(struct __sk_buff *skb, __u32 offset, __u64 from, __u64 to, __u64 flags) = (void *) 11;
                                                            ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:287:73: error: unknown type name '__u64'
  static long (*bpf_l4_csum_replace)(struct __sk_buff *skb, __u32 offset, __u64 from, __u64 to, __u64 flags) = (void *) 11;
                                                                          ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:287:85: error: unknown type name '__u64'
  static long (*bpf_l4_csum_replace)(struct __sk_buff *skb, __u32 offset, __u64 from, __u64 to, __u64 flags) = (void *) 11;
                                                                                      ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:287:95: error: unknown type name '__u64'
  static long (*bpf_l4_csum_replace)(struct __sk_buff *skb, __u32 offset, __u64 from, __u64 to, __u64 flags) = (void *) 11;
                                                                                                ^
  /home/georg/lockc-0.1.6/target/debug/build/lockc-1ee1dd2d2c6cf5fb/out/include/bpf/bpf_helper_defs.h:322:63: error: unknown type name '__u32'
  static long (*bpf_tail_call)(void *ctx, void *prog_array_map, __u32 index) = (void *) 12;
                                                                ^
  fatal error: too many errors emitted, stopping now [-ferror-limit=]
  6 warnings and 20 errors generated.

I tried the packaged bpftool as well as the one built from source, as per the instructions.

I too run cargo install libbpf-cargo --force after switching my installations of bpftool.

My build environment on Leap consists of the following:

$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/georg/.rustup
stable-x86_64-unknown-linux-gnu (default)
rustc 1.60.0 (7737e0b5c 2022-04-04)

$ cargo --version
cargo 1.59.0

$ cargo libbpf --version
cargo-libbpf-libbpf 0.11.0

$ bpftool --version
bpftool v6.8.0
using libbpf v0.8
features: libbpf_strict

Would appreciate any ideas! Thanks for the cool project!

vadorovsky commented 2 years ago

Hi! Thanks for reporting the error and sorry for late response!

I'm going to merge this pull request as soon as it's green: #199. That PR removes the depdencency of libbpf entirely, all eBPF programs are written in Rust in Aya, so I guess also your problems with compiling C code will be gone. :wink:

vadorovsky commented 2 years ago

It happened, so I'm closing. I will update docs how to build lockc after full migration to Rust.

tacerus commented 2 years ago

Hi @vadorovsky, that's great news! Thank you very much for the update!

vadorovsky commented 2 years ago

@tacerus I will make sure to update docs (about building everything with cargo/rust) till Tuesday at latest.

tacerus commented 2 years ago

No hurry! I tried it on my own but encountered some errors, I'll try it again whenever the documentation is there. :-)