forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Co-developed-by: "Andreas Hindborg (Samsung)" <[email protected]> Signed-off-by: "Andreas Hindborg (Samsung)" <[email protected]> Signed-off-by: Boqun Feng <[email protected]> Cc: [email protected] # v6.1+ Acked-by: Vlastimil Babka <[email protected]> Fixes: 247b365 ("rust: add `kernel` crate") Link: Rust-for-Linux#974 Link: https://lore.kernel.org/r/[email protected] [ Applied rewording of comment as discussed in the mailing list. ] Signed-off-by: Miguel Ojeda <[email protected]>
- Loading branch information
Showing
2 changed files
with
60 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters