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: Move return filter to kernel #1773

Merged
merged 14 commits into from
Dec 14, 2023
Merged

Conversation

olsajiri
Copy link
Contributor

@olsajiri olsajiri commented Nov 20, 2023

moving the return filter to bpf program and adding support for return actions

@olsajiri olsajiri added the release-note/minor This PR introduces a minor user-visible change label Nov 20, 2023
@olsajiri olsajiri force-pushed the pr/olsajiri/retkprobe_filter branch 8 times, most recently from 3dae4f7 to 566fa50 Compare November 21, 2023 12:07
@olsajiri olsajiri force-pushed the pr/olsajiri/retkprobe_filter branch from 566fa50 to eb1552a Compare November 29, 2023 09:07
Copy link

netlify bot commented Nov 29, 2023

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit 2c84752
🔍 Latest deploy log https://app.netlify.com/sites/tetragon/deploys/65797793d10a990008f01692
😎 Deploy Preview https://deploy-preview-1773--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 pr/olsajiri/retkprobe_filter branch 5 times, most recently from 4e18f76 to 20416b3 Compare December 4, 2023 11:37
@olsajiri olsajiri changed the title retkprobe filter tetragon: Move return filter to kernel Dec 4, 2023
@olsajiri olsajiri requested review from kkourt and tpapagian December 4, 2023 12:16
@olsajiri olsajiri marked this pull request as ready for review December 4, 2023 12:17
@olsajiri olsajiri requested review from a team and mtardy as code owners December 4, 2023 12:17
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.

Thanks! This looks good overall.

Just some minor comments.

Also: was this #1781 (comment) resolved? Would be nice to reject the tracing policy early if something is not supported.

prog.Close()

if err != nil {
signalHelper.detected = false
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this seems redundant, since we are setting it based on the return value in the caller.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true, fixed.. I copy/pasted this from another helper, so I changed that one as well ;-)

retFilterMap := program.MapBuilderPin("filter_map", sensors.PathJoin(pinPath, "retprobe_filter_map"), loadret)
maps = append(maps, retFilterMap)

maps = append(maps, filterMaps(loadret, pinPath, nil)...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I understand this.

So we append filterMaps(loadret, pinPath, nil) which will always return []*program.Map{}, AFAICT.

func filterMaps(load *program.Program, pinPath string, kprobeEntry *genericKprobe) []*program.Map {
	var maps []*program.Map

	state := getProgramSelector(load, kprobeEntry)
	if state == nil {
		return []*program.Map{}
	}

And:

func getProgramSelector(load *program.Program, kprobeEntry *genericKprobe) *selectors.KernelSelectorState {
	if kprobeEntry != nil {
		if load.RetProbe {
			return kprobeEntry.loadArgs.selectors.retrn
		}
		return kprobeEntry.loadArgs.selectors.entry
	}
	return nil
}

Can't we just remove this line the append here? (And maybe the nil check in the calling functions)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right..good catch.. the state is needed for single kprobe where we can fix maximums for kernel < 5.9, so it's not needed for multi kprobe which is available for later kernels, so there's no need for this fixes.. I'll make the fix and add comment

@olsajiri
Copy link
Contributor Author

olsajiri commented Dec 8, 2023

Thanks! This looks good overall.

Just some minor comments.

Also: was this #1781 (comment) resolved? Would be nice to reject the tracing policy early if something is not supported.

ugh, forgot about this one.. sry, added PR #1863

@olsajiri olsajiri force-pushed the pr/olsajiri/retkprobe_filter branch from 20416b3 to 9089df7 Compare December 8, 2023 12:12
@kkourt kkourt added the needs-rebase This PR needs to be rebased because it has merge conflicts. label Dec 11, 2023
@olsajiri olsajiri force-pushed the pr/olsajiri/retkprobe_filter branch from 9089df7 to 7ba1d1f Compare December 11, 2023 11:42
@olsajiri
Copy link
Contributor Author

@kkourt the signal helper detection got in through another PR without the fixes.. adding the fix in:
2d6ab87 tetragon: Fix detectOverrideHelper/detectSignalHelper cleanup path

@olsajiri olsajiri force-pushed the pr/olsajiri/retkprobe_filter branch from 7ba1d1f to 2c84752 Compare December 13, 2023 09:21
@mtardy mtardy removed the needs-rebase This PR needs to be rebased because it has merge conflicts. label Dec 13, 2023
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.

this looks good! thanks!

pkg/bpf/detect.go Show resolved Hide resolved
pkg/bpf/detect.go Show resolved Hide resolved
pkg/sensors/tracing/generickprobe.go Show resolved Hide resolved
@olsajiri olsajiri force-pushed the pr/olsajiri/retkprobe_filter branch from 2c84752 to 7141da5 Compare December 13, 2023 13:39
Move the prog.Close() to success path and remove superfluous
detected bool assignment.

Also there's no reason to use defer in detectLargeProgramSize.

Signed-off-by: Jiri Olsa <[email protected]>
@olsajiri olsajiri force-pushed the pr/olsajiri/retkprobe_filter branch from 7141da5 to 4be83ca Compare December 13, 2023 15:00
@olsajiri
Copy link
Contributor Author

hum, I think the 32 bit change that got merged blocked this change, because we cross the instructions limit for filter program on small kernels.. we'll need to split the filtering logic and then merge this change

Move the selector state instance under kprobeSelectors object,
because we are adding return selector in following changes so
this way both states object are stored together.

Signed-off-by: Jiri Olsa <[email protected]>
Adding MatchReturnActions selector data so we can specify actions
when return matcher passes.

It's allows same actions as MatchAction matcher.

Signed-off-by: Jiri Olsa <[email protected]>
Adding InitKernelReturnSelectorState function that creates return
probe kernel selector state object.

Signed-off-by: Jiri Olsa <[email protected]>
Adding support to create and load return selector into filter maps.

Signed-off-by: Jiri Olsa <[email protected]>
Adding tests for return selectors defined:
  - as empty
  - with return value matches in 2 int values
  - with return follow fd action

Signed-off-by: Jiri Olsa <[email protected]>
Adding support for filter in return kprobe object.

Adding filter and action tail calls to handle return probe filter
and possible actions.

Signed-off-by: Jiri Olsa <[email protected]>
Now that we have return argument filter support in kernel, we no longer
need the user space support, removing it.

Due to bpf filter program complexity we can't load GT/LT filters in 4.19
kernels, so I'm disabling GT/LT tests for 4.19 kernels. Let's see if that's
a real problem before we get to fun of mixing user and kernel filtering
for 4.19 kernels and newer ones.

Signed-off-by: Jiri Olsa <[email protected]>
Adding return action field to ProcessKprobe message
to pass the return action value to final event.

Signed-off-by: Jiri Olsa <[email protected]>
Storing the return action value to final merged kprobe event.

Signed-off-by: Jiri Olsa <[email protected]>
Moving TestKprobeSigkill functionality to testSigkill function,
so it can be used be following change.

Signed-off-by: Jiri Olsa <[email protected]>
Adding sigkill return action test that is triggered
by return lseek kprobe.

Signed-off-by: Jiri Olsa <[email protected]>
Updating the selectors docs with return actions info.

Signed-off-by: Jiri Olsa <[email protected]>
@olsajiri olsajiri force-pushed the pr/olsajiri/retkprobe_filter branch from 4be83ca to a8bde06 Compare December 13, 2023 17:22
Some of the killer tests are missing signal helper checks,
adding them.

Signed-off-by: Jiri Olsa <[email protected]>
@olsajiri olsajiri force-pushed the pr/olsajiri/retkprobe_filter branch from 2990435 to 8a07d09 Compare December 14, 2023 07:58
@olsajiri
Copy link
Contributor Author

hum, I think the 32 bit change that got merged blocked this change, because we cross the instructions limit for filter program on small kernels.. we'll need to split the filtering logic and then merge this change

ok, managed to reorg the code a bit and we're still good ;-) but I'll start on the filter re-work anyway

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.

Thanks!

@kkourt kkourt merged commit 092ca5c into main Dec 14, 2023
32 checks passed
@kkourt kkourt deleted the pr/olsajiri/retkprobe_filter branch December 14, 2023 13:53
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