SlideShare a Scribd company logo
Spying on the Linux kernel for
fun and profit
Andrea Righi
righi.andrea@gmail.com
Twitter: @arighi
Github profile: https://github.com/arighi
Linux kernel is complex
https://www.linuxcounter.net/statistics/kernel
Linux kernel changes
http://neuling.org/linux-next-size.html
How to keep up with changes
●
https://lwn.net/Kernel/
●
https://kernelnewbies.org/LinuxChanges
●
http://vger.kernel.org/vger-lists.html#linux-kernel
●
kernel source: Documentation/
Real-time tracing
strace
●
strace(1): system call tracer in Linux
●
It uses the ptrace() system call that pauses the
target process for each syscall so that the debugger
can read the state
●
And it’s doing this twice: when the syscall
begins and when it ends!
strace overhead
### Regular execution ###
$ dd if=/dev/zero of=/dev/null bs=1 count=500k
512000+0 records in
512000+0 records out
512000 bytes (512 kB, 500 KiB) copied, 0,501455 s, 1.0 MB/s
### Strace execution (tracing a syscall that is never called) ###
$ strace -e trace=accept dd if=/dev/zero of=/dev/null bs=1 count=500k
512000+0 records in
512000+0 records out
512000 bytes (512 kB, 500 KiB) copied, 44.0216 s, 11,6 kB/s
+++ exited with 0 +++
Advanced tracing techniques
eBPF
eBPF features
●
Highly efficient VM that lives in the kernel
●
Inject safe sanboxed bytecode into the kernel
●
Attach code to kernel functions / events
●
In-kernel JIT compiler
– Dynamically translate eBPF bytecode into native opcodes
●
eBPF makes kernel programmable without having to
cross kernel/user-space boundaries
●
Access in-kernel data structures directly without the risk of
crashing, hanging or breaking the kernel in any way
eBPF history
●
Initially it was BPF: Berkeley Packet Filter
●
It has its roots in BSD in the very early 1990’s
●
Originally designed as a mechanism for fast filtering network
packets
●
3.15: Linux introduced eBPF: extended Berkeley Packet Filter
●
More efficient / more generic than the original BPF
●
3.18: eBPF VM exposed to user-space
●
4.9: eBPF programs can be attached to perf_events
●
4.10: eBPF programs can be attached to cgroups
●
4.15: eBPF LSM hooks
eBPF as a VM
●
Example assembly of a simple
eBPF filter
●
Load 16-bit quantity from
offset 12 in the packet to the
accumulator (ethernet type)
●
Compare the value to see if
the packet is an IP packet
●
If the packet is IP, return TRUE
(packet is accepted)
●
otherwise return 0 (packet is
rejected)
●
Only 4 VM instructions to filter IP
packets!
ldh [12]
jeq #ETHERTYPE_IP, l1, l2
l1: ret #TRUE
l2: ret #0
eBPF use cases
kprobe
BCC tracing tools
●
BPF Compiler Collection
●
Front-end to eBPF
●
BCC makes eBPF programs easier to write
– Include C wrapper around LLVM
– Python
– Lua
– C++
– C helper libs
●
golang (gobpf)
●
https://github.com/iovisor/gobpf
https://github.com/iovisor/bcc
Examples
Example #1: trace exec()
●
Intercept all the processes executed in the system
Example #2: keylogger
●
Identify where and how keyboard characters are
received and processed by the kernel
Example #3: ping
●
Identify where ICMP packets (ECHO_REQUEST /
ECHO_REPLY) are received and processed by the
kernel
Example #4: task wait / wakeup
●
Determine the stack
trace of a sleeping
process and the stack
trace of the process
that wakes up a
sleeping process
Conclusion
●
Real-time tracing as a method to study the kernel
●
Understanding what the kernel is doing can help to
improve your application / service in terms of
performance, reliability and security
References
●
Brendan Gregg blog
●
http://brendangregg.com/blog/
●
BCC tools
●
https://github.com/iovisor/bcc
●
gobpf (BPF bindings for go):
●
https://github.com/iovisor/gobpf
●
The BSD Packet Filter: A New Architecture for User-level
Packet Capture -
S. McCanne and V. Jacobson
●
http://www.tcpdump.org/papers/bpf-usenix93.pdf
Thanks
●
twitter: @arighi
●
email: righi.andrea@gmail.com

More Related Content

PDF
Mirko Damiani - An Embedded soft real time distributed system in Go
PDF
Michele Dionisio & Pietro Lorefice - Developing and testing a device driver w...
PDF
Davide Berardi - Linux hardening and security measures against Memory corruption
PDF
Valerio Di Giampietro - Introduction To IoT Reverse Engineering with an examp...
PDF
MOVED: RDK/WPE Port on DB410C - SFO17-206
PDF
OpenWrt From Top to Bottom
PDF
Claudio Scordino - Handling mixed criticality on embedded multi-core systems
PDF
Kernel Recipes 2015: Greybus
Mirko Damiani - An Embedded soft real time distributed system in Go
Michele Dionisio & Pietro Lorefice - Developing and testing a device driver w...
Davide Berardi - Linux hardening and security measures against Memory corruption
Valerio Di Giampietro - Introduction To IoT Reverse Engineering with an examp...
MOVED: RDK/WPE Port on DB410C - SFO17-206
OpenWrt From Top to Bottom
Claudio Scordino - Handling mixed criticality on embedded multi-core systems
Kernel Recipes 2015: Greybus

What's hot (20)

PDF
Alessio Lama - Development and testing of a safety network protocol
PDF
Kernel Recipes 2016 - Landlock LSM: Unprivileged sandboxing
PDF
Kernel Recipes 2015 - The Dronecode Project – A step in open source drones
PDF
Kernel Recipes 2016 - New hwmon device registration API - Jean Delvare
PDF
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
PDF
Stefano Cordibella - An introduction to Yocto Project
PDF
The Linux Block Layer - Built for Fast Storage
PDF
Emanuele Faranda - Creating network overlays with IoT devices using N2N
PDF
BKK16-103 OpenCSD - Open for Business!
PDF
LAS16-210: Hardware Assisted Tracing on ARM with CoreSight and OpenCSD
PDF
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
PDF
BKK16-409 VOSY Switch Port to ARMv8 Platforms and ODP Integration
PDF
Luca Cipriani - Control your Embedded Linux remotely by using MQTT and a web ...
PDF
BKK16-505 Kernel and Bootloader Consolidation and Upstreaming
PDF
Tommaso Cucinotta - Low-latency and power-efficient audio applications on Linux
PDF
BSD Sockets API in Zephyr RTOS - SFO17-108
PPTX
A Kernel of Truth: Intrusion Detection and Attestation with eBPF
PDF
Lcu14 101- coresight overview
PPTX
Bypassing ASLR Exploiting CVE 2015-7545
PDF
ebpf and IO Visor: The What, how, and what next!
Alessio Lama - Development and testing of a safety network protocol
Kernel Recipes 2016 - Landlock LSM: Unprivileged sandboxing
Kernel Recipes 2015 - The Dronecode Project – A step in open source drones
Kernel Recipes 2016 - New hwmon device registration API - Jean Delvare
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
Stefano Cordibella - An introduction to Yocto Project
The Linux Block Layer - Built for Fast Storage
Emanuele Faranda - Creating network overlays with IoT devices using N2N
BKK16-103 OpenCSD - Open for Business!
LAS16-210: Hardware Assisted Tracing on ARM with CoreSight and OpenCSD
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
BKK16-409 VOSY Switch Port to ARMv8 Platforms and ODP Integration
Luca Cipriani - Control your Embedded Linux remotely by using MQTT and a web ...
BKK16-505 Kernel and Bootloader Consolidation and Upstreaming
Tommaso Cucinotta - Low-latency and power-efficient audio applications on Linux
BSD Sockets API in Zephyr RTOS - SFO17-108
A Kernel of Truth: Intrusion Detection and Attestation with eBPF
Lcu14 101- coresight overview
Bypassing ASLR Exploiting CVE 2015-7545
ebpf and IO Visor: The What, how, and what next!
Ad

Similar to Andrea Righi - Spying on the Linux kernel for fun and profit (20)

PDF
Kernel bug hunting
PDF
Security Monitoring with eBPF
PDF
UM2019 Extended BPF: A New Type of Software
PDF
Efficient System Monitoring in Cloud Native Environments
PDF
LSFMM 2019 BPF Observability
PPTX
Understanding eBPF in a Hurry!
ODP
Linux kernel tracing superpowers in the cloud
PDF
eBPF Trace from Kernel to Userspace
PDF
Using eBPF Off-CPU Sampling to See What Your DBs are Really Waiting For by Ta...
PDF
DEF CON 27 - JEFF DILEO - evil e bpf in depth
PDF
Linux BPF Superpowers
PDF
Kernel Recipes 2019 - BPF at Facebook
PDF
BPF: Tracing and more
PDF
Linux kernel bug hunting
PDF
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
PDF
Bpf performance tools chapter 4 bcc
PPTX
Always-on Profiling of All Linux Threads, On-CPU and Off-CPU, with eBPF & Con...
PDF
Linux 4.x Tracing Tools: Using BPF Superpowers
PDF
bpftrace - Tracing Summit 2018
PDF
OSSNA 2017 Performance Analysis Superpowers with Linux BPF
Kernel bug hunting
Security Monitoring with eBPF
UM2019 Extended BPF: A New Type of Software
Efficient System Monitoring in Cloud Native Environments
LSFMM 2019 BPF Observability
Understanding eBPF in a Hurry!
Linux kernel tracing superpowers in the cloud
eBPF Trace from Kernel to Userspace
Using eBPF Off-CPU Sampling to See What Your DBs are Really Waiting For by Ta...
DEF CON 27 - JEFF DILEO - evil e bpf in depth
Linux BPF Superpowers
Kernel Recipes 2019 - BPF at Facebook
BPF: Tracing and more
Linux kernel bug hunting
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Bpf performance tools chapter 4 bcc
Always-on Profiling of All Linux Threads, On-CPU and Off-CPU, with eBPF & Con...
Linux 4.x Tracing Tools: Using BPF Superpowers
bpftrace - Tracing Summit 2018
OSSNA 2017 Performance Analysis Superpowers with Linux BPF
Ad

More from linuxlab_conf (9)

PDF
Jonathan Corbet - Keynote: The Kernel Report
PDF
Marco Cavallini - Yocto Project, an automatic generator of embedded Linux dis...
PDF
Bruno Verachten - The Android device farm that fits in a (cloudy) pocket
PDF
Jagan Teki - U-boot from scratch
PDF
Jacopo Mondi - Complex cameras are complex
PDF
Dario Faggioli - Virtualization in the age of speculative execution HW bugs
PDF
Angelo Compagnucci - Upgrading buildroot based devices with swupdate
PDF
Luca Abeni - Real-Time Virtual Machines with Linux and kvm
PDF
Luca Ceresoli - Buildroot vs Yocto: Differences for Your Daily Job
Jonathan Corbet - Keynote: The Kernel Report
Marco Cavallini - Yocto Project, an automatic generator of embedded Linux dis...
Bruno Verachten - The Android device farm that fits in a (cloudy) pocket
Jagan Teki - U-boot from scratch
Jacopo Mondi - Complex cameras are complex
Dario Faggioli - Virtualization in the age of speculative execution HW bugs
Angelo Compagnucci - Upgrading buildroot based devices with swupdate
Luca Abeni - Real-Time Virtual Machines with Linux and kvm
Luca Ceresoli - Buildroot vs Yocto: Differences for Your Daily Job

Recently uploaded (20)

PPT
Introduction Database Management System for Course Database
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PPTX
Introduction to Artificial Intelligence
PDF
System and Network Administraation Chapter 3
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
System and Network Administration Chapter 2
PDF
top salesforce developer skills in 2025.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Transform Your Business with a Software ERP System
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
AI in Product Development-omnex systems
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Introduction Database Management System for Course Database
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Introduction to Artificial Intelligence
System and Network Administraation Chapter 3
How to Choose the Right IT Partner for Your Business in Malaysia
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
System and Network Administration Chapter 2
top salesforce developer skills in 2025.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
L1 - Introduction to python Backend.pptx
Transform Your Business with a Software ERP System
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Wondershare Filmora 15 Crack With Activation Key [2025
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
AI in Product Development-omnex systems
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus

Andrea Righi - Spying on the Linux kernel for fun and profit

  • 1. Spying on the Linux kernel for fun and profit Andrea Righi righi.andrea@gmail.com Twitter: @arighi Github profile: https://github.com/arighi
  • 2. Linux kernel is complex
  • 5. How to keep up with changes ● https://lwn.net/Kernel/ ● https://kernelnewbies.org/LinuxChanges ● http://vger.kernel.org/vger-lists.html#linux-kernel ● kernel source: Documentation/
  • 7. strace ● strace(1): system call tracer in Linux ● It uses the ptrace() system call that pauses the target process for each syscall so that the debugger can read the state ● And it’s doing this twice: when the syscall begins and when it ends!
  • 8. strace overhead ### Regular execution ### $ dd if=/dev/zero of=/dev/null bs=1 count=500k 512000+0 records in 512000+0 records out 512000 bytes (512 kB, 500 KiB) copied, 0,501455 s, 1.0 MB/s ### Strace execution (tracing a syscall that is never called) ### $ strace -e trace=accept dd if=/dev/zero of=/dev/null bs=1 count=500k 512000+0 records in 512000+0 records out 512000 bytes (512 kB, 500 KiB) copied, 44.0216 s, 11,6 kB/s +++ exited with 0 +++
  • 10. eBPF
  • 11. eBPF features ● Highly efficient VM that lives in the kernel ● Inject safe sanboxed bytecode into the kernel ● Attach code to kernel functions / events ● In-kernel JIT compiler – Dynamically translate eBPF bytecode into native opcodes ● eBPF makes kernel programmable without having to cross kernel/user-space boundaries ● Access in-kernel data structures directly without the risk of crashing, hanging or breaking the kernel in any way
  • 12. eBPF history ● Initially it was BPF: Berkeley Packet Filter ● It has its roots in BSD in the very early 1990’s ● Originally designed as a mechanism for fast filtering network packets ● 3.15: Linux introduced eBPF: extended Berkeley Packet Filter ● More efficient / more generic than the original BPF ● 3.18: eBPF VM exposed to user-space ● 4.9: eBPF programs can be attached to perf_events ● 4.10: eBPF programs can be attached to cgroups ● 4.15: eBPF LSM hooks
  • 13. eBPF as a VM ● Example assembly of a simple eBPF filter ● Load 16-bit quantity from offset 12 in the packet to the accumulator (ethernet type) ● Compare the value to see if the packet is an IP packet ● If the packet is IP, return TRUE (packet is accepted) ● otherwise return 0 (packet is rejected) ● Only 4 VM instructions to filter IP packets! ldh [12] jeq #ETHERTYPE_IP, l1, l2 l1: ret #TRUE l2: ret #0
  • 16. BCC tracing tools ● BPF Compiler Collection ● Front-end to eBPF ● BCC makes eBPF programs easier to write – Include C wrapper around LLVM – Python – Lua – C++ – C helper libs ● golang (gobpf) ● https://github.com/iovisor/gobpf https://github.com/iovisor/bcc
  • 18. Example #1: trace exec() ● Intercept all the processes executed in the system
  • 19. Example #2: keylogger ● Identify where and how keyboard characters are received and processed by the kernel
  • 20. Example #3: ping ● Identify where ICMP packets (ECHO_REQUEST / ECHO_REPLY) are received and processed by the kernel
  • 21. Example #4: task wait / wakeup ● Determine the stack trace of a sleeping process and the stack trace of the process that wakes up a sleeping process
  • 22. Conclusion ● Real-time tracing as a method to study the kernel ● Understanding what the kernel is doing can help to improve your application / service in terms of performance, reliability and security
  • 23. References ● Brendan Gregg blog ● http://brendangregg.com/blog/ ● BCC tools ● https://github.com/iovisor/bcc ● gobpf (BPF bindings for go): ● https://github.com/iovisor/gobpf ● The BSD Packet Filter: A New Architecture for User-level Packet Capture - S. McCanne and V. Jacobson ● http://www.tcpdump.org/papers/bpf-usenix93.pdf