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: <0f6c4fb3-039a-4dc6-a07c-980ca06ecbeb@kernel.org>
Date: Wed, 14 Aug 2024 14:08:00 +0200
From: Danilo Krummrich <dakr@...nel.org>
To: Dirk Behme <dirk.behme@...bosch.com>
Cc: ojeda@...nel.org, alex.gaynor@...il.com, wedsonaf@...il.com,
 boqun.feng@...il.com, gary@...yguo.net, bjorn3_gh@...tonmail.com,
 benno.lossin@...ton.me, a.hindborg@...sung.com, aliceryhl@...gle.com,
 akpm@...ux-foundation.org, daniel.almeida@...labora.com,
 faith.ekstrand@...labora.com, boris.brezillon@...labora.com,
 lina@...hilina.net, mcanal@...lia.com, zhiw@...dia.com, cjia@...dia.com,
 jhubbard@...dia.com, airlied@...hat.com, ajanulgu@...hat.com,
 lyude@...hat.com, linux-kernel@...r.kernel.org,
 rust-for-linux@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [PATCH v5 11/26] rust: alloc: remove `BoxExt` extension

Hi Dirk,

On 8/14/24 1:55 PM, Dirk Behme wrote:
> On 12.08.2024 20:22, Danilo Krummrich wrote:
>> Now that all existing `Box` users were moved to the kernel `Box` type,
>> remove the `BoxExt` extension and all other related extensions.
> I just noticed that in the recent 'rust-dev' branch we have a change which *adds* something to BoxExt:
> 
> rust: kernel: add drop_contents to BoxExt
> https://github.com/Rust-for-Linux/linux/commit/62c34da1da6c01a635ea2308cb42996d0571059e
> 
> I'm unclear how relevant that is. Just want to mention this in case it would make sense to include that directly in this patch series to avoid a future add-on patch ;)

Thanks for reporting. I'm aware of this patch, we expect it to land before this series.
I'll add `drop_contents` once I rebase onto it.

- Danilo

> 
> Thanks,
> 
> Dirk
> 
> P.S.: It looks like anything like this at least makes the compiler happy:
> 
> diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs
> index d67f975502246..e91d441835d54 100644
> --- a/rust/kernel/alloc/kbox.rs
> +++ b/rust/kernel/alloc/kbox.rs
> @@ -9,6 +9,7 @@
>   use core::mem::MaybeUninit;
>   use core::ops::{Deref, DerefMut};
>   use core::pin::Pin;
> +use core::ptr;
>   use core::ptr::NonNull;
>   use core::result::Result;
> 
> @@ -270,6 +271,28 @@ pub fn new_uninit(flags: Flags) -> Result<Box<MaybeUninit<T>, A>, AllocError> {
>           Ok(Box(ptr, PhantomData::<A>))
>       }
> 
> +    /// Drops the contents, but keeps the allocation.
> +    ///
> +    /// # Examples
> +    ///
> +    /// ```
> +    /// use kernel::alloc::{Flags, KBox};
> +    /// let value = KBox::new([0; 32], GFP_KERNEL)?;
> +    /// assert_eq!(*value, [0; 32]);
> +    /// let value = KBox::drop_contents(value);
> +    /// // Now we can re-use `value`:
> +    /// let value = KBox::write(value, [1; 32]);
> +    /// assert_eq!(*value, [1; 32]);
> +    /// # Ok::<(), Error>(())
> +    /// ```
> +    pub fn drop_contents(this: Self) -> Box<MaybeUninit<T>, A> {
> +        let ptr = Box::into_raw(this);
> +        // SAFETY: `ptr` is valid, because it came from `Box::into_raw`.
> +        unsafe { ptr::drop_in_place(ptr) };
> +        // SAFETY: `ptr` is valid, because it came from `Box::into_raw`.
> +        unsafe { Box::from_raw(ptr.cast()) }
> +    }
> +
>       /// Constructs a new `Pin<Box<T, A>>`. If `T` does not implement [`Unpin`], then `x` will be
>       /// pinned in memory and can't be moved.
>       #[inline]

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ