RustForge

rust-kernel

Rustbelt: a hobby x86_64 kernel written in Rust

rust-kernel / user / evil.rs
604 bytes ยท raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//! A misbehaving program: tries to read kernel memory directly. The kernel's
//! pages aren't USER_ACCESSIBLE, so the CPU raises a page fault, and the
//! kernel kills this process (and carries on).
#![no_std]
#![no_main]

#[macro_use]
#[path = "ulib.rs"]
mod ulib;

fn main() -> i64 {
    let kernel_code = 0x20_0000 as *const u64; // where the kernel is loaded
    println!("[evil] pid {}: reading kernel memory at {:p}...", ulib::getpid(), kernel_code);
    let value = unsafe { core::ptr::read_volatile(kernel_code) };
    println!("[evil] got {:#x} -- this must never be printed!", value);
    1
}