eBPF implementation that runs on top of Windows
Перейти к файлу
Alan Jowett 2a73f8cd54
Expression short circuiting causes skipping of ebpf_api_close_handle (#1663)
* Expression short circuiting causes skipping of ebpf_api_close_handle

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Fix code analysis failure

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Anurag Saxena <43585259+saxena-anurag@users.noreply.github.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-11-18 12:15:39 -07:00
.github Bump dawidd6/action-download-artifact from 2.24.0 to 2.24.2 (#1625) 2022-11-13 13:06:06 -07:00
cmake Build self-contained Convert-BpfToNative.ps1 (#1097) 2022-05-16 16:27:38 -06:00
docs Spelling (#1601) 2022-11-16 14:06:14 -07:00
ebpfapi Fuzz test netebpfext helper(s) (#1467) 2022-11-08 09:31:04 +00:00
ebpfcore Spelling (#1601) 2022-11-16 14:06:14 -07:00
ebpfsvc Spelling (#1601) 2022-11-16 14:06:14 -07:00
external Resolve conflict when updating ubpf (#1609) 2022-11-14 22:49:57 -08:00
images Bump windows/nanoserver in /images (#1489) 2022-10-22 12:07:37 -07:00
include Spelling (#1601) 2022-11-16 14:06:14 -07:00
libs Fix code scanning alert - Comparison of narrow type with wide type in… (#1594) 2022-11-18 09:11:30 -08:00
manifests/Kubernetes Added support for host-process container installation (#1099) 2022-05-31 09:42:53 -07:00
netebpfext Fuzz test netebpfext helper(s) (#1467) 2022-11-08 09:31:04 +00:00
resource Bump version to 0.5.0 (#1444) 2022-10-03 13:42:37 -07:00
rpc_interface Increase instruction count limit (#1152) 2022-05-31 16:02:05 -07:00
scripts Emulate driver verifier systematic low memory mode (#1512) 2022-11-09 15:28:09 -07:00
tests Expression short circuiting causes skipping of ebpf_api_close_handle (#1663) 2022-11-18 12:15:39 -07:00
tools Spelling (#1601) 2022-11-16 14:06:14 -07:00
.clang-format Fix build by restoring header ordering dependencies and turning off sort 2021-03-09 16:25:24 -08:00
.gitattributes Add libfuzzer based fuzzer. (#1117) 2022-05-27 16:31:04 -07:00
.gitignore Move generated include to include (#564) 2021-09-17 17:13:14 -06:00
.gitmodules dependabot's tracking for 'gitmodules' is failing (#1589) 2022-11-07 20:09:10 -07:00
Analyze.default.ruleset Add prog array map type and bpf_tail_call() helper (#359) 2021-08-06 14:18:47 -06:00
CMakeLists.txt cmakefile (#1075) 2022-05-13 18:23:18 -06:00
CONTRIBUTING.md Remove trailing whitespace in commited files (#1377) 2022-08-29 14:15:46 -06:00
Directory.Build.props Fuzz test netebpfext helper(s) (#1467) 2022-11-08 09:31:04 +00:00
Doxyfile Add main API reference page (#329) 2021-07-07 10:39:59 -07:00
LICENSE.txt Add prereqs to readme file 2021-02-12 16:18:45 -08:00
README.md Add diagrams and discussion of native driver execution type (#974) 2022-04-19 16:59:31 -07:00
ebpf-for-windows.sln Add bpf2c_plugin for use with bpf_conformance test suite (#1475) 2022-10-25 13:26:49 -06:00
mainpage.dox Fix doc link (#1338) 2022-08-23 12:46:50 -07:00

README.md

eBPF for Windows

CodeQL CII Best Practices codecov

eBPF is a well-known technology for providing programmability and agility, especially for extending an OS kernel, for use cases such as DoS protection and observability. This project is a work-in-progress that allows existing eBPF toolchains and APIs familiar in the Linux ecosystem to be used on top of Windows. That is, this project takes existing eBPF projects as submodules and adds the layer in between to make them run on top of Windows.

New to eBPF?

See our basic eBPF tutorial and our tutorial on debugging eBPF verification failures.

Architectural Overview

The following diagram shows the basic architecture of this project and related components:

Architectural Overview

As shown in the diagram, existing eBPF toolchains (clang, etc.) can be used to generate eBPF bytecode from source code in various languages. Bytecode can be consumed by any application, or via bpftool or the Netsh command line tool, which use a shared library that exposes Libbpf APIs, though this is still in progress.

The eBPF bytecode is sent to a static verifier (the PREVAIL verifier) that is hosted in a secure user-mode environment such as a system service (which is the case at present), enclave, or trusted VM. If the eBPF program passes all the verifier checks, it can be loaded into the kernel-mode execution context. Typically this is done by being JIT compiled (via the uBPF JIT compiler) into native code that is passed to the execution context. In a debug build, the byte code can instead be directly loaded into an interpreter (from uBPF in the kernel-mode execution context) though the interpreter is not present in a release build as it is considered less secure. See also the HVCI FAQ answer below.

eBPF programs installed into the kernel-mode execution context can attach to various hooks and call various helper APIs exposed by the eBPF shim, which internally wraps public Windows kernel APIs, allowing the use of eBPF on existing versions of Windows. Many helpers already exist, and more hooks and helpers will be added over time.

Getting Started

This project supports eBPF on Windows 10 or later, and on Windows Server 2019 or later. To try out this project, see our Getting Started Guide.

Want to help? We welcome contributions! See our Contributing guidelines. Feel free to take a look at our Good First Issues list if you're looking for somewhere to start.

Want to chat with us? We have a:

For tracking Q&A and general discussion, we use Discussions in github. This can also function similar to a mailing list if you subscribe to discussion notifications by clicking "Watch" (or "Unwatch") and selecting "Custom" -> "Discussions" (or by selecting "All Activity" if you want to receive notifications about everything else too).

Frequently Asked Questions

1. Is this a fork of eBPF?

No.

The eBPF for Windows project leverages existing projects, including the IOVisor uBPF project and the PREVAIL verifier, running them on top of Windows by adding the Windows-specific hosting environment for that code.

2. Does this provide app compatibility with eBPF programs written for Linux?

The intent is to provide source code compatibility for code that uses common hooks and helpers that apply across OS ecosystems.

Linux provides many hooks and helpers, some of which are very Linux specific (e.g., using Linux internal data structs) that would not be applicable to other platforms. Other hooks and helpers are generically applicable and the intent is to support them for eBPF programs.

Similarly, the eBPF for Windows project exposes Libbpf APIs to provide source code compatibility for applications that interact with eBPF programs.

3. Will eBPF work with HyperVisor-enforced Code Integrity (HVCI)?

Yes. With HVCI enabled, eBPF programs cannot be JIT compiled, but can be run either natively or in interpreted mode (but the interpreter is disabled in release builds and is only supported in debug builds). To understand why JIT compiled mode does not work, we must first understand what HVCI does.

HyperVisor-enforced Code Integrity (HVCI) is a mechanism whereby a hypervisor, such as Hyper-V, uses hardware virtualization to protect kernel-mode processes against the injection and execution of malicious or unverified code. Code integrity validation is performed in a secure environment that is resistant to attack from malicious software, and page permissions for kernel mode are set and maintained by the hypervisor.

Since a hypervisor doing such code integrity checks will refuse to accept code pages that aren't signed by a key that the hypervisor trusts, this does impact eBPF programs running natively. As such, when HVCI is enabled, eBPF programs work fine in interpreted mode, but not when using JIT compilation because the JIT compiler does not have a key that the hypervisor trusts. And since interpreted mode is absent in release builds, neither mode will work on an HVCI-enabled production system.

Instead, a third mode is also supported by eBPF for Windows, in addition to JIT compiled and interpreted modes. This third mode entails compiling eBPF programs into regular Windows drivers that can be accepted by HVCI. For more discussion, see the Native Code Generation documentation.