Goal: Implement automated and efficient checks for memory initialization in Kani.
Motivation
Safe Rust guarantees that every variable is initialized, and every reference points to a properly allocated and initialized memory position. The same guarantees do not apply to raw pointers, transmute operations and unions, which are available in unsafe Rust. The safe usage of these constructs and operations must be upheld by the Rust developer.
Failures to uphold these safety properties can have unwanted consequences: it can affect the application behavior and even result in the application exposing critical data.
Kani should be able to detect uninitialized memory accesses automatically and efficiently.
Examples
Currently, Kani does not catch the following cases of UB due to accessing uninitialized memory:
#[repr(C)]
struct S(u32, u8);
#[kani::proof]
fn check_uninit_padding() {
let s = S(0, 0);
let ptr: *const u8 = addr_of!(s) as *const u8;
let padding = unsafe { *(ptr.add(5)) }; // ~ERROR: padding bytes are uninitialized, so reading them is UB.
}
#[kani::proof]
fn check_vec_read_uninit() {
let v: Vec<u8> = Vec::with_capacity(10);
let uninit = unsafe { *v.as_ptr().add(5) }; // ~ERROR: reading from unitialized memory is UB.
}
Tasks
Goal: Implement automated and efficient checks for memory initialization in Kani.
Motivation
Safe Rust guarantees that every variable is initialized, and every reference points to a properly allocated and initialized memory position. The same guarantees do not apply to raw pointers, transmute operations and unions, which are available in unsafe Rust. The safe usage of these constructs and operations must be upheld by the Rust developer.
Failures to uphold these safety properties can have unwanted consequences: it can affect the application behavior and even result in the application exposing critical data.
Kani should be able to detect uninitialized memory accesses automatically and efficiently.
Examples
Currently, Kani does not catch the following cases of UB due to accessing uninitialized memory:
Tasks
copyandcopy_nonoverlapping(Checking memory initialization in presence ofcopyandcopy_nonoverlappingproduces false positives #3347, Implement memory initialization state copy functionality #3350)enums with variants that have different paddingunions (Add better support forMaybeUninit#896)extern statics