1 // SPDX-License-Identifier: GPL-2.0
3 //! Helper crate for KASAN testing.
5 //! Provides behavior to check the sanitization of Rust code.
7 use core::ptr::addr_of_mut;
8 use kernel::prelude::*;
10 /// Trivial UAF - allocate a big vector, grab a pointer partway through,
11 /// drop the vector, and touch it.
13 pub extern "C" fn kasan_test_rust_uaf() -> u8 {
14 let mut v: KVec<u8> = KVec::new();
16 v.push(0x42, GFP_KERNEL).unwrap();
18 let ptr: *mut u8 = addr_of_mut!(v[2048]);
20 // SAFETY: Incorrect, on purpose.