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