Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v6.17-rc7 22 lines 592 B view raw
1// SPDX-License-Identifier: GPL-2.0 2 3//! Helper crate for KASAN testing. 4//! 5//! Provides behavior to check the sanitization of Rust code. 6 7use core::ptr::addr_of_mut; 8use kernel::prelude::*; 9 10/// Trivial UAF - allocate a big vector, grab a pointer partway through, 11/// drop the vector, and touch it. 12#[no_mangle] 13pub extern "C" fn kasan_test_rust_uaf() -> u8 { 14 let mut v: KVec<u8> = KVec::new(); 15 for _ in 0..4096 { 16 v.push(0x42, GFP_KERNEL).unwrap(); 17 } 18 let ptr: *mut u8 = addr_of_mut!(v[2048]); 19 drop(v); 20 // SAFETY: Incorrect, on purpose. 21 unsafe { *ptr } 22}