lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DBCP0OLEAHAW.JC4AQHMVQW81@kernel.org>
Date: Tue, 15 Jul 2025 16:19:53 +0200
From: "Danilo Krummrich" <dakr@...nel.org>
To: "Alice Ryhl" <aliceryhl@...gle.com>
Cc: "Lorenzo Stoakes" <lorenzo.stoakes@...cle.com>, "Liam R. Howlett"
 <Liam.Howlett@...cle.com>, "Andrew Morton" <akpm@...ux-foundation.org>,
 "Matthew Wilcox" <willy@...radead.org>, "Tamir Duberstein"
 <tamird@...il.com>, "Andreas Hindborg" <a.hindborg@...nel.org>, "Miguel
 Ojeda" <ojeda@...nel.org>, "Boqun Feng" <boqun.feng@...il.com>, "Gary Guo"
 <gary@...yguo.net>, Björn Roy Baron
 <bjorn3_gh@...tonmail.com>, "Benno Lossin" <lossin@...nel.org>, "Trevor
 Gross" <tmgross@...ch.edu>, <linux-mm@...ck.org>,
 <rust-for-linux@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 2/2] rust: alloc: take the allocator into account for
 FOREIGN_ALIGN

On Tue Jul 15, 2025 at 3:46 PM CEST, Alice Ryhl wrote:
> diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs
> index bffe72f44cb33a265018e67d92d9f0abe82f8e22..fd3f1e0b9c3b3437fb50d8f1b28c92bc7cefd565 100644
> --- a/rust/kernel/alloc/kbox.rs
> +++ b/rust/kernel/alloc/kbox.rs
> @@ -400,12 +400,19 @@ fn try_init<E>(init: impl Init<T, E>, flags: Flags) -> Result<Self, E>
>  }
>  
>  // SAFETY: The pointer returned by `into_foreign` comes from a well aligned
> -// pointer to `T`.
> +// pointer to `T` allocated by `A`.
>  unsafe impl<T: 'static, A> ForeignOwnable for Box<T, A>
>  where
>      A: Allocator,
>  {
> -    const FOREIGN_ALIGN: usize = core::mem::align_of::<T>();
> +    const FOREIGN_ALIGN: usize = {
> +        let mut align = core::mem::align_of::<T>();
> +        if align < A::MIN_ALIGN {
> +            align = A::MIN_ALIGN;
> +        }
> +        align
> +    };

Pretty unfortunate that core::cmp::max() can't be used from const context. :(

What do you think about

	const FOREIGN_ALIGN: usize =
	    if core::mem::align_of::<T>() < A::MIN_ALIGN {
	        A::MIN_ALIGN
	    } else {
	        core::mem::align_of::<T>()
	    };

instead? I think that reads a bit better.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ