[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DA7Y9ELFKI6U.32MUDCD0VQEE2@kernel.org>
Date: Wed, 28 May 2025 18:55:08 +0200
From: "Benno Lossin" <lossin@...nel.org>
To: "Alice Ryhl" <aliceryhl@...gle.com>, "Miguel Ojeda" <ojeda@...nel.org>,
"Alexander Viro" <viro@...iv.linux.org.uk>, "Greg Kroah-Hartman"
<gregkh@...uxfoundation.org>, "Arnd Bergmann" <arnd@...db.de>
Cc: "Andrew Morton" <akpm@...ux-foundation.org>, "Boqun Feng"
<boqun.feng@...il.com>, "Gary Guo" <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>, "Benno Lossin"
<benno.lossin@...ton.me>, "Andreas Hindborg" <a.hindborg@...nel.org>,
"Trevor Gross" <tmgross@...ch.edu>, "Danilo Krummrich" <dakr@...nel.org>,
<rust-for-linux@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2] uaccess: rust: use newtype for user pointers
On Tue May 27, 2025 at 3:53 PM CEST, Alice Ryhl wrote:
> In C code we use sparse with the __user annotation to detect cases where
> a user pointer is mixed up with other things. To replicate that, we
> introduce a new struct UserPtr that serves the same purpose using the
> newtype pattern.
>
> The UserPtr type is not marked with #[derive(Debug)], which means that
Should we still implement it, not printing the address of course? So
something like `UserPtr(/* .. */)` or whatever people print instead of
showing the address?
> it's not possible to print values of this type. This avoids ASLR
> leakage.
>
> The type is added to the prelude as it is a fairly fundamental type
> similar to c_int. The wrapping_add() method is renamed to
> wrapping_byte_add() for consistency with the method name found on raw
> pointers.
>
> Signed-off-by: Alice Ryhl <aliceryhl@...gle.com>
I left one question below, but it already looks good, so:
Reviewed-by: Benno Lossin <lossin@...nel.org>
> @@ -444,7 +484,11 @@ fn raw_strncpy_from_user(dst: &mut [MaybeUninit<u8>], src: UserPtr) -> Result<us
>
> // SAFETY: `dst` is valid for writing `dst.len()` bytes.
> let res = unsafe {
> - bindings::strncpy_from_user(dst.as_mut_ptr().cast::<c_char>(), src as *const c_char, len)
> + bindings::strncpy_from_user(
> + dst.as_mut_ptr().cast::<c_char>(),
> + src.as_const_ptr().cast::<c_char>(),
Should we also have `as_{const,mut}_char_ptr` functions? After a quick
search, I found that `char __user *` is a common type for user pointers.
---
Cheers,
Benno
> + len,
> + )
> };
Powered by blists - more mailing lists