eBPF implementation that runs on top of Windows
Перейти к файлу
Dave Thaler 7c12adb067
Prevent mismatched program types in PROG_ARRAY maps (#374)
* Prevent mismatched program types in PROG_ARRAY maps

* Each prog array map has a natural progtype, determined when
  asociating it from a program, or when adding the first program
  to it, if not associated with any program.
* Trying to add a program with mismatching type will fail
* Added libbpf bpf_create_map() API
* Fixed error returns from several libbpf APIs to be negative
* For efficiency, ebpf_program_get_properties now returns a
  pointer rather than copying the data inside the execution
  context, and is renamed to ebpf_program_get_parameters()
  to match what its return type always was.
* Fixed a bug in map size calculation that resulted in a huge
  amount of memory being allocated
* Updated return type of bpf_tail_call to the value meant
  to signal stack unwind needed

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-08-11 12:17:10 -07:00
.github Add scheduled CodeQL workflow (#318) 2021-06-29 13:50:01 -07:00
docs Test Extension Part 2 (#361) 2021-08-07 14:19:00 -07:00
ebpfapi Prevent mismatched program types in PROG_ARRAY maps (#374) 2021-08-11 12:17:10 -07:00
ebpfcore Set device type to something _open_osfhandle understands (#346) 2021-07-26 17:06:12 -06:00
ebpfsvc Add eBPF UM APIs (#368) 2021-08-10 17:04:07 -07:00
external Prevent mismatched program types in PROG_ARRAY maps (#374) 2021-08-11 12:17:10 -07:00
include Prevent mismatched program types in PROG_ARRAY maps (#374) 2021-08-11 12:17:10 -07:00
libs Prevent mismatched program types in PROG_ARRAY maps (#374) 2021-08-11 12:17:10 -07:00
netebpfext Verify that program type is supported by attach provider (#348) 2021-07-27 16:33:58 -07:00
rpc_interface Replace "information" with "info" for consistency (#331) 2021-07-07 11:16:35 -07:00
scripts Test Extension Part 2 (#361) 2021-08-07 14:19:00 -07:00
tests Prevent mismatched program types in PROG_ARRAY maps (#374) 2021-08-11 12:17:10 -07:00
tools Prevent mismatched program types in PROG_ARRAY maps (#374) 2021-08-11 12:17:10 -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 setup_build project to install git hook 2021-03-05 21:46:30 -08:00
.gitignore API to create map and enumerate all pinned maps. (#246) 2021-06-09 09:44:24 -06:00
.gitmodules Libbpf API compatibility (#350) 2021-07-30 15:34:21 -07:00
Analyze.default.ruleset Add prog array map type and bpf_tail_call() helper (#359) 2021-08-06 14:18:47 -06:00
CONTRIBUTING.md Update CONTRIBUTING.md to include notes on closure of bugs (#305) 2021-06-25 08:31:22 -07:00
Directory.Build.props Add configuration option to run code analysis (#301) 2021-06-24 12:53:51 -06: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 Update README.md (#285) 2021-06-17 12:02:23 -07:00
ebpf-for-windows.sln Test Extension Part 2 (#361) 2021-08-07 14:19:00 -07:00
mainpage.dox Improve doxygen main page (#340) 2021-07-26 09:17:54 -07:00

README.md

eBPF for Windows

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 using 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 eBPF tutorial.

Architectural Overview

The following diagram shows the 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 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 user-mode protected process (a Windows security environment that allows a kernel component to trust a user-mode daemon signed by a key that it trusts). If the bytecode passes all the verifier checks, it can be either loaded into an interpreter (from uBPF in the kernel-mode execution context), or JIT compiled (via the uBPF JIT compiler) and have native code load into the kernel-mode execution context (but see the FAQ at bottom about HVCI).

Temporary Note: some parts are still under development and may not appear when building the master branch, but the end-to-end functionality can still be tested immediately while the security hardening is still in progress.

eBPF programs installed into the kernel-mode execution context can attach to various hooks (currently two hooks so far: an XDP-like hook that is based on the Windows Filtering Platform (WFP) layer 2 filtering, and a socket bind hook) 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. More hooks and helpers will be added over time.

Getting Started

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

Want to help? We welcome contributions! See our Contributing guidelines.

Want to chat with us? We have a:

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)?

eBPF programs can be run either in an interpreter or natively using a JIT compiler.

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.