linux-stable/rust/kernel
Boqun Feng b3d8aa84bb rust: allocator: Prevent mis-aligned allocation
Currently the rust allocator simply passes the size of the type Layout
to krealloc(), and in theory the alignment requirement from the type
Layout may be larger than the guarantee provided by SLAB, which means
the allocated object is mis-aligned.

Fix this by adjusting the allocation size to the nearest power of two,
which SLAB always guarantees a size-aligned allocation. And because Rust
guarantees that the original size must be a multiple of alignment and
the alignment must be a power of two, then the alignment requirement is
satisfied.

Suggested-by: Vlastimil Babka <vbabka@suse.cz>
Co-developed-by: "Andreas Hindborg (Samsung)" <nmi@metaspace.dk>
Signed-off-by: "Andreas Hindborg (Samsung)" <nmi@metaspace.dk>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Cc: stable@vger.kernel.org # v6.1+
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Fixes: 247b365dc8 ("rust: add `kernel` crate")
Link: https://github.com/Rust-for-Linux/linux/issues/974
Link: https://lore.kernel.org/r/20230730012905.643822-2-boqun.feng@gmail.com
[ Applied rewording of comment as discussed in the mailing list. ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-08-04 17:10:31 +02:00
..
init rust: init: update macro expansion example in docs 2023-05-31 18:53:10 +02:00
sync rust: sync: reword the Arc safety comment for Sync 2023-05-31 18:53:10 +02:00
allocator.rs rust: allocator: Prevent mis-aligned allocation 2023-08-04 17:10:31 +02:00
build_assert.rs rust: upgrade to Rust 1.68.2 2023-05-31 17:35:03 +02:00
error.rs rust: error: impl Debug for Error with errname() integration 2023-06-13 01:24:42 +02:00
init.rs rust: upgrade to Rust 1.68.2 2023-05-31 17:35:03 +02:00
ioctl.rs rust: ioctl: Add ioctl number manipulation functions 2023-04-22 01:46:45 +02:00
lib.rs rust: upgrade to Rust 1.68.2 2023-05-31 17:35:03 +02:00
prelude.rs rust: introduce current 2023-04-22 00:20:00 +02:00
print.rs rust: kernel: Mark rust_fmt_argument as extern "C" 2023-04-06 23:11:04 +02:00
static_assert.rs rust: static_assert: add static_assert! macro 2022-12-04 01:59:16 +01:00
std_vendor.rs rust: upgrade to Rust 1.68.2 2023-05-31 17:35:03 +02:00
str.rs rust: str: add conversion from CStr to CString 2023-05-31 18:53:10 +02:00
sync.rs rust: sync: introduce CondVar 2023-04-22 01:46:45 +02:00
task.rs rust: task: add Send marker to Task 2023-05-31 18:53:10 +02:00
types.rs rust: specify when ARef is thread safe 2023-05-31 18:53:10 +02:00