Skip to content

fix(driver/bpf): probe compilation fixes - #22

Merged
poiana merged 5 commits into
masterfrom
bpf-compat-fixes
Mar 24, 2021
Merged

poiana merged 5 commits into
masterfrom
bpf-compat-fixes

Conversation

@fntlnz

@fntlnz fntlnz commented Mar 22, 2021 •

Copy link
Copy Markdown
Contributor

Signed-off-by: Lorenzo Fontana lo@linux.com

What type of PR is this?

/kind bug

Any specific area of the project related to this PR?

/area driver-ebpf

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #4

This is another attempt to fix the issue reported by many users on Falco where you can't have a working BPF probe when compiling with Clang >= 10.0.0

Systems where to test before merging

  • COS (esp with 73 workaround)
  • Longterm Kernel 4.19.182
  • Longterm Kernel 5.10.25
  • Stable Kernel 5.11.8
  • Ubuntu 20.04
  • CentOS 8

In particular, we want to make sure the probe still works under systems where it was working before the changes made here.

For faster iteration with newer kernels I created a bpf-harness test suite for our probe. You can find it here https://github.com/fntlnz/bpf-harness

Special notes for your reviewer:

If you can, please test this under your environment and report.

Does this PR introduce a user-facing change?:

fix(driver/bpf): probe compatibility with clang >= 10.0.0

@poiana
poiana requested review from leodido and leogr March 22, 2021 12:54
@fntlnz fntlnz changed the title update(driver/bpf): move map definition struct to maps.h wip: update(driver/bpf): move map definition struct to maps.h Mar 22, 2021
@fntlnz

fntlnz commented Mar 22, 2021

Copy link
Copy Markdown
Contributor Author

Superseedes #5

@fntlnz fntlnz changed the title wip: update(driver/bpf): move map definition struct to maps.h wip: fix(driver/bpf): probe compatibility with kernel >= 5.8 and Clang >= 10.0.0 Mar 22, 2021
Comment thread driver/bpf/filler_helpers.h Resolved
Comment thread driver/bpf/fillers.h Resolved
Comment thread driver/bpf/filler_helpers.h Resolved
@poiana poiana added size/M and removed size/S labels Mar 22, 2021
@fntlnz
fntlnz force-pushed the bpf-compat-fixes branch 2 times, most recently from e0dcd83 to 26d095b Compare March 22, 2021 13:55
@fntlnz fntlnz changed the title wip: fix(driver/bpf): probe compatibility with kernel >= 5.8 and Clang >= 10.0.0 wip: fix(driver/bpf): probe compilation for >= 5.8 kernels Mar 23, 2021
@fntlnz
fntlnz force-pushed the bpf-compat-fixes branch from 8d73f6e to 26d095b Compare March 23, 2021 17:58
@poiana poiana added size/S and removed size/M labels Mar 23, 2021
@fntlnz fntlnz changed the title wip: fix(driver/bpf): probe compilation for >= 5.8 kernels wip: fix(driver/bpf): probe compilation fixes Mar 24, 2021
@poiana poiana added size/L and removed size/S labels Mar 24, 2021
@fntlnz
fntlnz force-pushed the bpf-compat-fixes branch from eb3f927 to 0dbd80e Compare March 24, 2021 02:17
@fntlnz
fntlnz force-pushed the bpf-compat-fixes branch from 0a33971 to 411f1c9 Compare March 24, 2021 12:22
fntlnz added 2 commits March 24, 2021 13:43
Signed-off-by: Lorenzo Fontana <lo@linux.com>
Signed-off-by: Lorenzo Fontana <lo@linux.com>
@fntlnz
fntlnz force-pushed the bpf-compat-fixes branch from 411f1c9 to d51af2c Compare March 24, 2021 12:44
@fntlnz fntlnz changed the title wip: fix(driver/bpf): probe compilation fixes fix(driver/bpf): probe compilation fixes Mar 24, 2021
@fntlnz
fntlnz requested a review from gnosek March 24, 2021 13:04

@gnosek gnosek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Way less magic, I like it :) Any chance we can #define memset __builtin_bpf_memset (and same thing for memcpy) instead of changing every single call site? This would make it easier to converge to a single filler implementation shared across all engines at some point in time

@fntlnz

fntlnz commented Mar 24, 2021

Copy link
Copy Markdown
Contributor Author

I knew you would've liked it now @gnosek - thanks for the patience :)

I tried to do as suggested but it leads to strange behaviors on some compilers and I went this route after. :(

@gnosek

gnosek commented Mar 24, 2021

Copy link
Copy Markdown
Contributor

Maybe something like this would work?

#ifdef memset
#undef memset
#endif
#define memset __builtin_memset

I feel like having to use the __builtin variants will be error-prone and easy to forget.

BTW, do we need the __bpf_builtin_memset wrapper? Wouldn't just __builtin_memset work?

BTW2, what "some compilers"? Is there anything else on the table except for various clang versions?

@fntlnz
fntlnz force-pushed the bpf-compat-fixes branch from d51af2c to 563083b Compare March 24, 2021 13:38
@poiana poiana added size/M and removed size/L labels Mar 24, 2021
fntlnz and others added 3 commits March 24, 2021 14:40
… and memset

Reported-By: Luca Montechiesi <lucamontechiesi@gmail.com>
Co-Authored-By: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
Signed-off-by: Lorenzo Fontana <lo@linux.com>
This is to make sure that in the subsequent conditions len is treated as a scalar rather than a pointer to map value internally.

Signed-off-by: Lorenzo Fontana <lo@linux.com>
…ctx.curoff before

using it in conditions.

This is to make sure the verifier addresses the comparison
operations to the scalar value instead of the map ptr

Signed-off-by: Lorenzo Fontana <lo@linux.com>
@fntlnz
fntlnz force-pushed the bpf-compat-fixes branch from 563083b to affe7bf Compare March 24, 2021 13:41
@fntlnz

fntlnz commented Mar 24, 2021

Copy link
Copy Markdown
Contributor Author

@gnosek you are right, my bad I was not changing all the occurrences when I tried and thought it was a compiler's issue. Pushed a fix and added you as a co-author.

@gnosek gnosek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@poiana

poiana commented Mar 24, 2021

Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: 688628b1ee969ae14ffe4d25ec9468006e62e2a6

@leodido leodido left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed this in person so many times 😃

Great job as usual.

/lgtm

@poiana

poiana commented Mar 24, 2021

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gnosek, leodido

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana
poiana merged commit cd8d5b0 into master Mar 24, 2021
@poiana
poiana deleted the bpf-compat-fixes branch March 24, 2021 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BPF probe compilation under Clang 10 and Clang 11

4 participants