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: <d83155b4-1c73-4191-85b6-55d1b904a926@de.bosch.com>
Date: Wed, 14 Aug 2024 13:55:09 +0200
From: Dirk Behme <dirk.behme@...bosch.com>
To: Danilo Krummrich <dakr@...nel.org>, <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>
CC: <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

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,

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