1 // SPDX-License-Identifier: GPL-2.0 1 // SPDX-License-Identifier: GPL-2.0 2 2 3 //! Helper crate for KASAN testing. 3 //! Helper crate for KASAN testing. 4 //! 4 //! 5 //! Provides behavior to check the sanitizatio 5 //! Provides behavior to check the sanitization of Rust code. 6 6 7 use core::ptr::addr_of_mut; 7 use core::ptr::addr_of_mut; 8 use kernel::prelude::*; 8 use kernel::prelude::*; 9 9 10 /// Trivial UAF - allocate a big vector, grab 10 /// Trivial UAF - allocate a big vector, grab a pointer partway through, 11 /// drop the vector, and touch it. 11 /// drop the vector, and touch it. 12 #[no_mangle] 12 #[no_mangle] 13 pub extern "C" fn kasan_test_rust_uaf() -> u8 13 pub extern "C" fn kasan_test_rust_uaf() -> u8 { 14 let mut v: Vec<u8> = Vec::new(); 14 let mut v: Vec<u8> = Vec::new(); 15 for _ in 0..4096 { 15 for _ in 0..4096 { 16 v.push(0x42, GFP_KERNEL).unwrap(); 16 v.push(0x42, GFP_KERNEL).unwrap(); 17 } 17 } 18 let ptr: *mut u8 = addr_of_mut!(v[2048]); 18 let ptr: *mut u8 = addr_of_mut!(v[2048]); 19 drop(v); 19 drop(v); 20 unsafe { *ptr } 20 unsafe { *ptr } 21 } 21 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.