Skip to content

Conversation

kkourt
Copy link
Contributor

@kkourt kkourt commented Jul 11, 2025

Change the newly introduced Arg to be an array so that we can support operators that work with multiple arguments.
(The Arg change has not yet been released, so this is not a breaking change).

Using above change, implement a CapabilitiesGained operator.

See commits.

Example policy:

apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
  name: "capabilites-gained"
spec:
  kprobes:
  - call: "security_capset"
    syscall: false
    return: true
    args:
      - index: 1
        type: "cap_effective"
        resolve: "cap_effective"
        label: "old_creds.cap_effective"
      - index: 2
        type: "cap_effective"
        label: "cap_effective"
    returnArg:
      index: 0
      type: "int"
    selectors:
      - matchActions:
        - action: Post
        matchArgs:
        - operator: CapabilitiesGained
          args:
          - 0
          - 1
    message: capability escalation

TODO:

  • Add test
  • Update docs for Arg

@kkourt kkourt requested a review from a team as a code owner July 11, 2025 15:02
@kkourt kkourt requested a review from tpapagian July 11, 2025 15:02
@kkourt kkourt added the release-note/minor This PR introduces a minor user-visible change label Jul 11, 2025
@kkourt kkourt marked this pull request as draft July 11, 2025 15:15
Copy link
Contributor

@olsajiri olsajiri left a comment

Choose a reason for hiding this comment

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

looks good, left some comments, thanks

@kkourt kkourt force-pushed the pr/kkourt/capabilities-gained branch 2 times, most recently from 796eaf6 to 9ca719d Compare July 14, 2025 09:45
@kkourt
Copy link
Contributor Author

kkourt commented Jul 14, 2025

Pushed a new version where I: merged commits so that all commits compile, added a test, constrained this feature only for kernels that support large programs (since 4.19 was failing to load the prog).

@kkourt kkourt force-pushed the pr/kkourt/capabilities-gained branch 2 times, most recently from 1548a21 to 4ee7a02 Compare July 14, 2025 11:14
@kkourt kkourt changed the title [RFC] add CapabiliitesGained operator tracingpolicies: add CapabiliitesGained operator Jul 14, 2025
@kkourt kkourt marked this pull request as ready for review July 14, 2025 11:57
@kkourt kkourt requested a review from olsajiri July 14, 2025 11:57
Copy link
Member

@mtardy mtardy left a comment

Choose a reason for hiding this comment

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

looks good to me! (indeed missing the updated docs for now)

kkourt added 7 commits July 16, 2025 08:06
This commit replaces the new Arg *uint32 field introduced in
4488a6d with an array. The intention is
to enable operators that use multiple arguments, which will happen in
subsequent commits.

Note that the above commit has not yet been in a released version of
tetragon, so breaking the compatibility is OK.

Having an array, we use the same semantics as the pointer. If the array
is empty, we use Index instead.

The commit also updates the tests and the docs.

Signed-off-by: Kornilios Kourtis <[email protected]>
Signed-off-by: Kornilios Kourtis <[email protected]>
Introduce a CapabilitiesGained operator that uses two arguments. The
index of the second argument is copied into values so that it can be
extracted by the bpf code.

Signed-off-by: Kornilios Kourtis <[email protected]>
Support the op_capabilities_gained operator. The operator is treated as
a specifial case. The second argument index is extracted from the
values, from which we get the args offset and, finally, the value.

The CapabilitiesGained  operator checks whether a capability argument
has gained capabilities compared to another argument.

For example:

```
apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
  name: "capabilities-gained"
spec:
  kprobes:
  - call: "security_capset"
    syscall: false
    return: true
    args:
      - index: 1
        type: "cap_effective"
        resolve: "cap_effective"
        label: "old_creds.cap_effective"
      - index: 2
        type: "cap_effective"
        label: "cap_effective"
    returnArg:
      index: 0
      type: "int"
    selectors:
      - matchActions:
        - action: Post
        matchArgs:
        - operator: CapabilitiesGained
          args:
          - 0
          - 1
```

Signed-off-by: Kornilios Kourtis <[email protected]>
Add a capabiliites-gained test program that performs three capset
sycalls, with only one gaining capabilities. Use it to test the
CapabilitiesGained operator.

Signed-off-by: Kornilios Kourtis <[email protected]>
Set the CapabilitiesGained operator to only work when large progrs are
supported in the kernel, since loading the generic program fails in
4.19.

Signed-off-by: Kornilios Kourtis <[email protected]>
@kkourt kkourt force-pushed the pr/kkourt/capabilities-gained branch from 4ee7a02 to ce21f25 Compare July 16, 2025 06:06
@kkourt
Copy link
Contributor Author

kkourt commented Jul 16, 2025

looks good to me! (indeed missing the updated docs for now)

Thanks! Pushed a new commit that also updates that docs.

Copy link

netlify bot commented Jul 16, 2025

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit ce21f25
🔍 Latest deploy log https://app.netlify.com/projects/tetragon/deploys/6877417d309c430008484b82
😎 Deploy Preview https://deploy-preview-3887--tetragon.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

@olsajiri olsajiri left a comment

Choose a reason for hiding this comment

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

looks good, thanks

@kkourt kkourt merged commit 1b99c6e into main Jul 16, 2025
60 of 61 checks passed
@kkourt kkourt deleted the pr/kkourt/capabilities-gained branch July 16, 2025 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/minor This PR introduces a minor user-visible change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants