mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-28 16:56:26 +00:00
58eff8e872
Now that we got the kernel `Vec` in place, convert all existing `Vec` users to make use of it. Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Gary Guo <gary@garyguo.net> Signed-off-by: Danilo Krummrich <dakr@kernel.org> Link: https://lore.kernel.org/r/20241004154149.93856-20-dakr@kernel.org [ Converted `kasan_test_rust.rs` too, as discussed. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
23 lines
592 B
Rust
23 lines
592 B
Rust
// 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 {
|
|
let mut v: KVec<u8> = KVec::new();
|
|
for _ in 0..4096 {
|
|
v.push(0x42, GFP_KERNEL).unwrap();
|
|
}
|
|
let ptr: *mut u8 = addr_of_mut!(v[2048]);
|
|
drop(v);
|
|
// SAFETY: Incorrect, on purpose.
|
|
unsafe { *ptr }
|
|
}
|