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: <20230806170831.5d9f73a5.gary@garyguo.net>
Date:   Sun, 6 Aug 2023 17:08:31 +0100
From:   Gary Guo <gary@...yguo.net>
To:     Benno Lossin <benno.lossin@...ton.me>
Cc:     Miguel Ojeda <ojeda@...nel.org>,
        Wedson Almeida Filho <wedsonaf@...il.com>,
        Alex Gaynor <alex.gaynor@...il.com>,
        Boqun Feng <boqun.feng@...il.com>,
        Björn Roy Baron <bjorn3_gh@...tonmail.com>,
        Alice Ryhl <aliceryhl@...gle.com>,
        Andreas Hindborg <nmi@...aspace.dk>,
        rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3 10/13] rust: init: implement `Zeroable` for
 `UnsafeCell<T>` and `Opaque<T>`

On Sat, 29 Jul 2023 09:10:19 +0000
Benno Lossin <benno.lossin@...ton.me> wrote:

> `UnsafeCell<T>` and `T` have the same layout so if `T` is `Zeroable`
> then so should `UnsafeCell<T>` be. This allows using the derive macro
> for `Zeroable` on types that contain an `UnsafeCell<T>`.
> Since `Opaque<T>` contains a `MaybeUninit<T>`, all bytes zero is a valid
> bit pattern for that type.
> 
> Signed-off-by: Benno Lossin <benno.lossin@...ton.me>

Reviewed-by: Gary Guo <gary@...yguo.net>

> ---
> v2 -> v3:
> - also implement Zeroable for `UnsafeCell<T>` when `T: Zeroable`,
> - use `impl_zeroable!` instead of `derive(Zeroable)`.
> 
>  rust/kernel/init.rs | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs
> index af96d4acc26b..06ecab4901f2 100644
> --- a/rust/kernel/init.rs
> +++ b/rust/kernel/init.rs
> @@ -212,10 +212,12 @@
>  use crate::{
>      error::{self, Error},
>      sync::UniqueArc,
> +    types::Opaque,
>  };
>  use alloc::boxed::Box;
>  use core::{
>      alloc::AllocError,
> +    cell::UnsafeCell,
>      convert::Infallible,
>      marker::PhantomData,
>      mem::MaybeUninit,
> @@ -1157,6 +1159,11 @@ macro_rules! impl_zeroable {
>  
>      // SAFETY: Type is allowed to take any value, including all zeros.
>      {<T>} MaybeUninit<T>,
> +    // SAFETY: Type is allowed to take any value, including all zeros.
> +    {<T>} Opaque<T>,
> +
> +    // SAFETY: `T: Zeroable` and `UnsafeCell` is `repr(transparent)`.
> +    {<T: ?Sized + Zeroable>} UnsafeCell<T>,
>  
>      // SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee).
>      Option<NonZeroU8>, Option<NonZeroU16>, Option<NonZeroU32>, Option<NonZeroU64>,

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ