8000 Capabilities fixes by rafaeldtinoco · Pull Request #3006 · aquasecurity/tracee · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Capabilities fixes #3006

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

Merged
merged 2 commits into from
Apr 30, 2023
Merged

Capabilities fixes #3006

merged 2 commits into from
Apr 30, 2023

Conversation

rafaeldtinoco
Copy link
Contributor

commit cb71563 (HEAD -> capabilities-fixes, origin/capabilities-fixes)
Author: Rafael David Tinoco rafaeldtinoco@gmail.com
Date: Wed Apr 19 04:01:45 2023

capabilities: fix legacy detachment for older kernels

Legacy attachments (for now: cgroupv2 prog attachments under older
kernels) might not be done using BpfLink logic. Without a file
descriptor for the link, tracee needs to raise its capabilities
in order to call bpf() syscall for the legacy detachment.

This fixes error happening in older kernels when exiting tracee:

  {"level":"error","ts":1681876470.9877832,"msg":"failed to detach
  probes when closing tracee","err":"probes.(*probes).DetachAll:
  probes.(*cgroupProbe).detach: failed to detach program:
  cgroup_skb_ingress (failed to detach (legacy) program
  cgroup_skb_ingress from cgroupv2 /sys/fs/cgroup/unified)"}

Fixes: #2998

commit b063b4b
Author: Rafael David Tinoco rafaeldtinoco@gmail.com
Date: Wed Apr 19 03:16:46 2023

capabilities: fix early call to cap raise

When executing tracee-ebpf, the capabilities are dropped correctly, but
when executing the single binary, they are not.

That happens because the single binary calls a function to find
signatures in a directory, and that function raised capabilities. Since
the capabilities gwere not initialized at that moment (by tracee.New()),
then they were initialized incorrectly (since GetInstace() initializes
capabilities if it isn't yet).

This commit removes capabilities raising from early stage functions,
in tracee rules logic, and postpones a bit the full capabilities setup
This way, both tracee-ebpf and tracee binaries can coexist with
a working initialization logic.

Fixes: #3004

@rafaeldtinoco
Copy link
Contributor Author

@josedonizetti I would like you to take a look at the changes related to "tracee-rules" (and tracee single binary) initialization, if possible. I postponed the privilege dropping so both tracee-ebpf and tracee could use the same "capabilities initialization" under Tracee.Init().

@@ -105,32 +103,26 @@ func NewConfigsFromDir(dirPath string) ([]SignaturesConfig, error) {
func walkFilesWithExtensions(rootDir string, extensions []string) ([]string, error) {
var files []string

err := capabilities.GetInstance().Specific(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we remove this request?

Copy link
Collaborator
@yanivagman yanivagman Apr 19, 2023

Choose a reason for hiding this comment

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

Ok, I see why from you commit message.
I'm just trying to think what should be done in the future if we need to call this function in runtime (maybe we will support dynamically loading new signatures?)
Can't we move the capabilities initialization part to be before calling this func?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm just trying to think what should be done in the future if we need to call this function in runtime (maybe we will support dynamically loading new signatures?)

Yes, that will be the "next step", together with the "mapping all things that need to be done for the dynamic unload/load of signatures" (for the API). For now I thought it would be ok to keep it like this and fix the bugs we currently have (For the release). WDYT ?

When executing tracee-ebpf, the capabilities are dropped correctly, but
when executing the single binary, they are not.

That happens because the single binary calls a function to find
signatures in a directory, and that function raised capabilities. Since
the capabilities gwere not initialized at that moment (by tracee.New()),
then they were initialized incorrectly (since GetInstace() initializes
capabilities if it isn't yet).

This commit removes capabilities raising from early stage functions,
in tracee rules logic, and postpones a bit the full capabilities setup
This way, both tracee-ebpf and tracee binaries can coexist with
a working initialization logic.

Fixes: #3004
Legacy attachments (for now: cgroupv2 prog attachments under older
kernels) might not be done using BpfLink logic. Without a file
descriptor for the link, tracee needs to raise its capabilities
in order to call bpf() syscall for the legacy detachment.

This fixes error happening in older kernels when exiting tracee:

  {"level":"error","ts":1681876470.9877832,"msg":"failed to detach
  probes when closing tracee","err":"probes.(*probes).DetachAll:
  probes.(*cgroupProbe).detach: failed to detach program:
  cgroup_skb_ingress (failed to detach (legacy) program
  cgroup_skb_ingress from cgroupv2 /sys/fs/cgroup/unified)"}

Fixes: #2998
@rafaeldtinoco
Copy link
Contributor Author

@yanivagman I believe this is ready for merging (for the release).

Copy link
Collaborator
@yanivagman yanivagman left a comment

Choose a reason for hiding this comment

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

LGTM

@rafaeldtinoco rafaeldtinoco merged commit a1e228b into aquasecurity:main Apr 30, 2023
@rafaeldtinoco rafaeldtinoco deleted the capabilities-fixes branch April 30, 2023 11:39
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.

Single binary tracee isn't dropping capabilities correctly Legacy cgroup kprobe detachment fails when capabilities are dropped by default
2 participants
0