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

update: add open_by_handle_at syscall #148

Merged

Conversation

Andreagit97
Copy link
Member

@Andreagit97 Andreagit97 commented Dec 3, 2021

What type of PR is this?

/kind feature

Any specific area of the project related to this PR?

/area driver-kmod

/area driver-ebpf

/area libscap

/area libsinsp

What this PR does / why we need it:

This adds support to the open_by_handle_at syscall. This has been reported as a high priority missing syscall in the "umbrella issue" 👇

falcosecurity/falco#676

Which issue(s) this PR fixes:

Special notes for your reviewer:

The following sample program has been used for testing:

main.c.txt

  1. Compile main.c:
gcc main.c -o main
  1. Create the file to open where you want.

  2. Run main passing as argument the absolute file path or the path relative to the current working directory of the calling process:

./main <path>

Open_by_hanlde_at path extraction

We have chosen to extract the absolute path of the opened file from the file descriptor returned by the syscall. In case of error, the file descriptor is not valid so unfortunately, we cannot extract the file path. The file descriptor seems the smartest way to extract information about the path, given the little information provided by the syscall.

Bpf testing

I have tested the new bpf features on the following vagrant images:

  1. Image = bento/amazonlinux-2
  • Kernel = 4.14.198-152.320.amzn2.x86_64
  • clang = clang version 11.1.0
  1. Image = generic/debian10
  • Kernel = 4.19.0-18-amd64
  • clang = clang version 7.0.1-8+deb10u2
  1. Image = generic/centos8
  • Kernel = 4.18.0-348.2.1.el8_5.x86_64
  • clang = clang version 12.0.1
  1. Image = generic/fedora33
  • Kernel = 5.14.18-100.fc33.x86_64
  • clang = clang version 11.0.0 (Fedora 11.0.0-3.fc33)
  1. Image = generic/alpine314
  • Kernel = 5.10.82
  • clang = clang version 11.1.0
  1. Image = bento/ubuntu-20.10
  • Kernel = 5.8.0-63-generic
  • clang = clang version 11.0.0-2
  1. Image = bento/ubuntu-21.04
  • Kernel = 5.14.0-051400-generic
  • clang = clang version 12.0.0
  1. Image = opensuse/Tumbleweed.x86_64
  • Kernel = 5.15.6
  • clang = clang version 13.0.0

Old kernels verifiers (like 4.14) allow reading only file paths consisting of at most 16 components. With more than 16 components the verifier complains about the excessive bpf program length due to the loop unrolling approach used in the new bpf_get_path function. The function bpf_get_path added in this pull request, is an attempt to collect the file path from the file descriptor. Kernel 5.10 introduced a new bpf_helper called bpf_d_path which however cannot be used by BPF_PROG_TYPE_RAW_TRACEPOINT programs. Unfortunately, in our case, libscap loads all bpf programs as BPF_PROG_TYPE_RAW_TRACEPOINT.

Does this PR introduce a user-facing change?:

update: add support for `open_by_handle_at` syscall

@poiana
Copy link
Contributor

poiana commented Dec 3, 2021

Hi @Andreagit97. Thanks for your PR.

I'm waiting for a falcosecurity member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

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.

Great work! Left a couple of comments.

driver/bpf/filler_helpers.h Outdated Show resolved Hide resolved
driver/bpf/filler_helpers.h Show resolved Hide resolved
driver/bpf/fillers.h Outdated Show resolved Hide resolved
driver/ppm_fillers.c Outdated Show resolved Hide resolved
userspace/libsinsp/filterchecks.cpp Outdated Show resolved Hide resolved
userspace/libsinsp/filterchecks.cpp Outdated Show resolved Hide resolved
@leogr
Copy link
Member

leogr commented Dec 7, 2021

/ok-to-test

Andrea Terzolo and others added 6 commits March 11, 2022 13:53
Signed-off-by: Andrea Terzolo <[email protected]>
Co-authored-by: Jason Dellaluce <[email protected]>
Signed-off-by: Andrea Terzolo <[email protected]>
Co-authored-by: Jason Dellaluce <[email protected]>
Old kernels (like 4.14) have too strict limits on the bpf program length to support 32 path components. For the moment we decrease the limit to 16.

Signed-off-by: Andrea Terzolo <[email protected]>
@Andreagit97 Andreagit97 force-pushed the add_open_by_handle_at_syscall branch from c6d3627 to 27b8295 Compare March 11, 2022 12:59
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.

/approve

@poiana
Copy link
Contributor

poiana commented Mar 11, 2022

LGTM label has been added.

Git tree hash: 4deec2c4aac411d09ff71f3647d52fcb6a8a423c

@poiana
Copy link
Contributor

poiana commented Mar 11, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Andreagit97, 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

@ldegio ldegio self-requested a review March 11, 2022 20:29
@poiana poiana merged commit ce83ef8 into falcosecurity:master Mar 11, 2022
@Andreagit97 Andreagit97 deleted the add_open_by_handle_at_syscall branch May 24, 2022 17:24
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