All Projects → souvik1997 → Kernel Roulette

souvik1997 / Kernel Roulette

Licence: gpl-3.0
A kernel module written in Rust

Programming Languages

c
50402 projects - #5 most used programming language
rust
11053 projects

Projects that are alternatives of or similar to Kernel Roulette

Juniper
GraphQL server library for Rust
Stars: ✭ 4,187 (+3276.61%)
Mutual labels:  rust-library, cargo
Bifrost
Pure rust building block for distributed systems
Stars: ✭ 118 (-4.84%)
Mutual labels:  rust-library
Udev Joystick Blacklist
Fix for keyboard/mouse/tablet being detected as joystick in Linux
Stars: ✭ 97 (-21.77%)
Mutual labels:  linux-kernel
Virtualcar
A virtual car. Because you wouldn't download a car, would you?
Stars: ✭ 114 (-8.06%)
Mutual labels:  linux-kernel
Cargo Embed
a cargo extension for working with microcontrollers
Stars: ✭ 100 (-19.35%)
Mutual labels:  cargo
Liquorix Package
Liquorix Debian Package
Stars: ✭ 114 (-8.06%)
Mutual labels:  linux-kernel
Lpic 1 Anki Flashcards
Deck of Anki flashcards for the LPIC-1 (Linux System Administrator) exams 101 and 102 of the Linux Professional Institute (LPI).
Stars: ✭ 90 (-27.42%)
Mutual labels:  linux-kernel
Crate2nix
nix build file generator for rust crates
Stars: ✭ 123 (-0.81%)
Mutual labels:  cargo
Gust
A small charting/visualization tool and partial vega implementation for Rust
Stars: ✭ 116 (-6.45%)
Mutual labels:  rust-library
Ltp
Linux Test Project http://linux-test-project.github.io/
Stars: ✭ 1,654 (+1233.87%)
Mutual labels:  linux-kernel
Grammers
(tele)gramme.rs - use Telegram's API from Rust
Stars: ✭ 109 (-12.1%)
Mutual labels:  rust-library
Corrosion
Marrying Rust and CMake - Easy Rust and C/C++ Integration!
Stars: ✭ 106 (-14.52%)
Mutual labels:  cargo
Raspberry Pi Os
Learning operating system development using Linux kernel and Raspberry Pi
Stars: ✭ 11,000 (+8770.97%)
Mutual labels:  linux-kernel
Xia For Linux
XIA implementation for the Linux kernel
Stars: ✭ 98 (-20.97%)
Mutual labels:  linux-kernel
Huawei Wmi
Huawei WMI laptop extras linux driver
Stars: ✭ 120 (-3.23%)
Mutual labels:  linux-kernel
Audit Check
🛡️ GitHub Action for security audits
Stars: ✭ 90 (-27.42%)
Mutual labels:  cargo
Meta Rust
OpenEmbedded/Yocto layer for Rust and Cargo
Stars: ✭ 108 (-12.9%)
Mutual labels:  cargo
Ckernel
中国Linux内核开发者大会
Stars: ✭ 115 (-7.26%)
Mutual labels:  linux-kernel
Ndctl
Helper tools and libraries for managing the libnvdimm (non-volatile memory device) sub-system in the Linux kernel
Stars: ✭ 122 (-1.61%)
Mutual labels:  linux-kernel
Tera
A template engine for Rust based on Jinja2/Django
Stars: ✭ 1,873 (+1410.48%)
Mutual labels:  rust-library

kernel-roulette: play Russian Roulette with the Linux kernel

kernel-roulette is a simple Linux kernel module written in Rust and C that implements a character device driver for a virtual device. When this virtual device is read, there is a chance that the system will crash with a kernel panic *.

More importantly, it demonstrates how to build a kernel module with Rust. The rust code uses #![no_std] to disable the standard library, but we can still use the following:

  • the core crate
  • the alloc crate, which includes data structures such as Vec that use dynamic memory allocation.
  • macros like println!() to print to the dmesg buffer.

*: It actually uses the BUG() macro to show a stack trace in dmesg, which doesn't crash the system but leaves it in a somewhat inconsistent state. If you really want it to panic replace abort() with panic_c() in src/lang.rs:31.

Dependencies

  • Linux kernel headers and build-essential (gcc, make, etc.)

  • Nightly Rust (install from https://rustup.rs)

  • Xargo and rust-src

    Download the Rust library source with rustup component add rust-src

    Install xargo with cargo install xargo

  • sudo access

Building

  • Run make from the project directory
  • Run sudo insmod build/roulette.ko
  • Run dmesg | tail -n 10 and verify that the kernel module was loaded. You should see something like:
[   35.735871] IPv6: ADDRCONF(NETDEV_UP): enp4s0: link is not ready
[   39.123353] r8169 0000:04:00.0 enp4s0: link up
[   39.123364] IPv6: ADDRCONF(NETDEV_CHANGE): enp4s0: link becomes ready
[  792.965067] roulette: loading out-of-tree module taints kernel.
[  792.965070] roulette: module license 'unspecified' taints kernel.
[  792.965070] Disabling lock debugging due to kernel taint
[  792.965236] roulette: module verification failed: signature and/or required key missing - tainting kernel
[  792.966321] Registered kernel-roulette with major device number 243
[  792.966322] Run /bin/mknod /dev/kernel-roulette c 243 0
[  793.477624] Panic probability: 10/100
  • Follow the instructions in dmesg: in this case you would run sudo /bin/mknod /dev/kernel-roulette c 243 0
  • Run cat /dev/kernel-roulette
  • Unload the module with sudo rmmod build/roulette.ko

Acknowledgements

License

GPL 3

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].