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

tetragon: Add killer sensor #1205

Merged
merged 14 commits into from
Oct 12, 2023
Merged

tetragon: Add killer sensor #1205

merged 14 commits into from
Oct 12, 2023

Conversation

olsajiri
Copy link
Contributor

@olsajiri olsajiri commented Jul 10, 2023

adding support to have fast way (when multi kprobe link is not available)
of attaching killer/override program to multiple syscalls

details in: https://github.com/olsajiri/tetragon/blob/killer/docs/content/en/docs/concepts/tracing-policy/selectors.md#notify-killer-action

@netlify
Copy link

netlify bot commented Jul 10, 2023

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit 2d80318
🔍 Latest deploy log https://app.netlify.com/sites/tetragon/deploys/6527e4f135be40000834b7d2
😎 Deploy Preview https://deploy-preview-1205--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 site configuration.

@olsajiri olsajiri force-pushed the killer branch 3 times, most recently from c13973c to 21daede Compare July 11, 2023 13:31
@olsajiri olsajiri force-pushed the killer branch 5 times, most recently from b27c59f to 69718d7 Compare August 22, 2023 13:37
@olsajiri olsajiri force-pushed the killer branch 2 times, most recently from 967b56c to 8bf3a4e Compare August 30, 2023 09:41
@olsajiri olsajiri added the release-note/minor This PR introduces a minor user-visible change label Aug 30, 2023
@olsajiri olsajiri force-pushed the killer branch 7 times, most recently from 7b67b6d to 2725b32 Compare September 5, 2023 11:13
@olsajiri olsajiri force-pushed the killer branch 4 times, most recently from 1c0e273 to edc5374 Compare September 20, 2023 16:41
@olsajiri olsajiri force-pushed the killer branch 7 times, most recently from ec97b4c to bf75c17 Compare October 6, 2023 13:31
@olsajiri olsajiri changed the title Killer tetragon: Add killer sensor Oct 6, 2023
@olsajiri olsajiri force-pushed the killer branch 2 times, most recently from dd6bd1c to 82a64dc Compare October 7, 2023 15:12
@olsajiri olsajiri marked this pull request as ready for review October 9, 2023 08:52
@olsajiri olsajiri requested review from a team and mtardy as code owners October 9, 2023 08:52
@olsajiri olsajiri requested a review from kkourt October 9, 2023 08:53
Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

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

🚀

Have a couple of nits, but this looks good! Thanks!

@@ -576,6 +576,9 @@ spec:
- generated_syscalls
- generated_ftrace
type: string
validated:
description: List was validated
type: boolean
Copy link
Contributor

@kkourt kkourt Oct 9, 2023

Choose a reason for hiding this comment

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

So from what I can tell, this option means that no validation will be performed.
Maybe ignore-validation is a better name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's there to ensure the validation goes through just once, so it gets validated,
sets the flag so another sensor won't run it again, I'll update changelog with that, sry

Copy link
Member

Choose a reason for hiding this comment

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

is there a way we could avoid implementation things to be visible/editable from the UI (the yaml)?

this is typically that could go into the status of the resource instead of the spec.

@@ -315,3 +315,8 @@ type PodInfoList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []PodInfo `json:"items"`
}

type KillerSpec struct {
// syscalls to kill
Copy link
Contributor

Choose a reason for hiding this comment

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

How about description: syscalls where killer is executed in?

AFAIU, these are the syscalls where we will load the killer and do the check on whether to "kill" the process or not.

@@ -433,6 +433,8 @@ message ProcessTracepoint {
// Arguments definition of the observed tracepoint.
// TODO: once we implement all we want, rename KprobeArgument to GenericArgument
repeated KprobeArgument args = 6;
// Action performed when the kprobe matched.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/kprobe/tracepoint/?

@@ -897,6 +898,95 @@ broken.

Socket tracking is only available on kernel >=5.3.

### Notify Killer action

The `NotifyKiller` action notifies the killer program to kill or override syscall.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The `NotifyKiller` action notifies the killer program to kill or override syscall.
The `NotifyKiller` action notifies the killer program to kill or override a syscall.

The `NotifyKiller` action notifies the killer program to kill or override syscall.

The specs needs to have `killer` program definition, that instructs tetragon to load
`killer` program and attach it to specified syscalls.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`killer` program and attach it to specified syscalls.
the `killer` program and attach it to specified syscalls.

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.

Thanks, only docs nits and agree with Kornilios points above!! The way your commits are done makes this really easy to review, would love to learn to do the same.

Comment on lines 929 to 930
If pecified the argError will be passed to `bpf_override_return` helper to override the syscall return value.
If pecified the argSig will be passed to `bpf_send_signal` helper to override the syscall return value.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
If pecified the argError will be passed to `bpf_override_return` helper to override the syscall return value.
If pecified the argSig will be passed to `bpf_send_signal` helper to override the syscall return value.
If specified the argError will be passed to `bpf_override_return` helper to override the syscall return value.
If specified the argSig will be passed to `bpf_send_signal` helper to override the syscall return value.

Comment on lines 966 to 1057
Note the `NotifyKiller` with killer program is meant to be used only on kernel versions
with no support for fast attach of multiple kprobes (`kprobe_multi` link).
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to move that to the very beginning, after the "The NotifyKiller action notifies the killer program to kill or override syscall." sentence? Also, could we have a little more details on the why of this feature? Why this is interesting and maybe useful for the reader?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I'll add some description at the beginning, thanks

Adding Validated field to ListSpec to ensure the validation goes
through just once, so it gets validated, sets the flag so another
sensor won't run it again.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Adding preValidateLists function that iterates all
the lists and validates them.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Passing symbol argument to kprobeAttach so we can use it
in followich changes with different symbols.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Adding LoadKprobeProgramAttachMany function that loads
kprobe program and attaches it to symbols provided in
array of strings.

Note the program gets loaded just once.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Add possibility to define killer in the schema like:

  killers:
  - syscalls:
    - "sys_dup"
      "sys.."

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Adding killer sensor that attaches to defined syscalls and
overrides them or/and kill the process.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Adding bpf_killer bpf program that allows to (when attached to syscall)
override syscall or kill current process.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Adding support to notify killer program attached to syscalls
with another action spec, like:

     matchActions:
     - action: "NotifyKiller"
       argError: -1
       argSig: 9

It's possible to specify error for override and signal number
to kill the current process with.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
So we can use it through kubectl.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Adding example killer policy that setups sys_enter raw syscalls
and add filter for sys_dup and sys_dup2 syscalls plus match for
/usr/bin/bash binary and kill it through killer.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Adding action field to tracepoint event, so it's available
in the event in case the action is triggered.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Catching up with kprobe/tracepoint event action enum definitions.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Adding test for killer sensor and testing both killing
application matching the selector and overriding syscall
that matches the selector.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
@olsajiri olsajiri merged commit c4cf61b into cilium:main Oct 12, 2023
33 checks passed
@kkourt kkourt added release-note/major This PR introduces major new functionality and removed release-note/minor This PR introduces a minor user-visible change labels Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/major This PR introduces major new functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants