Skip to content

Changes to support aarch64 (64-bit ARM) and s390x (zLinux) architectures - #84

Closed
jcpittman144 wants to merge 36 commits into
falcosecurity:masterfrom
draios:agent-libs-aarch64-s390x-support
Closed

jcpittman144 wants to merge 36 commits into
falcosecurity:masterfrom
draios:agent-libs-aarch64-s390x-support

Conversation

@jcpittman144

Copy link
Copy Markdown
Contributor

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 build

/area driver-kmod

/area driver-ebpf

/area libscap

/area libsinsp

/area tests

/area proposals

What this PR does / why we need it:
Changes needed for Sysdig agent to support aarch64 (64-bit ARM) and s390x (zLinux) architectures.

Which issue(s) this PR fixes:

Fixes SSPROD-7548
Fixes SSPROD-6955

Special notes for your reviewer:

  • Remove Little-Endian byte-order assumptions in HTTP header parsing and IP address checking logic.
  • Extend use of existing mechanisms -- volatile variable, masking -- to allow eBPF probe to be accepted by kernel verifier
  • Adjust set of LUA APIs used, to allow interoperability with the different LUA versions available for the different architectures.

Does this PR introduce a user-facing change?:

Sysdig agent is now supported on 64-bit ARM Linux systems.
Sysdig agent is now supported on IBM zLinux systems.

jcpittman144 and others added 30 commits September 17, 2021 13:21
…ailable

If Linux kernel is built with CONFIG_AUDIT=n, /proc loginuid file is not
available to provide the loginuid of the process.  Instead of failing to
add process into libscap thread table, record process loginuid=-1 instead.
Changes to support tracking how a container was configured with an
initial user and make that info available as user.name for
CONTAINER_JSON events:

1. Add a "container user" field m_container_user to container_info. By
default, the value is "<NA>".
2. In the docker and cri container engine resolvers, parse any
configured user info out of the json response and set
m_container_user.
3. Serialize the parsed username to the json blob that comprises a
CONTAINER_JSON event, and parse it out of the json blob when parsing a
CONTAINER_JSON event.
4. When creating the fake threadinfo that is attached to a container
event, also set m_exe to "container:<id>".
5. For the proc.name filtercheck, if the event type is container_json,
return not the thread uid but the container user.

This ends up being more robust in the face of containers where the
initial process might exec and then setuid than a different user. This
tracks the configured user rather than the uids of processes in the
container, which might change.
- Support terminating scan after specified timeout
- Support periodic log messages to report progress
- API to specify timeout, log interval, and log function
- Add last PID and total FDs processed, to /proc scan progress messages
- Enhance scap_open args and logic to record debug_log_fn and parameters
- Reworked /proc scan to reduce complexity and nesting depth
- Pass through API to specify log/timeout parameters to libscap /proc scan
This should explain the purpose of this class better
Rootless podman containers have multiple sockets (one per user
account), and we don't really want to spawn a separate thread
for each user.

This means that we can no longer use a single CURL handle but need
to create a new one for each individual request.
All the platform-specific code from docker_async_source is moved
to a new docker_connection class. The interface is almost identical,
so keep a single header file with two separate implementation files
(one for Linux, one for Windows).
This is a private implementation detail of the connection
class. Also, this fixes a but where (on Windows) we appended
`?size=true` to the wrong place in the request (to the Host
header, not the URL).
We need full control over the request to make this method
suitable for putting in a base class.
All the code after the initial docker container detection
is platform-agnostic and can be moved to a base class.
Now we're ready to make clean OS-specific subclasses.
They have different interfaces and different implementations,
keeping both under the same name doesn't really avoid
any duplication
Since it's very similar to Docker (modulo some quirks handled by
the previous commit), it inherits almos all the code from `docker_base`.

The cgroup detection for non-root containers is done manually
and due to the limitations of our driver (not easily bypassed),
we have to fall back to parsing cgroups files manually.
When opening a capture based on a fd (e.g. sinsp::fdopen), we cannot
reopen the capture by simply calling close/open_int, as gzclose()
at the end of the call chain originating from close() closes the file
descriptor and we cannot access it again.

So when we're reopening a fd-based capture, dup() the original fd,
lseek() it to the beginning and substitute it for the closed one.
If a container is started e.g. as `docker.io/library/httpd`,
this is what ends up in container.m_image. Then we match m_image
against the names on the container image list, but they always
have a tag, e.g. `docker.io/library/httpd:latest` so they won't
match the name without a tag.

Fix it by:
- defaulting to the `latest` tag a bit earlier (before fetching
  the image list)
- using repo + ':' + tag as the string to match to always have
  the tag in the name to compare
gnosek and others added 6 commits September 17, 2021 13:22
While these two are apparently always the same, we check .Image
for the '/' and then we parse .Config.Image.

Switch to parsing .Image for somewhat reduced confusion.
This got broken when adding Podman support. The original code involved
multiple layers negations and while trying to understand the code,
I got the logic wrong. This got exposed when running a container
using the image id instead of the image name: we mistakenly reported
the image repo/tag as sha256/<image id>.
The image id (with or without the `sha256:` prefix) is at least
as long as the requested image id (which can be a substring
of the full id), so the proper logic is "does the full id
start with the requested id", not the other way round.
- Fix little-endian byte order assumptions in HTTP header parsing
  and IP address checking logic
- Expand use of existing techniques (volatile, masking) in eBPF probe to
  pass kernel verifier on aarch64 systems
- Update LUA code to interoperate with the LUA toolchain versions used in
  s390x and aarch64 docker images
@poiana

poiana commented Sep 20, 2021

Copy link
Copy Markdown
Contributor

Thanks for your pull request. Before we can look at it, you'll need to add a 'DCO signoff' to your commits.

📝 Please follow instructions in the contributing guide to update your commits with the DCO

Full details of the Developer Certificate of Origin can be found at developercertificate.org.

The list of commits missing DCO signoff:

  • d43d79c Fill thread loginuid with default value -1, if /proc loginuid is unavailable
  • 9f1174c parse other container variables in static container
  • f03e3c6 Track container user info and expose via user.name (update: clang format file name #7)
  • f335ba4 Enhancements to initial scan of /proc, for supportability
  • fb8d651 Rename docker_async_instruction to docker_lookup_request
  • 9d6076f Fix comparison of docker_lookup_requests
  • cc64620 Pass container_id as a const ref to docker_lookup_request ctor
  • 0491927 Move docker_lookup_request to a separate file
  • 7138ee4 Pass docker socket to the async engine separately for each request
  • 337c288 Move platform-specific Docker-API code to a separate class
  • b041084 Remove docker_connection::build_request
  • 434f151 Move docker_async_source to its own source file
  • 1910a45 Pass a complete request to parse_docker_async
  • c1ebc13 Move most of docker::resolve to a new method
  • 884f4ef Move common docker bits to a base class
  • e140eff Split Linux/Windows docker implementations
  • 49eff79 Split docker_async_source::parse_docker into helper methods
  • 7cfc81f Support Podman quirks in docker_async_source
  • 4526715 Support Podman container engine
  • be23d36 Add a podman_owner_uid label for rootless Podman containers
  • 305a66e Actually enable the Podman engine
  • 78e0716 Support sinsp::restart_capture_at_filepos for fd-based captures
  • baef089 add presubmit
  • 0ff04fc remove unnecessary buil;d builder option
  • 4659dd9 Match Podman images including the tag
  • 0e5db76 Log the socket used to contact the Docker/Podman daemon
  • e1fb268 SSPROD-7609, create sinsp_evt copy routine
  • 061f51f bug/dup code removed
  • 0eb6b7e make sinsp_threadinfo tinfo as const in populate_cmdline
  • 7ed202f review comments
  • 2416743 Split the right image id for podman containers
  • 86bdf22 Fix inverted logic when checking whether image name is the id
  • 6be1128 Flip the parameters to startswith when comparing image ids
  • b6270e2 Extend the comment about running containers with image ids
  • 5c82cee Initialize m_ptid when initializing other vars
  • d5cf86b Changes to support aarch64 (64-bit ARM) and s390x (zLinux) architectures
Details

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. I understand the commands that are listed here.

@poiana

poiana commented Sep 20, 2021

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jcpittman144
To complete the pull request process, please assign leogr after the PR has been reviewed.
You can assign the PR to them by writing /assign @leogr in a comment when ready.

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

Details 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 commented Sep 20, 2021

Copy link
Copy Markdown
Contributor

Hi @jcpittman144. 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.

Details

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.

@jcpittman144

Copy link
Copy Markdown
Contributor Author

Retracting this PR.
I'm trying to submit to the draios/agent-libs repo, not the falcosecurity/libs repo.

@jcpittman144
jcpittman144 deleted the agent-libs-aarch64-s390x-support branch September 20, 2021 17:05
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.

6 participants