• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

fishinabarrel/linux-kernel-module-rust: Framework for writing Linux kernel modul ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

fishinabarrel/linux-kernel-module-rust

开源软件地址(OpenSource Url):

https://github.com/fishinabarrel/linux-kernel-module-rust

开源编程语言(OpenSource Language):

Rust 94.6%

开源软件介绍(OpenSource Introduction):

Linux kernel modules in safe Rust

For most purposes, if you're interested in writing Linux kernel modules in Rust, you should look at https://github.com/Rust-for-Linux/linux, which is an effort to contribute that process to the upstream kernel.

This is a framework for writing loadable Linux kernel modules in Rust, using safe abstractions around kernel interfaces and primitives.

For more information on the motivation and goals for this project, check out our presentation at Linux Security Summit North America 2019 and the video on YouTube. We're immediately focusing on making this project viable for out-of-tree modules, but we also see this project as a testing ground for whether in-tree components could be written in Rust.

There is a simple demo module in the hello-world directory, as well as various other examples in the tests/ directory.

Design

We run bindgen on the kernel headers to generate automatic Rust FFI bindings. bindgen is powered by Clang, so we use the kernel's own build system to determine the appropriate CFLAGS. Then we write safe bindings to these types (see the various files inside src/).

Each kernel module in Rust lives in a staticlib crate, which generates a .a file. We pass this object to the Linux kernel's own module build system for linking into a .ko.

The kernel is inherently multi-threaded: kernel resources can be accessed from multiple userspace processes at once, which causes multiple threads of execution inside the kernel to handle system calls (or interrupts). Therefore, the KernelModule type is Sync, so all data shared by a kernel module must be safe to access concurrently (such as by implementing locking).

System requirements

We're currently only running CI on Linux 4.15 (Ubuntu Xenial) on amd64, although we intend to support kernels from 4.4 through the latest release. Please report a bug (or better yet, send in a patch!) if your kernel doesn't work.

Other architectures aren't implemented yet, but should work as long as there's Rust and LLVM support - see #112 for expected status. They'll need src/c_types.rs ported, too.

You'll need to have Rust - in particular Rust nightly, as we use some unstable features - and Clang installed. You need LLVM/Clang 9 (released September 2019) or higher for multiple reasons, primarily support for asm goto. If you're on Debian, Ubuntu, or a derivative, https://apt.llvm.org is great.

If the binary named clang is too old, make sure to set the CC or CLANG environment variable appropriately, e.g., CC=clang-9.

Very recent kernels may require newer versions of Clang - try Clang 11 if older versions don't work for you.

Building hello-world

  1. Install clang, kernel headers, and the rust-src and rustfmt components from rustup:
apt-get install llvm clang linux-headers-"$(uname -r)" # or the equivalent for your OS
rustup component add --toolchain=nightly rust-src rustfmt
  1. cd to one of the examples
cd hello-world
  1. Build the kernel module using the Linux kernel build system (kbuild), this will invoke cargo to build the Rust code
make
  1. Load and unload the module!
sudo insmod helloworld.ko
sudo rmmod helloworld
dmesg | tail



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap