Skip to content
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

Tracee can't be compiled with clang 15 #2624

Closed
rafaeldtinoco opened this issue Jan 26, 2023 · 3 comments
Closed

Tracee can't be compiled with clang 15 #2624

rafaeldtinoco opened this issue Jan 26, 2023 · 3 comments
Assignees

Comments

@rafaeldtinoco
Copy link
Contributor

rafaeldtinoco commented Jan 26, 2023

Description

PR: #2581 has created a macro for has_prefix() to make clang-14 unroll loops from the eBPF code correctly. It was reported by @geyslan that clang-15 won't unroll loops correctly even with the 2 approaches we currently have. So, for now, tracee can only be built correctly by clang-12, clang-13, and clang-14.

Current commit: c885025

In addition to this, @geyslan reported a verification error when loading the bpf program (compiled with clang-15) into the kernel (might be related to the above loop unrolling issue):

❯ sudo ./dist/tracee -f comm=uname
Place your finger on the fingerprint reader
{"level":"warn","ts":1685366140.1138046,"msg":"libbpf: prog 'trace_ret_vfs_write_tail': BPF program load failed: Permission denied"}
libbpf: prog 'trace_ret_vfs_write_tail': -- BEGIN PROG LOAD LOG --
0: R1=ctx(off=0,imm=0) R10=fp0
; int BPF_KPROBE(trace_ret_vfs_write_tail)
0: (7b) *(u64 *)(r10 -184) = r1       ; R1=ctx(off=0,imm=0) R10=fp0 fp-184_w=ctx
1: (b7) r1 = 0                        ; R1_w=0
; int zero = 0;
2: (63) *(u32 *)(r10 -80) = r1        ; R1_w=0 R10=fp0 fp-80=????0000
...
; if (path == NULL) {
3311: (15) if r9 == 0x0 goto pc+2     ; R9_w=map_value(off=0,ks=24,vs=4096,imm=0)
3312: (79) r6 = *(u64 *)(r10 -160)    ; R6_w=map_value(off=0,ks=4,vs=32152,imm=0) R10=fp0
3313: (05) goto pc+1945
; if (path_buf != NULL && !has_prefix("/dev/null", (char *) &path_buf, 10)) {
5259: (bf) r1 = r9                    ; R1_w=map_value(off=0,ks=24,vs=4096,imm=0) R9_w=map_value(off=0,ks=24,vs=4096,imm=0)
5260: (57) r1 &= 255
R1 bitwise operator &= on pointer prohibited
processed 1019 insns (limit 1000000) max_states_per_insn 0 total_states 61 peak_states 61 mark_read 35
-- END PROG LOAD LOG --
{"level":"warn","ts":1685366140.1271274,"msg":"libbpf: prog 'trace_ret_vfs_write_tail': failed to load: -13"}
{"level":"warn","ts":1685366140.1276152,"msg":"libbpf: failed to load object ''"}
{"level":"fatal","ts":1685366140.1280177,"msg":"Tracee runner failed","error":"cmd.Runner.Run: error initializing Tracee: ebpf.(*Tracee).Init: ebpf.(*Tracee).initBPF: failed to load BPF object: permission denied"}
@rafaeldtinoco rafaeldtinoco added this to the v0.12.0 milestone Jan 26, 2023
@rafaeldtinoco rafaeldtinoco modified the milestones: v0.12.0, v0.13.0 Feb 28, 2023
@yanivagman yanivagman modified the milestones: v0.13.0, v0.14.0 Mar 8, 2023
@yanivagman yanivagman modified the milestones: v0.14.0, v0.15.0 Mar 30, 2023
@rafaeldtinoco rafaeldtinoco modified the milestones: v0.15.0, v0.14.0 Apr 25, 2023
@yanivagman yanivagman removed this from the v0.15.0 milestone May 24, 2023
@yanivagman yanivagman changed the title clang-15 won't unroll ebpf loops correctly Tracee can't be compiled with clang 15 May 30, 2023
@geyslan
Copy link
Member

geyslan commented Sep 12, 2023

Tried clang version 16.0.6, the build is completed but with an unique warning:

clang-16: warning: argument unused during compilation: '-march=bpf' [-Wunused-command-line-argument]

Execution continues to err in the same R1 bitwise operator &= on pointer prohibited.

@yanivagman yanivagman assigned geyslan and unassigned rafaeldtinoco Jan 30, 2024
@yanivagman
Copy link
Collaborator

I don't think this is still an error.
I just compiled Tracee with clang 16 with no errors.
@geyslan can you please verify on your environment and close if not an issue?

@geyslan
Copy link
Member

geyslan commented Jan 30, 2024

I've compiled and ran integration tests successfully on these envs:

  • Ubuntu, clang 12.0.1-19ubuntu3

  • Ubuntu and Manjaro, clang 14.0.6

  • Ubuntu, clang 15.0.7

  • Ubuntu, clang 16.0.6

    clang: warning: argument unused during compilation: '-march=bpf' [-Wunused-command-line-argument]

  • Ubuntu, clang 17.0.2

    clang: error: unsupported option '-march=' for target 'bpf'

    It compiled after removing the -march=bpf flag. This will be tackled in a chore PR - chore: remove clang march flag #3831.


In all cases, there's the unbounding issue #3830 when we expect to see 600 iterations and get only 60 in find_modules_from_module_kset_list().

Steps to check it:

  • Get the prog ID: sudo bpftool prog list | grep lkm_seeker_kset
  • Dump it: sudo bpftool prog dump xlated id ID > lkm_seeker_kset_tail_xlated
  • Count a condition inside the loop: grep 'if (mod_kobj) {' lkm_seeker_kset_tail_xlated_clang | wc -l

@geyslan geyslan closed this as completed Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants