All Projects → redcanaryco → redcanary-ebpf-sensor

redcanaryco / redcanary-ebpf-sensor

Licence: GPL-2.0 license
Red Canary's eBPF Sensor

Programming Languages

c
50402 projects - #5 most used programming language
Makefile
30231 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to redcanary-ebpf-sensor

solis-sensor
HomeAssistant integration for the Ginlong Solis PV Monitoring portal. This integration supports the current Platform v2.0 portal (m.ginlong.com) which supports Solis and Solarman PV inverter brands. Also supports new SolisCloud platform
Stars: ✭ 80 (+53.85%)
Mutual labels:  sensor
bme280
Arduino and CMake library for communicating with the Bosch Sensortec BME280 environmental sensor.
Stars: ✭ 21 (-59.62%)
Mutual labels:  sensor
cilium-cli
CLI to install, manage & troubleshoot Kubernetes clusters running Cilium
Stars: ✭ 162 (+211.54%)
Mutual labels:  ebpf
KinectXbox360-UE4
kinect Xbox 360 sdk 1.8 Plugin for Unreal Engine 4
Stars: ✭ 43 (-17.31%)
Mutual labels:  sensor
air-quality
Air quality sensing and monitoring
Stars: ✭ 17 (-67.31%)
Mutual labels:  sensor
embedded-sht
Embedded SHT Drivers for Sensirion Temperature and Humidity Sensors - Download the Zip Package from the Release Page
Stars: ✭ 53 (+1.92%)
Mutual labels:  sensor
portablebpf
You came here so you could have a base code to serve you as an example on how to develop a BPF application, compatible to BCC and/or LIBBPF, specially LIBBPF, having the userland part made in C or PYTHON.
Stars: ✭ 32 (-38.46%)
Mutual labels:  ebpf
TLE5012-Magnetic-Angle-Sensor
This repository includes an library for Arduino for the TLE5012 Magnetic Angle Sensor with SSC interface.
Stars: ✭ 37 (-28.85%)
Mutual labels:  sensor
eBPF-for-Ghidra
eBPF Processor for Ghidra
Stars: ✭ 157 (+201.92%)
Mutual labels:  ebpf
ebpf
eBPF package for Go
Stars: ✭ 25 (-51.92%)
Mutual labels:  ebpf
ebpfault
A BPF-based syscall fault injector
Stars: ✭ 65 (+25%)
Mutual labels:  ebpf
CO2-Ampel
CO2-Ampel / CO2-Traffic-Light to measure and show the carbon dioxide concentration in a room, based on Sensirion SCD30/SCD4x sensor and Microchip SAMD21 microcontroller
Stars: ✭ 20 (-61.54%)
Mutual labels:  sensor
SHT31
Arduino library for the SHT31 temperature and humidity sensor
Stars: ✭ 26 (-50%)
Mutual labels:  sensor
hubble-ui
Observability & Troubleshooting for Kubernetes Services
Stars: ✭ 210 (+303.85%)
Mutual labels:  ebpf
IoTHAT
Turta IoT HAT Source, Reference and Manual.
Stars: ✭ 23 (-55.77%)
Mutual labels:  sensor
bsec bme680 linux
Read the BME680 sensor with the BSEC library on Linux (e.g. Raspberry Pi)
Stars: ✭ 78 (+50%)
Mutual labels:  sensor
ublox
Arduino and CMake library for communicating with uBlox GPS receivers.
Stars: ✭ 89 (+71.15%)
Mutual labels:  sensor
SparkFun CCS811 Arduino Library
A library to drive the AMS CCS811 air quality sensor
Stars: ✭ 38 (-26.92%)
Mutual labels:  sensor
Indego
Home Assistant Custom Component for Bosch Indego Lawn Mower
Stars: ✭ 42 (-19.23%)
Mutual labels:  sensor
merbridge
Use eBPF to speed up your Service Mesh like crossing an Einstein-Rosen Bridge.
Stars: ✭ 469 (+801.92%)
Mutual labels:  ebpf

redcanary-ebpf-sensor

This project consists of a variety of eBPF applications aimed at gathering events of interest for Red Canary's Cloud Workload Protection product.

These applications do not use BCC to build. The main objective of this design is to have a compile once, run everywhere application.

To build this project run docker-compose run --rm ebpf make all

A vscode cpp properties files has been included. Make sure to update the include path with the path on your local system where the kernel header files are located

Gotchas and Patterns

Dummy Telemetry Event

At the beginning of the programs we often have code that looks like:

telemetry_event_t sev = {0};

We then proceed to send &sev to our functions and set the proper values there. This is done for two reasons:

  1. We want to save stack space, so by creating a single dummy event at the top we can remind ourselves that this is the only event we ever want to have at a time and it is meant to be reused.

  2. The eBPF verifier does not like uninitialized padding. When initializing a padded struct in C, not all of the space occupied by the struct necessarily gets initialized as padding may exist between fields, or empty space unused by some union members. The eBPF verifier does not like this so to guarantee nothing is unitialized we need to zero out all of the space for the event struct. For more information see this issue.

Per CPU structures

Be careful when using PERCPU structures (such as BPF_MAP_TYPE_PERFCPU_ARRAY). While an eBPF program is not preemptable, syscalls are. This means that a kprobe for a syscall may happen in one CPU but its kretprobe will happen in a different CPU. This means that passing data using per cpu structures accross programs will not always work in multicore systems. Note, however, that tail calling is NOT preemptable, so it is okay to pass information using per cpu structures through tail calls.

Kprobe and Kretprobe synchronization

Since syscalls may start and finish in different CPUs (they are preemptable), we need to be send extra data to synchronize them in user space. To do this, we send a a TE_ENTER_DONE event as the very last event produced by a kprobe. Note that since programs may tail call into other programs we need to follow that tail call through and send it as the very last event in the final tail call. We also rely on the TE_RETCODE event being the last event in a kretprobe so no extra signaling event is done for them. If this changes in the future (e.g., due to tail calling) we'll need to add synchronization events there too.

Validate Instruction Count

Due to older kernel limitations (< 5.2) the instruction limit for our ebpf programs is 4096. This was changed in Kernel 5.2+ to be 1 million but we cannot rely on that at this time. To verify that we aren't going over the limit, after modifying an ebpf program run it through llvm-objdump and check its instruction count:

llvm-objdump -d <PATH_TO_COMPILED_FILE> -j <SPECIFIC_SECTION_TO_ANALYZE> | less

You may ommit the -j <SPECIFIC_SECTION_TO_ANALYZE> if you want to check all the sections at the same time.

eBPF programs can branch (but not jump back!) so make sure to check that none of the branches go over the 4096 instructions limit.

Licensing

Please note, these programs are mostly licensed under GPL, which is required to leverage BPF features critical for gathering security telemetry.

char _license[] SEC("license") = "GPL";

If you bundle these programs with your own code (for example, by using include_bytes!() in Rust), that extends GPL to your code base. If you wish to use your own code with its own license alongside these programs, you'll need to build, manage, and distribute them separately.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].