百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
K

kernel-wasm

> 编程语言
开源

沙箱内核模式 WebAssembly 运行时。

761 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

沙箱内核模式 WebAssembly 运行时。

kernel-wasm

Safely run WebAssembly in the Linux kernel, with faster-than-native performance.

Background

I wrote Cervus, another WebAssembly "usermode" subsystem running in Linux kernel, about one year ago. At that time we didn't yet have WASI or any "production-ready" non-Web runtimes, though the Cervus project has proved that the idea is possible and of great potential.

Now the WASM ecosystem is growing, and it's time to build a complete in-kernel WASM runtime for real applications.

Features

  • WASI support (incomplete; work in progress)
  • Asynchronous networking extension with epoll support
  • Modular host API provider interface
  • Fully sandboxed execution environment with software fault isolation
  • Faster than native (partially achieved)
  • Device drivers in WASM
  • "eBPF" in WASM

Why run WebAssembly in the kernel?

Performance and flexibility.

Since WASM is a virtual ISA protected by a virtual machine, we don't need to rely on external hardware and software checks to ensure safety. Running WASM in the kernel avoids most of the overhead introduced by those checks, e.g. system call (context switching) and copy_{from,to}_user, therefore improving performance.

Also, having low-level control means that we can implement a lot of features that were heavy or impossible in userspace, like virtual memory tricks and handling of intensive kernel events (like network packet filtering).

Examples and benchmark

There are two examples (echo-server and http-server) in the examples directory of Wasmer main repo, implementing features as their names suggest.

When compiled with the singlepass backend (unoptimized direct x86-64 code generation) and benchmarked using tcpkali/wrk, echo-server is ~10% faster (25210 Mbps / 22820 Mbps) than its native equivalent, and http-server is ~6% faster (53293 Rps / 50083 Rps). Even higher performance is expected when the other two Wasmer backends with optimizations (Cranelift/LLVM) are updated to support generating code for the kernel.

Those two examples use both WASI (for file abstraction and printing) and the asynchronous networking extension (via the kwasm-net crate). Take a look at them to learn how to do high-performance networking in kernel-wasm.

Build and run

Check and ensure that:

  • Your system is running Linux kernel 4.15 or higher.
  • Your kernel has preemption enabled. Attempting to run WASM user code without kernel preemption will freeze your system.
  • Kernel headers are installed and the building environment is properly set up.

Then just run make in the root directory, and (optionally) networking and wasi:

make

Install the modules into /lib/modules/`uname -r`/extra

make install

Load the modules:

bash
sudo modprobe kernel-wasm
sudo modprobe kwasm-networking
sudo modprobe kwasm-wasi

Run wasmer with the kernel loader and singlepass backend:

bash
sudo wasmer run --backend singlepass --disable-cache --loader kernel your_wasm_file.wasm

Security

Running user code in kernel mode is always a dangerous thing. Although we use many techniques to protect against different kinds of malicious code and attacks, it's advised that only trusted binaries should be run through this module, in a short term before we fully reviewed the codebase for security.

Currently known security risks and their solutions:

  • Stack overflow check (implemented with explicit bound checking in codegen)
  • Memory bound check (implemented with 6GB virtual address space)
  • Forceful termination (implemented by setting NX on code pages)
  • Floating point register save/restore (implemented with kernel_fpu_{begin,end} and preempt_notifier)

License

GPLv2, as required for linking to the Linux kernel.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言