<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Falco – Falco Libs</title><link>https://v0-43--falcosecurity.netlify.app/tags/falco-libs/</link><description>Recent content in Falco Libs on Falco</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Thu, 21 Sep 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://v0-43--falcosecurity.netlify.app/tags/falco-libs/feed.xml" rel="self" type="application/rss+xml"/><item><title>Blog: Introducing a framework for regression testing against Linux kernels</title><link>https://v0-43--falcosecurity.netlify.app/blog/falco-kernel-testing/</link><pubDate>Thu, 21 Sep 2023 00:00:00 +0000</pubDate><guid>https://v0-43--falcosecurity.netlify.app/blog/falco-kernel-testing/</guid><description>
&lt;p&gt;There are a few foundational technologies that empower the Cloud Native ecosystem. Containers is one. And one of the basis for containerization is the Linux Kernel itself. With Falco, we are developing a runtime security tool that hooks directly in the kernel to collect information about the system and notifies about malicious behavior.&lt;br&gt;
We have found the need to validate our drivers against various versions of the Linux kernel, to properly ensure that with each iteration of our drivers, supported kernels remained unaffected.&lt;br&gt;
To elaborate, we lacked a means to guarantee that a new driver release could:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Successfully compile on multiple kernel versions.&lt;/li&gt;
&lt;li&gt;Pass the eBPF verifier when executed on various kernel versions.&lt;/li&gt;
&lt;li&gt;Operate as expected, such as retrieving kernel events, across multiple kernel versions.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To address this issue, we started a major intervention. Initially, a &lt;a href="https://github.com/falcosecurity/libs/blob/master/proposals/20230530-driver-kernel-testing-framework.md"&gt;proposal&lt;/a&gt; was discussed and incorporated into the libs repository.&lt;/p&gt;
&lt;p&gt;Since this was a pretty novel area, there were no pre-existing tools available to tackle it. Consequently, we embarked on the development of a completely new framework.&lt;br&gt;
Allow us to introduce you to the &lt;code&gt;kernel testing framework&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id="components-of-a-kernel-testing-framework"&gt;Components of a kernel testing framework&lt;/h3&gt;
&lt;p&gt;Considering the inherent characteristics of the challenge, we need to set up a complete virtual machine for each distinct kernel version.&lt;br&gt;
These tests should be executed automatically each time new code is integrated into our drivers, serving as a means to promptly identify any issue or flaw in the tested kernel versions.&lt;br&gt;
With these objectives in mind, our approach should fulfill the following requirements:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Rapid and cost-effective VM creation: the process of creating these virtual machines should be efficient and budget-friendly.&lt;/li&gt;
&lt;li&gt;Effortless distribution of VM images: we should ensure easy sharing and deployment of the virtual machine images.&lt;/li&gt;
&lt;li&gt;Parallel execution of tests on multiple VMs: tests should run concurrently on each virtual machine to expedite the process.&lt;/li&gt;
&lt;li&gt;Reproducibility in local environments for debugging purposes: developers should be able to replicate the test environment locally to investigate and troubleshoot issues.&lt;/li&gt;
&lt;li&gt;Straightforward and user-friendly presentation of the test results: they should be presented in a simple and intuitive manner to immediately spot failures.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="ignite-a-firecracker-microvm"&gt;Ignite a Firecracker microVM&lt;/h4&gt;
&lt;p&gt;&lt;a href="https://https://github.com/weaveworks/ignite"&gt;Weave Ignite&lt;/a&gt; is used to provision the &lt;a href="https://github.com/firecracker-microvm/firecracker"&gt;firecracker&lt;/a&gt; microVMs. Weave Ignite is an open source tool designed for lightweight and fast virtual machine management. It enables users to effortlessly create and manage virtual machines (VMs) for various purposes, such as development, testing, and experimentation.
One of the main reasons why we chose to use this tool was its capability to create firecracker microVMs from kernels and rootfs packed as OCI images.
Currently, we are using a patched version located at &lt;a href="https://github.com/therealbobo/ignite"&gt;a forked repository&lt;/a&gt;. These patches were essential to enable the booting of kernels that necessitated the use of an initrd (initial ramdisk).&lt;/p&gt;
&lt;h4 id="kernel-rootfs-oci-images"&gt;Kernel &amp;amp; Rootfs OCI images&lt;/h4&gt;
&lt;p&gt;Virtual machines consist of two essential layers: the kernel and the rootfs. These layers are packaged and distributed as OCI (Open Container Initiative) images. The kernel image encompasses the kernel that the virtual machine relies on, in contrast the rootfs image serves as the fundamental building block of a virtual machine, offering the essential filesystem necessary for booting the VM. Typically, these rootfs images incorporate a Linux distribution.
For more info on how we build them please check the available &lt;a href="https://github.com/falcosecurity/kernel-testing/tree/main/images"&gt;images documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id="ansible-playbooks"&gt;Ansible Playbooks&lt;/h4&gt;
&lt;p&gt;Automation is accomplished through the utilization of &lt;a href="https://docs.ansible.com/ansible/latest/index.html"&gt;Ansible&lt;/a&gt;. A collection of &lt;a href="https://github.com/falcosecurity/kernel-testing/tree/main/ansible-playbooks"&gt;playbooks&lt;/a&gt; is responsible for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Orchestrating the provisioning of microVMs.&lt;/li&gt;
&lt;li&gt;Configuring the machines.&lt;/li&gt;
&lt;li&gt;Retrieving the code to be tested.&lt;/li&gt;
&lt;li&gt;Eliminating the microVMs once the testing process is completed.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="presenting-test-results"&gt;Presenting test results&lt;/h4&gt;
&lt;p&gt;We wanted the test data to be publicly and easily accessible by anyone, thus we had to find a way to represent the test output.&lt;br&gt;
Since there are 3 possible ways of instrumenting the kernel, that are using a kernel module or one of the available eBPF probes, the playbooks perform up to 3 tests. Taking into account that the modern eBPF probe is built in the Falco libraries, only 2 drivers need to be compiled.
We have 3 possible results for each of them:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;success, when the test goes fine&lt;/li&gt;
&lt;li&gt;error, when the test fails&lt;/li&gt;
&lt;li&gt;skipped, when the test is not runnable for the kernel (for example, skipping modern eBPF tests where it is unsupported)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The natural way of dealing with all of this was to develop a &lt;a href="https://github.com/falcosecurity/kernel-testing/tree/main/matrix_gen"&gt;small tool&lt;/a&gt; that, given as input the output root folder, would generate a markdown matrix with the results.&lt;/p&gt;
&lt;p&gt;While scrutinizing the first version of the markdown matrix, we understood that it would have been even better if errors were also attached to the markdown, allowing for a more streamlined visualization of the results.&lt;br&gt;
This is the format we settled with; it can be found &lt;a href="https://falcosecurity.github.io/libs/matrix_X64/"&gt;at libs github pages&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src="images/matrix.png" alt="" loading="lazy" /&gt;
&lt;/p&gt;
&lt;h3 id="how-we-use-it"&gt;How we use it&lt;/h3&gt;
&lt;p&gt;We implemented a new Github action workflow in the libs repository that triggers on pushes to master, using an x86_64 and an aarch64 nodes with virtualization capabilities provided by the CNCF.&lt;br&gt;
The &lt;a href="https://github.com/falcosecurity/libs/blob/master/.github/workflows/kernel_tests.yaml"&gt;workflow&lt;/a&gt; itself is very simple since it runs the testing framework on self-hosted nodes just like you would run it locally:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code class="language-yaml=" data-lang="yaml="&gt;jobs:
test-kernels:
strategy:
fail-fast: false
matrix:
architecture: [X64, ARM64] # We use a matrix to run our job on both supported arch
# Since github actions do not support arm64 runners and they do not offer virtualization capabilities, we need to use self hosted nodes.
runs-on: [ &amp;#34;self-hosted&amp;#34;, &amp;#34;linux&amp;#34;, &amp;#34;${{matrix.architecture}}&amp;#34; ]
steps:
# We clone the kernel-testing repo, generate vars.yaml (ie: input options for the kernel-testing run)
# and run needed ansible playbooks one by one, directly on each node.
- name: Checkout
uses: actions/checkout@v3
with:
repository: falcosecurity/kernel-testing
ref: v0.2.3
- name: Generate vars yaml
working-directory: ./ansible-playbooks
run: |
LIBS_V=${{ github.event.inputs.libsversion }}
LIBS_VERSION=${LIBS_V:-${{ github.ref_name }}}
cat &amp;gt; vars.yml &amp;lt;&amp;lt;EOF
run_id: &amp;#34;id-${{ github.run_id }}&amp;#34;
output_dir: &amp;#34;~/ansible_output_${{ github.run_id }}&amp;#34;
repos:
libs: {name: &amp;#34;falcosecurity-libs&amp;#34;, repo: &amp;#34;https://github.com/falcosecurity/libs.git&amp;#34;, version: &amp;#34;$LIBS_VERSION&amp;#34;}
EOF
- name: Bootstrap VMs
working-directory: ./ansible-playbooks
run: |
ansible-playbook bootstrap.yml --extra-vars &amp;#34;@vars.yml&amp;#34;
- name: Common setup
working-directory: ./ansible-playbooks
run: |
ansible-playbook common.yml --extra-vars &amp;#34;@vars.yml&amp;#34;
- name: Prepare github repos
working-directory: ./ansible-playbooks
run: |
ansible-playbook git-repos.yml --extra-vars &amp;#34;@vars.yml&amp;#34;
- name: Run scap-open tests
working-directory: ./ansible-playbooks
run: |
ansible-playbook scap-open.yml --extra-vars &amp;#34;@vars.yml&amp;#34; || :
# Once test finished, we collect its output folder and upload it to the github workflow space
- name: Tar output files
run: |
tar -cvf ansible_output.tar ~/ansible_output_${{ github.run_id }}
- uses: actions/upload-artifact@v3
with:
name: ansible_output_${{matrix.architecture}}
path: ansible_output.tar
# We then build the matrix and upload them too
- name: Build matrix_gen
working-directory: ./matrix_gen
env:
GOPATH: /root/go
GOCACHE: /root/.cache/go-build
run: |
go build .
- name: Generate new matrix
working-directory: ./matrix_gen
run: |
./matrix_gen --root-folder ~/ansible_output_${{ github.run_id }} --output-file matrix_${{matrix.architecture}}.md
- uses: actions/upload-artifact@v3
with:
name: matrix_${{matrix.architecture}}
path: ./matrix_gen/matrix_${{matrix.architecture}}.md
# Always run the cleanup playbook to avoid leaving garbage on the nodes
- name: Cleanup
if: always()
working-directory: ./ansible-playbooks
run: |
ansible-playbook clean-up.yml --extra-vars &amp;#34;@vars.yml&amp;#34; || :
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In the &lt;code&gt;Generate new matrix&lt;/code&gt; step, the kernel matrix gets generated and then uploaded.&lt;br&gt;
Once this workflow runs successfully for both architectures, another &lt;a href="https://github.com/falcosecurity/libs/blob/master/.github/workflows/pages.yml"&gt;workflow&lt;/a&gt; gets triggered,&lt;br&gt;
that is responsible for generating and pushing updated Github pages.&lt;br&gt;
The end result can be seen at &lt;a href="https://falcosecurity.github.io/libs/matrix/"&gt;https://falcosecurity.github.io/libs/matrix/&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Moreover, the kernel-testing workflow gets also triggered on each driver's tag; then a &lt;a href="https://github.com/falcosecurity/libs/blob/master/.github/workflows/release-body.yml"&gt;supplementary workflow&lt;/a&gt; takes care of attaching matrixes to the release body;&lt;br&gt;
here is an example: &lt;a href="https://github.com/falcosecurity/libs/releases/tag/6.0.0%2Bdriver"&gt;https://github.com/falcosecurity/libs/releases/tag/6.0.0%2Bdriver&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Pretty nice, uh?&lt;/p&gt;
&lt;h3 id="what-s-next-for-the-framework"&gt;What's next for the framework&lt;/h3&gt;
&lt;p&gt;There are quite a few gaps that still need to be addressed by our framework. First of all, the images being used by Ignite to spawn FireCracker VMs are still under a development Docker repository and need to be moved under Falcosecurity.&lt;br&gt;
Moreover, we need to implement a CI to automatically build and push those images.&lt;/p&gt;
&lt;p&gt;As previously said, the kernel tests are currently running &lt;a href="https://github.com/falcosecurity/libs/tree/master/userspace/libscap/examples/01-open"&gt;&lt;code&gt;scap-open&lt;/code&gt;&lt;/a&gt; binary to check whether any event gets received. It is a small libscap C example that loads a driver and waits for events, nothing more.&lt;br&gt;
It would be great to run &lt;a href="https://github.com/falcosecurity/libs/tree/master/test/drivers"&gt;drivers tests&lt;/a&gt; instead, to fully test the expected behavior of the drivers.&lt;/p&gt;
&lt;p&gt;Finally, an utopian idea: imagine if we were able to run &lt;a href="https://github.com/falcosecurity/kernel-crawler"&gt;&lt;code&gt;kernel-crawler&lt;/code&gt;&lt;/a&gt; to fetch kernel images, and then &lt;strong&gt;automatically&lt;/strong&gt; build new kernel testing matrix entries for newly discovered images.&lt;br&gt;
This would mean that our kernel testing matrix coverage increases steadily week after week, giving users even more guarantees about the stability of the Falco drivers!&lt;/p&gt;
&lt;p&gt;Here is the libs tracking issue: &lt;a href="https://github.com/falcosecurity/libs/issues/1224"&gt;https://github.com/falcosecurity/libs/issues/1224&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We would love to hear back from you! If you try out the framework and find any issues, please file them at &lt;a href="https://github.com/falcosecurity/kernel-testing/issues"&gt;https://github.com/falcosecurity/kernel-testing/issues&lt;/a&gt;. If you want to help us to improve, please join our Slack, and feel free to open a Pull Request!&lt;/p&gt;</description></item><item><title>Blog: Adaptive Syscalls Selection in Falco</title><link>https://v0-43--falcosecurity.netlify.app/blog/adaptive-syscalls-selection/</link><pubDate>Tue, 04 Jul 2023 00:00:00 +0000</pubDate><guid>https://v0-43--falcosecurity.netlify.app/blog/adaptive-syscalls-selection/</guid><description>
&lt;p&gt;The release of Falco 0.35.0 is a significant milestone, introducing a groundbreaking feature: the ability to select which syscalls to monitor. This empowers users with granular control, optimizing system performance by reducing CPU load through selective syscall monitoring.&lt;/p&gt;
&lt;p&gt;Why stop at just the one groundbreaking feature, such as selecting which syscalls to monitor? Previously, Falco was limited to monitoring a narrower set of syscalls, which was a drawback since its underlying libraries and kernel drivers were capable of monitoring a wider range of syscalls. We addressed this gap, and Falco now has the enhanced capability to monitor every &lt;a href="https://falcosecurity.github.io/libs/report/"&gt;syscall supported&lt;/a&gt; by its libraries. This milestone, allowing access to a notable range of syscalls, represents another significant advancement in threat detection.&lt;/p&gt;
&lt;div class="card card-sm pageinfo pageinfo-info my-4"&gt;
&lt;div class="card-body"&gt;
&lt;div class="card-text"&gt;
&lt;p&gt;Kudos to the remarkable teamwork of Jason Dellaluce, Federico Di Pierro, Andrea Terzolo, and Melissa Kilby for making the adaptive syscalls selection feature a reality. We would also like to express our gratitude to Stanley Chan for providing invaluable feedback to ensure a clear and user-friendly experience.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h2 id="key-terms"&gt;Key Terms&lt;/h2&gt;
&lt;p&gt;First, let's define key terms that are crucial for understanding the complexity and high-level nature of the refactoring that has been performed.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;syscall&lt;/code&gt;: In Linux, system calls serve as the interface for requesting permission from the kernel to interact with hardware resources, such as accessing memory or reading files. These system calls are defined in the Linux headers, and each syscall is associated with a specific number, such as &lt;code&gt;__NR_close&lt;/code&gt;. Falco, being designed to support multiple architectures internally, employs a mapping mechanism to track each system call using a custom invented code called &lt;code&gt;PPM_SC_*&lt;/code&gt;. This mapping allows Falco's libraries to uniquely identify and handle each supported syscall in a uniform manner. (e.g. &lt;code&gt;PPM_SC_CLOSE&lt;/code&gt; represents the close syscall).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;event&lt;/code&gt;: Syscalls consist of an enter event and an exit event. This is why Falco introduces an additional mapping from the &lt;code&gt;PPM_SC_*&lt;/code&gt; code to another enumeration called &lt;code&gt;PPME_*&lt;/code&gt;, which is specific to Falco's libraries. This mapping is crucial for organizing the parsing process and ensuring a structured approach, especially because Falco not only handles syscall events but also deals with non-syscall events. For syscalls, specific codes are assigned to events like the enter event of the syscall (e.g. &lt;code&gt;PPME_SYSCALL_CLOSE_E&lt;/code&gt;) and the exit event (e.g. &lt;code&gt;PPME_SYSCALL_CLOSE_X&lt;/code&gt;). However, not every syscall has its own &lt;code&gt;PPME_*&lt;/code&gt; code. Falco introduces the concept of generic syscalls, which brings the advantage of a shared schema and parsing mechanism for multiple syscalls using a generic extractor, optimizing efficiency by avoiding the need for separate parsers in those cases.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;br&gt;&lt;a target="_blank" href="images/adaptive-syscalls-selection-01.png"&gt;
&lt;img style="border: 2px solid #00b4c8"
alt="Examples of Falco internal mapping of Syscalls"
src="images/adaptive-syscalls-selection-01.png"&gt;
&lt;/img&gt;
&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;monitoring&lt;/code&gt;/&lt;code&gt;tracing&lt;/code&gt;: Refers to passively observing and analyzing events within the Linux kernel by hooking into tracepoints and subsequently serving information up as structured Falco alerts. Falco's monitoring process does not influence or modify any syscalls.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;processing&lt;/code&gt;/&lt;code&gt;parsing&lt;/code&gt;: Extracting meaningful information from the events captured by Falco and converting them into a structured format. We extract data fields in the kernel and perform the necessary parsing in userspace.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;filtering&lt;/code&gt;: Refers to stopping the processing / parsing or ignoring events. No modifications are made to the kernel during this process.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;rules matching&lt;/code&gt;: Refers to evaluating an event in userspace against the Abstract Syntax Tree (AST) generated from a Falco rule.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="background"&gt;Background&lt;/h2&gt;
&lt;p&gt;Before the 0.35.0 release, Falco would monitor a predefined set of commonly used syscalls in its kernel driver for threat detection, regardless of the specific rules being applied. However, this approach had limitations as it would monitor a large number of syscalls. In certain user configurations, Falco would needlessly monitor syscalls not relevant to the loaded rules, consuming system resources without effectively contributing to the intended purpose of threat detection.&lt;/p&gt;
&lt;p&gt;You may ask yourself why Falco has been monitoring a predetermined set of commonly used syscalls until now. Falco relies on a set of syscalls to establish and maintain its state in userspace. For example, when a new process is spawned or a network connection is created, multiple syscalls are involved. Additionally, Falco maintains a process cache table in userspace, which requires tracking certain syscalls to ensure the accuracy and currency of the cache table. The process table is crucial for retrieving real-time process tree lineages and other functions.&lt;/p&gt;
&lt;p&gt;Initially, tracing a predefined set of syscalls provided a solid foundation for Falco's functionality. However, with the growing computational workload on servers and systems, it became necessary to adopt a new and more efficient approach to optimize performance.&lt;/p&gt;
&lt;h2 id="adaptive-syscall-selection"&gt;Adaptive Syscall Selection&lt;/h2&gt;
&lt;p&gt;Adaptive syscall selection is a new feature that adds the ability to select which syscalls to monitor. This empowers users with granular control, optimizing system performance by reducing CPU load through selective syscall monitoring. Adaptive syscall selection was added to Falco on version 0.35, and, by default, it doesn't change Falco behavior from a high-level view. In other words, by default, Falco continues to operate as usual.&lt;/p&gt;
&lt;p&gt;The changes primarily impact the handling of syscall events and the selection of specific syscalls to be monitored and analyzed. The current changes only affect live syscall events. The sycall selection is now done as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Falco determines a base set of syscalls to monitor. This can be either the default minimum set known as the &amp;quot;sinsp state set&amp;quot; (automatically determined by the underlying libsinsp library to maintain state consistency and stability), or a customized set of syscalls defined by the user via the new &lt;code&gt;base_syscalls&lt;/code&gt; configuration (discussed later).&lt;/li&gt;
&lt;li&gt;The final set of syscalls selected by Falco is determined as the union of two components: the base set of syscalls computed in the previous step, and the syscalls specified in the loaded rules.&lt;/li&gt;
&lt;li&gt;If the &lt;code&gt;-A&lt;/code&gt; flag is not enabled, performance-heavy syscalls, such as I/O-intensive syscalls, are excluded from the set of syscalls, and a warning is shown to the user.&lt;/li&gt;
&lt;li&gt;Falco configures the kernel driver with the chosen set of syscalls and only monitors syscalls that match the selected syscalls on the kernel side.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="card card-sm pageinfo pageinfo-warning my-4"&gt;
&lt;div class="card-body"&gt;
&lt;div class="card-text"&gt;
&lt;p&gt;Adaptive syscall selection does not apply to capture files and only affects the behavior of live capture.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br&gt;&lt;a target="_blank" href="images/adaptive-syscalls-selection-02.png"&gt;
&lt;img style="border: 2px solid #00b4c8"
alt="Examples of automatic Syscalls inclusion/exclussion"
src="images/adaptive-syscalls-selection-02.png"&gt;
&lt;/img&gt;
&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;&lt;br&gt;&lt;a target="_blank" href="images/adaptive-syscalls-selection-03.png"&gt;
&lt;img style="border: 2px solid #00b4c8"
alt="Mapping of observed Syscalls by the Falco Driver"
src="images/adaptive-syscalls-selection-03.png"&gt;
&lt;/img&gt;
&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;h2 id="new-configuration-options"&gt;New Configuration Options&lt;/h2&gt;
&lt;p&gt;As discussed above, Falco 0.35 allows users to define a customized base set of syscalls to monitor. This is done via the &lt;code&gt;base_syscalls&lt;/code&gt; setting, which provides two configuration options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The &lt;code&gt;custom_set&lt;/code&gt; option enables users to define a custom list of syscalls to monitor in Falco in addition to the syscalls from each Falco rule. It supports both positive notation, where a syscall is specified to be activated, and negative notation, indicated by &lt;code&gt;!&lt;/code&gt; followed by the syscall name, to deactivate a syscall even if it is used in the ruleset. This flexibility allows users to have precise control over which syscalls are included or excluded in the &lt;code&gt;sys_enter&lt;/code&gt; and &lt;code&gt;sys_exit&lt;/code&gt; tracepoints, ensuring a tailored configuration that aligns with their specific requirements, use cases and cost budget.&lt;/p&gt;
&lt;p&gt;To maintain a streamlined and efficient configuration, it is recommended to remove unwanted syscalls directly from the Falco rules instead of excluding them in the &lt;code&gt;custom_set&lt;/code&gt; configuration. This approach ensures that the rules accurately reflect the desired behavior and reduces unnecessary complexity in the configuration.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When the &lt;code&gt;repair&lt;/code&gt; option is set to &lt;code&gt;true&lt;/code&gt;, it automatically adjusts the custom syscall set to ensure the accurate creation of its state engine, including necessary syscalls such as &lt;code&gt;close&lt;/code&gt; or &lt;code&gt;procexit&lt;/code&gt;. However, it is designed to be the most system resource-friendly by activating the least number of additional syscalls (outside of those enabled for enabled rules) as alternative to Falco's default libsinsp state engine enforcement. It dynamically selects necessary syscalls based on the active rules, making it truly adaptive and efficient. The &lt;code&gt;repair_state&lt;/code&gt; feature helps mitigate issues that may arise from incorrect usage of &lt;code&gt;custom_set&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here are some helpful suggestions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;For &lt;strong&gt;process-related rules&lt;/strong&gt; include syscalls such as &lt;code&gt;clone&lt;/code&gt;, &lt;code&gt;clone3&lt;/code&gt;, &lt;code&gt;fork&lt;/code&gt;, &lt;code&gt;vfork&lt;/code&gt;, &lt;code&gt;execve&lt;/code&gt;, &lt;code&gt;execveat&lt;/code&gt;, and &lt;code&gt;close&lt;/code&gt; in the &lt;code&gt;base_syscalls.custom_set&lt;/code&gt;; these syscalls are essential for retrieving process information and managing file descriptors.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For &lt;strong&gt;networking-related rules&lt;/strong&gt; include syscalls like &lt;code&gt;socket&lt;/code&gt;, &lt;code&gt;bind&lt;/code&gt;, and &lt;code&gt;getsockopt&lt;/code&gt; in the &lt;code&gt;base_syscalls.custom_set&lt;/code&gt;; these syscalls ensure that network-related events are properly logged, including IP tuples and relevant information.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For &lt;strong&gt;tracking process information accurately&lt;/strong&gt; consider adding syscalls such as &lt;code&gt;setresuid&lt;/code&gt;, &lt;code&gt;setsid&lt;/code&gt;, &lt;code&gt;setuid&lt;/code&gt;, &lt;code&gt;setgid&lt;/code&gt;, &lt;code&gt;setpgid&lt;/code&gt;, &lt;code&gt;setresgid&lt;/code&gt;, &lt;code&gt;setsid&lt;/code&gt;, &lt;code&gt;capset&lt;/code&gt;, &lt;code&gt;chdir&lt;/code&gt;, &lt;code&gt;chroot&lt;/code&gt;, &lt;code&gt;prctl&lt;/code&gt; and &lt;code&gt;fchdir&lt;/code&gt;; these syscalls help track the correct UID, GID, SID, and PGID etc of a process when it interacts with files or makes network connections.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The provided suggestions serve as a starting point for configuring the &lt;code&gt;base_syscalls.custom_set&lt;/code&gt; according to users' specific monitoring needs. It is crucial to assess these suggestions within the context of individual use cases and make appropriate adjustments.&lt;/p&gt;
&lt;p&gt;By adhering to these recommendations and carefully fine-tuning the syscall selection, users can achieve optimal performance, minimize resource utilization and possible kernel side event drops, and maintain precise monitoring and detection of potential security threats with Falco. Tailoring the syscall selection aligns Falco with the unique requirements of the environment, enhancing its effectiveness in threat detection.&lt;/p&gt;
&lt;p&gt;&lt;br&gt;&lt;a target="_blank" href="images/adaptive-syscalls-selection-04.png"&gt;
&lt;img style="border: 2px solid #00b4c8"
alt="Falco's Kernel Event Monitoring Flow"
src="images/adaptive-syscalls-selection-04.png"&gt;
&lt;/img&gt;
&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;For further information, please refer to the Falco configuration file and navigate to the new &lt;code&gt;base_syscalls&lt;/code&gt; option: &lt;a href="https://github.com/falcosecurity/falco/blob/master/falco.yaml"&gt;https://github.com/falcosecurity/falco/blob/master/falco.yaml&lt;/a&gt;&lt;/p&gt;
&lt;div class="card card-sm pageinfo pageinfo-info my-4"&gt;
&lt;div class="card-body"&gt;
&lt;div class="card-text"&gt;
&lt;p&gt;If all of this sounds confusing or unclear, the best way to gain a deeper understanding of this new feature is through hands-on experimentation. By actively exploring and testing the feature, you can observe firsthand how it can enhance the performance of your deployment.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Also, you can test it live in this interactive environment that we have prepared for you.&lt;/p&gt;
&lt;p&gt;Click on it to start playing with it 🎮&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" href="https://play.instruqt.com/embed/sysdig/tracks/falco-adaptive-syscalls?token=em_ng2XK3hUZCl4VnTm&amp;icp_embed_source=blog-falco-adaptive-syscall&amp;icp_owner=oss"&gt;&lt;img src="images/adaptive-syscalls-selection-lab.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you wish to examine the final set of syscalls that will be used by Falco on your own envinronment, you can print them to the STDOUT by including the &lt;code&gt;-o &amp;quot;log_level=debug&amp;quot; -o &amp;quot;log_stderr=true&amp;quot; --dry-run&lt;/code&gt; args during a dry run of Falco. By utilizing this option, you can gain valuable insights into the selected syscalls, aiding in troubleshooting and verifying the configuration.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;❯ falco -o &amp;#34;log_level=debug&amp;#34; -o &amp;#34;log_stderr=true&amp;#34; --dry-run
Tue May 30 14:01:27 2023: Falco version: 0.35.0-alpha5 (x86_64)
Tue May 30 14:01:27 2023: CLI args: falco -o log_level=debug -o log_stderr=true --dry-run
Tue May 30 14:01:27 2023: Falco initialized with configuration file: /etc/falco/falco.yaml
Tue May 30 14:01:27 2023: Configured rules filenames:
Tue May 30 14:01:27 2023: /etc/falco/falco_rules.yaml
Tue May 30 14:01:27 2023: /etc/falco/falco_rules.local.yaml
Tue May 30 14:01:27 2023: /etc/falco/rules.d
Tue May 30 14:01:27 2023: Loading rules from file /etc/falco/falco_rules.yaml
Tue May 30 14:01:27 2023: Loading rules from file /etc/falco/falco_rules.local.yaml
Tue May 30 14:01:27 2023: Skipping daemonizing in dry-run
Tue May 30 14:01:27 2023: Skipping signal handlers creation in dry-run
Tue May 30 14:01:27 2023: Skipping daemonizing in dry-run
Tue May 30 14:01:27 2023: Setting metadata download max size to 100 MB
Tue May 30 14:01:27 2023: Setting metadata download chunk wait time to 1000 μs
Tue May 30 14:01:27 2023: Setting metadata download watch frequency to 1 seconds
Tue May 30 14:01:27 2023: Skipping clients initialization in dry-run
Tue May 30 14:01:27 2023: (32) syscalls in rules: accept, accept4, connect, creat, dup, dup2, dup3, execve, execveat, link, linkat, listen, mkdir, mkdirat, open, openat, openat2, ptrace, recvfrom, rename, renameat, renameat2, rmdir, sendmsg, sendto, setuid, socket, symlink, symlinkat, unlink, unlinkat, userfaultfd
Tue May 30 14:01:27 2023: +(40) syscalls (Falco&amp;#39;s state engine set of syscalls): bind, capset, chdir, chroot, clone, clone3, close, epoll_create, epoll_create1, eventfd, eventfd2, fchdir, fcntl, fork, getsockopt, inotify_init, inotify_init1, io_uring_setup, mount, open_by_handle_at, pipe, pipe2, prctl, prlimit, procexit, recvmsg, setgid, setpgid, setresgid, setresuid, setrlimit, setsid, shutdown, signalfd, signalfd4, socketpair, timerfd_create, umount, umount2, vfork
Tue May 30 14:01:27 2023: (72) syscalls selected in total (final set): accept, accept4, bind, capset, chdir, chroot, clone, clone3, close, connect, creat, dup, dup2, dup3, epoll_create, epoll_create1, eventfd, eventfd2, execve, execveat, fchdir, fcntl, fork, getsockopt, inotify_init, inotify_init1, io_uring_setup, link, linkat, listen, mkdir, mkdirat, mount, open, open_by_handle_at, openat, openat2, pipe, pipe2, prctl, prlimit, procexit, ptrace, recvfrom, recvmsg, rename, renameat, renameat2, rmdir, sendmsg, sendto, setgid, setpgid, setresgid, setresuid, setrlimit, setsid, setuid, shutdown, signalfd, signalfd4, socket, socketpair, symlink, symlinkat, timerfd_create, umount, umount2, unlink, unlinkat, userfaultfd, vfork
Tue May 30 14:01:27 2023: The chosen syscall buffer dimension is: 8388608 bytes (8 MBs)
Tue May 30 14:01:27 2023: Skipping starting webserver in dry-run
Tue May 30 14:01:27 2023: Skipping event processing in dry-run
Tue May 30 14:01:27 2023: Skipping unregistering signal handlers in dry-run
Tue May 30 14:01:27 2023: Skipping stopping webserver in dry-run
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id="refactors-involved"&gt;Refactors Involved&lt;/h2&gt;
&lt;p&gt;This section provides an overview of the underlying refactors that have enabled the implementation of the innovative adaptive syscall selection mechanisms in Falco.&lt;/p&gt;
&lt;h3 id="falco-s-ppm-sc-api"&gt;Falco's ppm sc API&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;A new event set class has been introduced to support efficient set operations natively in the &lt;code&gt;ppm sc API&lt;/code&gt; in Falco's &lt;code&gt;libs&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Additional refinements in the &lt;code&gt;ppm sc API&lt;/code&gt; have resulted in robust mechanisms to accurately map syscall and other event strings from the loaded Falco rules to the &lt;code&gt;PPM_SC_*&lt;/code&gt; or &lt;code&gt;PPME_*&lt;/code&gt; enumerations.&lt;br&gt;
This enhancement was essential to overcome the challenges inherited from previous mapping processes and improve the efficiency and structure of event parsing.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The initial separate enumeration for kernel tracepoints has been merged with the &lt;code&gt;PPM_SC_*&lt;/code&gt; codes (&lt;code&gt;sc&lt;/code&gt; now reflecting &lt;code&gt;scap codes&lt;/code&gt; instead of &lt;code&gt;syscall codes&lt;/code&gt; only), resulting in a single enumeration.&lt;/p&gt;
&lt;p&gt;This consolidation sets the groundwork for integrating future LSM (Linux Security Modules) hooks into Falco. By combining these codes, Falco achieves a seamless integration of tracepoint activations and syscall event handling within a unified framework.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="syscall-event-type-extraction-from-falco-s-rules-expression-language"&gt;Syscall Event Type Extraction from Falco's Rules Expression Language&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;In order to extract the corresponding event types, Falco traverses the filter Abstract Syntax Tree (AST) of each rule. The traversal process has been improved for robustness and integrated with the modernized &lt;code&gt;ppm sc API&lt;/code&gt; by moving it to the underlying Falco &lt;code&gt;libs&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Additionally, traversals now include support for mapping the rules event strings to both the &lt;code&gt;PPM_SC_*&lt;/code&gt; and &lt;code&gt;PPME_*&lt;/code&gt; codes. These changes have allowed for the resolution of technical debt concerning the mapping of event strings to their respective syscall codes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Just to emphasize this once more: Falco now has the capability to support any syscall that is supported by its underlying libraries. This expansion of support allows Falco to monitor and analyze a wider range of syscalls for threat detection purposes (see Falco's &lt;a href="https://falcosecurity.github.io/libs/report/"&gt;supported syscalls&lt;/a&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="driver-syscall-push-down-filters"&gt;Driver Syscall Push Down Filters&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;After mapping the event strings from the rules to their corresponding syscall IDs, we utilize a dedicated eBPF map (in the case of &lt;code&gt;*bpf*&lt;/code&gt; drivers) or an internal bitmask using the ioctl API (in the case of kernel module) to inject this information into the &lt;code&gt;sys_enter&lt;/code&gt; and &lt;code&gt;sys_exit&lt;/code&gt; tracepoints within the driver.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Due to the triggering of the &lt;code&gt;sys_enter&lt;/code&gt; and &lt;code&gt;sys_exit&lt;/code&gt; kernel tracepoints for every syscall, our pushdown filter is designed to efficiently ignore unnecessary syscalls before any data field extraction takes place in our kernel drivers. Once again, Falco operates as a passive monitor of syscalls and does not exert any influence or modify the behavior of the syscalls being monitored.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Furthermore, the objective of kernel-side filtering is to minimize the number of events that need to be transferred to userspace via the buffer between kernel and userspace, as well as reduce the number of events that are processed and evaluated against Falco rules in userspace.&lt;br&gt;
This filtering allows us to achieve these efficiencies without sacrificing visibility, as the ignored syscalls are not utilized in Falco rules.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Spoiler alert:&lt;/em&gt; Imagine a monitoring experience where Falco adapts in real-time, intelligently adjusting its capabilities as needed. The &lt;code&gt;ppm sc API&lt;/code&gt; already allows you to dynamically enable or disable syscalls and tracepoints at runtime.&lt;br&gt;
This opens up exciting possibilities for the future of Falco. One day, we envision a truly adaptive monitoring system where Falco can supervise itself and automatically adjust the level of logging verbosity on the fly based on the system's needs.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="userspace-libsinsp-state-engine"&gt;Userspace libsinsp State Engine&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;By efficiently extracting syscall codes from Falco rules strings, we no longer need a large hard-coded predetermined set of syscalls.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;As mentioned previously, the remaining task involved enabling all the syscalls required for the libsinsp state that were not explicitly included in the Falco rules. This is where the new &lt;code&gt;base_syscalls&lt;/code&gt; configuration comes into play, providing end users with complete control over this process.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;With the &lt;code&gt;base_syscalls&lt;/code&gt; configuration, users can define and activate the necessary syscalls for the libsinsp state, ensuring comprehensive monitoring and threat detection capabilities.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="action-items-and-recommendations-for-adopters"&gt;Action Items and Recommendations for Adopters&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Review the updated &lt;code&gt;falco.yaml&lt;/code&gt; file for performance tuning configurations.&lt;/li&gt;
&lt;li&gt;Assess if performance optimizations are needed based on your threat model and budget. Adjust the &lt;code&gt;base_syscalls&lt;/code&gt; configuration accordingly.&lt;/li&gt;
&lt;li&gt;Gradually tailor the &lt;code&gt;base_syscalls&lt;/code&gt; configuration as needed, aiming to optimize resource utilization without compromising threat detection, if feasible.&lt;/li&gt;
&lt;li&gt;Experiment and measure changes in resource usage by utilizing the native Falco &lt;code&gt;metrics&lt;/code&gt; option.&lt;/li&gt;
&lt;li&gt;Enhance Falco rules with specific syscalls for increased robustness [see note 1].&lt;/li&gt;
&lt;li&gt;Official &lt;a href="https://falcosecurity.github.io/libs/report/"&gt;syscall string names&lt;/a&gt; in rules are now required.&lt;/li&gt;
&lt;li&gt;Explore new threat detection approaches with Falco's expanded syscall support.&lt;/li&gt;
&lt;li&gt;Stay updated on future releases for enhanced kernel monitoring capabilities.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="card card-sm pageinfo pageinfo-info my-4"&gt;
&lt;div class="card-body"&gt;
&lt;div class="card-text"&gt;
&lt;p&gt;One concrete example is the rule named &amp;quot;Linux Kernel Module Injection Detected.&amp;quot; Previously, this rule relied on monitoring spawned processes. However, with the broader syscall coverage, it is now possible to enhance the rule by focusing on specific syscalls such as &lt;code&gt;init_module&lt;/code&gt; and &lt;code&gt;finit_module&lt;/code&gt;, which are directly related to kernel module injection.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</description></item></channel></rss>