Closed
Description
This program writes to arbitrary memory, violating Rust's safety guarantees, despite using no unsafe code:
use std::fs;
use std::io;
use std::io::prelude::*;
fn main() {
let i = 0;
let j = &i as *const i32 as u64;
let mut f = fs::OpenOptions::new().write(true).open("/proc/self/mem").unwrap();
f.seek(io::SeekFrom::Start(j+16)).unwrap();
let k = [16; 16];
f.write(&k).unwrap();
}
Because the filesystem APIs cannot be made safe (blocking /proc
paths specifically will not work, because symlinks can be created to it), File::create
, File::open
, and OpenOptions::open
should be marked unsafe. I am working on an RFC for that right now.