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: <DDXF7TVFW1TE.2X34Z4X771Z73@nvidia.com>
Date: Sat, 01 Nov 2025 23:16:58 +0900
From: "Alexandre Courbot" <acourbot@...dia.com>
To: "Danilo Krummrich" <dakr@...nel.org>, <gregkh@...uxfoundation.org>,
 <rafael@...nel.org>, <ojeda@...nel.org>, <alex.gaynor@...il.com>,
 <boqun.feng@...il.com>, <gary@...yguo.net>, <bjorn3_gh@...tonmail.com>,
 <lossin@...nel.org>, <a.hindborg@...nel.org>, <aliceryhl@...gle.com>,
 <tmgross@...ch.edu>, <mmaurer@...gle.com>
Cc: <rust-for-linux@...r.kernel.org>, <linux-fsdevel@...r.kernel.org>,
 <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v3 03/10] rust: uaccess: add
 UserSliceReader::read_slice_file()

On Wed Oct 22, 2025 at 11:30 PM JST, Danilo Krummrich wrote:
> Add UserSliceReader::read_slice_file(), which is the same as
> UserSliceReader::read_slice_partial() but updates the given file::Offset
> by the number of bytes read.
>
> This is equivalent to C's `simple_write_to_buffer()` and useful when
> dealing with file offsets from file operations.
>
> Signed-off-by: Danilo Krummrich <dakr@...nel.org>
> ---
>  rust/kernel/uaccess.rs | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
>
> diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs
> index c1cd3a76cff8..c2d3dfee8934 100644
> --- a/rust/kernel/uaccess.rs
> +++ b/rust/kernel/uaccess.rs
> @@ -9,6 +9,7 @@
>      bindings,
>      error::Result,
>      ffi::{c_char, c_void},
> +    fs::file,
>      prelude::*,
>      transmute::{AsBytes, FromBytes},
>  };
> @@ -303,6 +304,30 @@ pub fn read_slice_partial(&mut self, out: &mut [u8], offset: usize) -> Result<us
>              .map_or(Ok(0), |dst| self.read_slice(dst).map(|()| dst.len()))
>      }
>  
> +    /// Reads raw data from the user slice into a kernel buffer partially.
> +    ///
> +    /// This is the same as [`Self::read_slice_partial`] but updates the given [`file::Offset`] by
> +    /// the number of bytes read.
> +    ///
> +    /// This is equivalent to C's `simple_write_to_buffer()`.
> +    ///
> +    /// On success, returns the number of bytes read.
> +    pub fn read_slice_file(&mut self, out: &mut [u8], offset: &mut file::Offset) -> Result<usize> {
> +        if offset.is_negative() {
> +            return Err(EINVAL);
> +        }
> +
> +        let Ok(offset_index) = (*offset).try_into() else {
> +            return Ok(0);
> +        };
> +
> +        let read = self.read_slice_partial(out, offset_index)?;
> +
> +        *offset = offset.saturating_add_usize(read);
> +
> +        Ok(read)

Not sure whether this would be better, but you can avoid the `read`
local variable with the following:

    self.read_slice_partial(out, offset_index)
        .inspect(|&read| *offset = offset.saturating_add_usize(read))

In any case,

Reviewed-by: Alexandre Courbot <acourbot@...dia.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ