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

cleanup(rules)!: refactor kernel module rule #43

Merged
merged 2 commits into from
Apr 4, 2023

Conversation

incertum
Copy link
Contributor

@incertum incertum commented Mar 31, 2023

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind feature

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area rules

/area registry

/area build

/area documentation

What this PR does / why we need it:

Rule "Linux Kernel Module Injection Detected" is limited in scope.
A major refactor of Falco now exposes each syscall Falco's libs supports (including init_module) to the end user :)
Official support starts with Falco 0.35.0.

Which issue(s) this PR fixes:

falcosecurity/falco#2443 (comment)

Fixes #

Special notes for your reviewer:

CC @loresuso @LucaGuerra @jasondellaluce

cleanup(rules)!: refactor kernel module rule

A major refactor of Falco now exposes each syscall Falco's libs
supports to the end user :)

Official support starts with Falco 0.35.0

Signed-off-by: Melissa Kilby <[email protected]>
output: Linux Kernel Module injection using insmod detected (user=%user.name user_loginuid=%user.loginuid parent_process=%proc.pname module=%proc.args %container.info image=%container.image.repository:%container.image.tag)
condition: ((spawned_process and proc.name=insmod) or init_module)
and container
and not proc.args in (white_listed_modules)
Copy link
Member

Choose a reason for hiding this comment

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

Nice, thanks for noticing!
Btw, I am thinking that maybe it's time to change this rule and make it even better.
I would like to drop the part of the condition relying on insmod, and use instead the related syscalls, which is of course init_module but also finit_module (which is what my insmod is using). wdyt? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @loresuso this is great! Done :)

Copy link
Member

@loresuso loresuso Apr 3, 2023

Choose a reason for hiding this comment

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

Nice! One last thing convertingwhite_listed_modules into an allowed_container_images_loading_kernel_module list and add it to the condition with and not and it's perfect for me!

@incertum incertum changed the title cleanup(rules): improve kernel module rule cleanup(rules)!: refactor kernel module rule Apr 3, 2023
@@ -3147,13 +3150,14 @@
enabled: false
tags: [host, container, network, mitre_command_and_control, TA0011]

- list: white_listed_modules
Copy link
Contributor

@Kaizhe Kaizhe Apr 3, 2023

Choose a reason for hiding this comment

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

how are we going to handle the whitelisted kernel modules

Copy link
Member

Choose a reason for hiding this comment

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

For me now given that the rule is changing, it makes sense having a whitelist on container images that can load modules

Copy link
Contributor

Choose a reason for hiding this comment

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

did you add it in the condition

Copy link
Member

Choose a reason for hiding this comment

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

no, that's what I was asking (see above), let's wait for Melissa :)

Copy link
Contributor

Choose a reason for hiding this comment

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

with the whitelisted images (e.g. falco), I think we're good to go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added, this is great feedback, ty :)

Since Falco 0.35 only alert on respective syscalls (init_module, finit_module).
Deprecate alerting on spawned_process and insmod as proc.name.

Co-authored-by: Lorenzo Susini <[email protected]>
Signed-off-by: incertum <[email protected]>
@incertum incertum force-pushed the kernel-module-rule branch from c5b08d8 to 3723314 Compare April 4, 2023 06:41
Copy link
Member

@loresuso loresuso left a comment

Choose a reason for hiding this comment

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

Nice! /approve

@poiana
Copy link

poiana commented Apr 4, 2023

LGTM label has been added.

Git tree hash: e0d44b38085b14a75df4f75f074e57a85ba287b4

Copy link
Contributor

@jasondellaluce jasondellaluce left a comment

Choose a reason for hiding this comment

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

/approve

@poiana
Copy link

poiana commented Apr 4, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: incertum, jasondellaluce, loresuso

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

The pull request process is described here

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 added the approved label Apr 4, 2023
@poiana poiana merged commit 8780d9d into falcosecurity:main Apr 4, 2023
@jasondellaluce
Copy link
Contributor

Note for us: renaming the macro can represent a breaking change. Let's keep this in mind for the next falco_rules release.

@Kaizhe
Copy link
Contributor

Kaizhe commented Apr 4, 2023

Note for us: renaming the macro can represent a breaking change. Let's keep this in mind for the next falco_rules release.

Maybe let's revert the macro, we should probably give a heads up in the release notes (saying this macro will be deprecated in release 3.8 or 9)

@jasondellaluce jasondellaluce added this to the falco-rules-1.0.0 milestone Jun 20, 2023
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.

5 participants