[Paper Review] MOAT: Towards Safe BPF Kernel Extension
Moat proposes a hardware-assisted, low-overhead isolation mechanism for untrusted BPF programs using Intel Memory Protection Keys (MPK) to prevent kernel memory exploitation. It addresses MPK's limited key space via a dynamic/fixed key allocation scheme and secures BPF helper functions through group-based defense policies, achieving 6% average throughput loss in real-world workloads while mitigating all examined CVEs.
The Linux kernel extensively uses the Berkeley Packet Filter (BPF) to allow user-written BPF applications to execute in the kernel space. The BPF employs a verifier to check the security of user-supplied BPF code statically. Recent attacks show that BPF programs can evade security checks and gain unauthorized access to kernel memory, indicating that the verification process is not flawless. In this paper, we present MOAT, a system that isolates potentially malicious BPF programs using Intel Memory Protection Keys (MPK). Enforcing BPF program isolation with MPK is not straightforward; MOAT is designed to alleviate technical obstacles, such as limited hardware keys and the need to protect a wide variety of BPF helper functions. We implement MOAT on Linux (ver. 6.1.38), and our evaluation shows that MOAT delivers low-cost isolation of BPF programs under mainstream use cases, such as isolating a BPF packet filter with only 3% throughput loss.
Motivation & Objective
- To address the growing security risks in BPF due to verifier limitations and zero-day exploits in kernel memory access.
- To enable hardware-enforced isolation of untrusted BPF programs using Intel Memory Protection Keys (MPK), despite hardware constraints like limited key availability.
- To securely support the extensive BPF helper function ecosystem without per-function policy hardcoding.
- To design a scalable, low-overhead key allocation strategy that supports concurrent BPF programs under MPK's 16-key limit.
- To evaluate Moat's effectiveness in mitigating real-world BPF vulnerabilities and measuring performance overhead in production-like scenarios.
Proposed method
- Leverages Intel Memory Protection Keys (MPK) to isolate BPF programs by assigning distinct keys to kernel and BPF program memory regions.
- Introduces a dynamic/fixed key allocation scheme to efficiently manage the limited 16 MPK keys across multiple concurrent BPF programs.
- Performs static dependency analysis on BPF helper functions to group them into security policy clusters, reducing policy maintenance overhead.
- Applies two-tier defense schemes—per-group policies and runtime checks—to prevent misuse of helper functions by malicious BPF programs.
- Integrates with the existing BPF verifier to use its analysis results for safe key assignment and access control enforcement.
- Implements a prototype kernel module to evaluate isolation, performance, and exploit mitigation in real-world workloads.
Experimental results
Research questions
- RQ1Can MPK-based isolation effectively prevent untrusted BPF programs from accessing kernel memory, even when the BPF verifier is bypassed?
- RQ2How can the limited number of MPK keys (16) be efficiently reused to support multiple concurrent BPF programs?
- RQ3Can a scalable, group-based defense model for BPF helper functions prevent exploitation without per-function policy configuration?
- RQ4What is the performance overhead of Moat in real-world BPF workloads, such as packet forwarding and database acceleration?
- RQ5To what extent does Moat mitigate known BPF vulnerabilities, including recent CVEs?
Key findings
- Moat successfully mitigates all examined CVEs related to BPF, including those in bpf_ringbuf and verifier bypasses via corner-case operations.
- The prototype achieves an average throughput loss of only 6% when isolating a BPF-based packet-forwarding program for memcached.
- The dynamic/fixed key allocation scheme effectively supports multiple concurrent BPF programs within the 16-key MPK limit with minimal overhead.
- The group-based helper function defense model reduces policy complexity and enables extensibility for new helpers without new policy definitions.
- Moat’s isolation mechanism remains effective even under edge-case workloads, demonstrating robustness across diverse BPF usage patterns.
- The evaluation confirms that Moat provides strong security guarantees with acceptable performance cost, making it viable for production deployment.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.