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: <4df4e3a0-9caa-4253-bf65-66c238bf0291@gmail.com>
Date: Tue, 22 Apr 2025 11:42:46 +0200
From: Christian Schrefl <chrisi.schrefl@...il.com>
To: Benno Lossin <benno.lossin@...ton.me>, Miguel Ojeda <ojeda@...nel.org>,
 Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>,
 Gary Guo <gary@...yguo.net>, Björn Roy Baron
 <bjorn3_gh@...tonmail.com>, Andreas Hindborg <a.hindborg@...nel.org>,
 Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
 Danilo Krummrich <dakr@...nel.org>, Fiona Behrens <me@...enk.dev>
Cc: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 3/8] rust: pin-init: Implement `Wrapper` for
 `UnsafePinned` behind feature flag.

On 22.04.25 12:18 AM, Benno Lossin wrote:
> From: Christian Schrefl <chrisi.schrefl@...il.com>
> 
> Add the `unsafe-pinned` feature which gates the `Wrapper`
> implementation of the `core::pin::UnsafePinned` struct.
> 
> For now this is just a cargo feature, but once `core::pin::UnsafePinned`
> is stable a config flag can be added to allow the usage of this
> implementation in the linux kernel.
> 
> Signed-off-by: Christian Schrefl <chrisi.schrefl@...il.com>
> Link: https://github.com/Rust-for-Linux/pin-init/pull/37/commits/99cb1934425357e780ea5b0628f66633123847b8
> [ Fixed commit authorship. - Benno ]
> Signed-off-by: Benno Lossin <benno.lossin@...ton.me>
> ---
>  rust/pin-init/src/lib.rs | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/rust/pin-init/src/lib.rs b/rust/pin-init/src/lib.rs
> index 467ccc8bd616..745cf534d239 100644
> --- a/rust/pin-init/src/lib.rs
> +++ b/rust/pin-init/src/lib.rs
> @@ -269,6 +269,10 @@
>  #![forbid(missing_docs, unsafe_op_in_unsafe_fn)]
>  #![cfg_attr(not(feature = "std"), no_std)]
>  #![cfg_attr(feature = "alloc", feature(allocator_api))]
> +#![cfg_attr(
> +    all(feature = "unsafe-pinned", CONFIG_RUSTC_HAS_UNSAFE_PINNED),
> +    feature(unsafe_pinned)
> +)]
>  
>  use core::{
>      cell::UnsafeCell,
> @@ -1557,3 +1561,11 @@ fn pin_init<E>(value_init: impl PinInit<T, E>) -> impl PinInit<Self, E> {
>          unsafe { cast_pin_init(value_init) }
>      }
>  }
> +
> +#[cfg(all(feature = "unsafe-pinned", CONFIG_RUSTC_HAS_UNSAFE_PINNED))]
> +impl<T> Wrapper<T> for core::pin::UnsafePinned<T> {
> +    fn pin_init<E>(init: impl PinInit<T, E>) -> impl PinInit<Self, E> {
> +        // SAFETY: `UnsafePinned<T>` has a compatible layout to `T`.
> +        unsafe { cast_pin_init(init) }
> +    }
> +}

I've realized that for us to use `UnsafePinned` in `Opaque` internally 
we need to have a `T: ?Sized` for this implementation. `cast_pin_init`
won't work for that since we can't cast pointers between different DSTs.
We could add something similar that uses a closure to convert a
`*mut T` to `*mut U`.

That won't really be relevant until we actually use 
`core::pin::UnsafePinned` however.

Should I do another PR to extend this to `T: ?Sized`?

Cheers
Christian

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ