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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b0d2a93e-4f23-4751-ab70-12c8357c46c6@de.bosch.com>
Date: Tue, 1 Jul 2025 13:41:44 +0200
From: Dirk Behme <dirk.behme@...bosch.com>
To: Matthew Maurer <mmaurer@...gle.com>, 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>, Greg Kroah-Hartman
	<gregkh@...uxfoundation.org>, "Rafael J. Wysocki" <rafael@...nel.org>, "Sami
 Tolvanen" <samitolvanen@...gle.com>, Timur Tabi <ttabi@...dia.com>, "Benno
 Lossin" <lossin@...nel.org>
CC: <linux-kernel@...r.kernel.org>, <rust-for-linux@...r.kernel.org>
Subject: Re: [PATCH v8 3/6] rust: types: Support &'static and &'static mut
 ForeignOwnable

On 28/06/2025 01:18, Matthew Maurer wrote:
> These types live forever and do not require cleanup, so they can
> serve as `ForeignOwnable`.
> 
> Tested-by: Dirk Behme <dirk.behme@...bosch.com>
> Signed-off-by: Matthew Maurer <mmaurer@...gle.com>
> ---
>  rust/kernel/types.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 58 insertions(+)
> 
> diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
> index 22985b6f69820d6df8ff3aae0bf815fad36a9d92..0a2b15cd05f91c69ef9c678555b845a23c19b82c 100644
> --- a/rust/kernel/types.rs
> +++ b/rust/kernel/types.rs
> @@ -142,6 +142,64 @@ unsafe fn borrow<'a>(_: *mut Self::PointedTo) -> Self::Borrowed<'a> {}
>      unsafe fn borrow_mut<'a>(_: *mut Self::PointedTo) -> Self::BorrowedMut<'a> {}
>  }
>  
> +// SAFETY: The `into_foreign` function derives its pointer from a reference, so it is correctly
> +// aligned.
> +unsafe impl<T: 'static> ForeignOwnable for &'static T {
> +    type PointedTo = T;
> +    type Borrowed<'a> = &'a T;
> +    type BorrowedMut<'a> = &'a T;
> +
...
> +// SAFETY: The `into_foreign` function derives its pointer from a reference, so it is correctly
> +// aligned.
> +unsafe impl<T: 'static> ForeignOwnable for &'static mut T {
> +    type PointedTo = T;
> +    type Borrowed<'a> = &'a T;
> +    type BorrowedMut<'a> = &'a mut T;

Just fyi, depending on what hits mainline first, this patch series or

https://lore.kernel.org/rust-for-linux/20250626200054.243480-5-dakr@kernel.org/

the latter might need something like [1].

Dirk

[1]

diff --git a/rust/kernel/debugfs/display_file.rs
b/rust/kernel/debugfs/display_file.rs
index b38675a90e1b..9cea3bd633dc 100644
--- a/rust/kernel/debugfs/display_file.rs
+++ b/rust/kernel/debugfs/display_file.rs
@@ -102,6 +102,7 @@ pub(crate) struct BorrowedAdapter<'a, D:
ForeignOwnable, F> {
 // SAFETY: We delegate to D's implementation of `ForeignOwnable`, so
`into_foreign` produced aligned
 // pointers.
 unsafe impl<D: ForeignOwnable, F> ForeignOwnable for FormatAdapter<D, F> {
+    type Target = D;
     type PointedTo = D::PointedTo;
     type Borrowed<'a> = BorrowedAdapter<'a, D, F>;
     type BorrowedMut<'a> = Self::Borrowed<'a>;
diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
index ffbd750e1eda..c2d87e077c8f 100644
--- a/rust/kernel/types.rs
+++ b/rust/kernel/types.rs
@@ -149,6 +149,7 @@ unsafe fn borrow_mut<'a>(_: *mut Self::PointedTo) ->
Self::BorrowedMut<'a> {}
 // SAFETY: The `into_foreign` function derives its pointer from a
reference, so it is correctly
 // aligned.
 unsafe impl<T: 'static> ForeignOwnable for &'static T {
+    type Target = T;
     type PointedTo = T;
     type Borrowed<'a> = &'a T;
     type BorrowedMut<'a> = &'a T;
@@ -176,6 +177,7 @@ unsafe fn borrow_mut<'a>(foreign: *mut
Self::PointedTo) -> Self::BorrowedMut<'a>
 // SAFETY: The `into_foreign` function derives its pointer from a
reference, so it is correctly
 // aligned.
 unsafe impl<T: 'static> ForeignOwnable for &'static mut T {
+    type Target = T;
     type PointedTo = T;
     type Borrowed<'a> = &'a T;
     type BorrowedMut<'a> = &'a mut T;

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ