2024-08-20 19:48:59 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
//! Helper crate for KASAN testing.
|
|
|
|
//!
|
|
|
|
//! Provides behavior to check the sanitization of Rust code.
|
|
|
|
|
|
|
|
use core::ptr::addr_of_mut;
|
|
|
|
use kernel::prelude::*;
|
|
|
|
|
|
|
|
/// Trivial UAF - allocate a big vector, grab a pointer partway through,
|
|
|
|
/// drop the vector, and touch it.
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn kasan_test_rust_uaf() -> u8 {
|
2024-10-04 17:41:23 +02:00
|
|
|
let mut v: KVec<u8> = KVec::new();
|
2024-08-20 19:48:59 +00:00
|
|
|
for _ in 0..4096 {
|
|
|
|
v.push(0x42, GFP_KERNEL).unwrap();
|
|
|
|
}
|
|
|
|
let ptr: *mut u8 = addr_of_mut!(v[2048]);
|
|
|
|
drop(v);
|
2024-09-04 22:43:32 +02:00
|
|
|
// SAFETY: Incorrect, on purpose.
|
2024-08-20 19:48:59 +00:00
|
|
|
unsafe { *ptr }
|
|
|
|
}
|