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

New Rule Detect Linux Cgroup Container Escape Vulnerability (CVE-2022-0492) #1969

Merged
merged 4 commits into from
May 12, 2022

Conversation

darryk10
Copy link
Contributor

@darryk10 darryk10 commented Apr 13, 2022

This PR add a new rule to detect container escapes techniques (also used CVE-2022-0492 Linux Cgroup Container Escape Vulnerability) using new field available thread.cap_effective to check capabilities in the container which is part of the requirement for the exploitation.
Reference:
https://unit42.paloaltonetworks.com/cve-2022-0492-cgroups/
https://blog.trailofbits.com/2019/07/19/understanding-docker-container-escapes/

Signed-off-by: darryk10 [email protected]
Co-authored-by: Lorenzo Susini [email protected]

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

If contributing rules or changes to rules, please make sure to also uncomment one of the following line:

/kind rule-update

/kind rule-create

Any specific area of the project related to this PR?

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

/area build

/area engine

/area rules

/area tests

/area proposals

What this PR does / why we need it:
This PR add a new rule to detect container escapes techniques (also used CVE-2022-0492 Linux Cgroup Container Escape Vulnerability)
Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

rule(Detect release_agent File Container Escapes): new rule created to detect an attempt to exploit a container escape using release_agent file

@poiana poiana requested review from Kaizhe and leodido April 13, 2022 10:11
@poiana poiana added the size/S label Apr 13, 2022
@darryk10 darryk10 changed the title wip: New Rule Detect Linux Cgroup Container Escape Vulnerability (CVE-2022-4092) wip: New Rule Detect Linux Cgroup Container Escape Vulnerability (CVE-2022-0492) Apr 13, 2022
- rule: Linux Cgroup Container Escape Vulnerability (CVE-2022-0492)
desc: "Detect an attempt to exploit a container escape vulnerability in the Linux Kernel (CVE-2022-0492). By running a container with certains capabilities, a privileged user can modify release_agent file and escape from the container"
condition:
open_write and fd.name endswith release_agent and (user.uid=0 or thread.cap_permitted contains CAP_DAC_OVERRIDE) and excessively_capable_container
Copy link
Contributor

Choose a reason for hiding this comment

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

is this excessively_capable_container macro defined somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Then what non-default capabilities are needed for the exploit?

@Kaizhe
Copy link
Contributor

Kaizhe commented Apr 15, 2022

The prerequisite make it hard to exploit:
Quoted from the Unit42 blog:
As the root user, or without the no_new_privs flag; and
Without AppArmor or SELinux; and
Without Seccomp; and
On a host that enables unprivileged user namespaces; and
In a root v1 cgroup.

@darryk10
Copy link
Contributor Author

Thanks @Kaizhe for the review :)
I think it's worth noting this CVE (along with others) can be exploited in privileged container as well which increase the chance to get exploited.
In addition there are different container escaping techniques that use relase_agent file to reach container escaping. Some of those also found in malwares reported in the following link. The rule created checking the capabilities will trigger on those use cases as well.
https://blog.aquasec.com/threat-alert-container-escape

@jasondellaluce
Copy link
Contributor

/milestone 0.32.0

@poiana poiana added this to the 0.32.0 milestone Apr 15, 2022
@darryk10
Copy link
Contributor Author

@Kaizhe Looking at other techniques where release_agent file is involved. I figured out the same rule is effective for all the techniques which involve release_agent file (included the CVE-2022-0492). So I redesigned the rule to be generic on the release_agent file. Hope it's better now :)
References:
https://blog.trailofbits.com/2019/07/19/understanding-docker-container-escapes/
https://unit42.paloaltonetworks.com/cve-2022-0492-cgroups/

Thanks again

Kaizhe
Kaizhe previously approved these changes Apr 29, 2022
@poiana
Copy link
Contributor

poiana commented Apr 29, 2022

LGTM label has been added.

Git tree hash: 0df959df0be336a07ffa70df7fd2b2e76a94f3a8

@leogr leogr changed the title wip: New Rule Detect Linux Cgroup Container Escape Vulnerability (CVE-2022-0492) New Rule Detect Linux Cgroup Container Escape Vulnerability (CVE-2022-0492) May 4, 2022
@leogr
Copy link
Member

leogr commented May 4, 2022

Closing and reopening to trigger the CI
/close

@poiana poiana closed this May 4, 2022
@poiana
Copy link
Contributor

poiana commented May 4, 2022

@leogr: Closed this PR.

In response to this:

Closing and reopening to trigger the CI
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@leogr
Copy link
Member

leogr commented May 4, 2022

/reopen

@poiana
Copy link
Contributor

poiana commented May 4, 2022

@leogr: Reopened this PR.

In response to this:

/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@poiana poiana reopened this May 4, 2022
@FedeDP FedeDP mentioned this pull request May 9, 2022
53 tasks
Copy link
Member

@leogr leogr left a comment

Choose a reason for hiding this comment

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

I think that tests are failing because the driver version used by this PR is still caa0e4d0044fdaaebab086592a97f0c7f32aeaa9. IIRC, thread.cap_effective was introduced later.

If so, rebasing this PR on top of the current master branch should solve the issue.
@darryk10 could you rebase this PR, please?

Signed-off-by: darryk10 <[email protected]>
Co-authored-by: Lorenzo Susini <[email protected]>
darryk10 added 3 commits May 12, 2022 11:42
Signed-off-by: darryk10 <[email protected]>
Co-authored-by: Lorenzo Susini <[email protected]>
Signed-off-by: darryk10 <[email protected]>
Co-authored-by: Lorenzo Susini <[email protected]>
Copy link
Member

@leogr leogr left a comment

Choose a reason for hiding this comment

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

Great, after the rebase, it works 👍

/approve

@poiana
Copy link
Contributor

poiana commented May 12, 2022

LGTM label has been added.

Git tree hash: 3fec78695d250747677d1877c4d6fd4af9ece392

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
Contributor

poiana commented May 12, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: darryk10, jasondellaluce, leogr

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 merged commit 3e60318 into falcosecurity:master May 12, 2022
@darryk10 darryk10 deleted the new_rule_cve_2022_4092 branch May 12, 2022 12:43
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