Giter VIP home page Giter VIP logo

kernel-roulette's Introduction

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

kernel-roulette's People

Contributors

souvik1997 avatar tomoyuki-nakabayashi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

kernel-roulette's Issues

Undefined symbols

Hi,

The make succeeds for me, but I'm getting the following warnings. Any idea on what could be going wrong here?

I'm using rust nightly (1.35), clang 5.0 and linux kernel 4.20.6+.

WARNING: "sample" [/usr/src/kernel-roulette/build/roulette.ko] undefined!
WARNING: "get_chance" [/usr/src/kernel-roulette/build/roulette.ko] undefined!
WARNING: "rust_mod_init" [/usr/src/kernel-roulette/build/roulette.ko] undefined!
WARNING: "rust_mod_exit" [/usr/src/kernel-roulette/build/roulette.ko] undefined!

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.