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] [day] [month] [year] [list]
Message-ID: <aJ2W4kgJGJPItC9F@google.com>
Date: Thu, 14 Aug 2025 07:57:22 +0000
From: Alice Ryhl <aliceryhl@...gle.com>
To: "Benoît du Garreau" <benoit@...arreau.fr>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>, Alexander Viro <viro@...iv.linux.org.uk>, 
	Arnd Bergmann <arnd@...db.de>, Miguel Ojeda <ojeda@...nel.org>, 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>, 
	Trevor Gross <tmgross@...ch.edu>, Danilo Krummrich <dakr@...nel.org>, Matthew Maurer <mmaurer@...gle.com>, 
	Lee Jones <lee@...nel.org>, linux-kernel@...r.kernel.org, 
	rust-for-linux@...r.kernel.org, Benno Lossin <lossin@...nel.org>
Subject: Re: [PATCH v4 2/4] rust: iov: add iov_iter abstractions for ITER_DEST

On Wed, Aug 13, 2025 at 03:33:39PM +0200, Benoît du Garreau wrote:
> On Wed, 13 Aug 2025 08:27:18 +0000 Alice Ryhl <aliceryhl@...gle.com> wrote:
> 
> > +    /// Utility for implementing `read_iter` given the full contents of the file.
> > +    ///
> > +    /// The full contents of the file being read from is represented by `contents`. This call will
> > +    /// write the appropriate sub-slice of `contents` and update the file position in `ppos` so
> > +    /// that the file will appear to contain `contents` even if takes multiple reads to read the
> > +    /// entire file.
> > +    #[inline]
> > +    pub fn simple_read_from_buffer(&mut self, ppos: &mut i64, contents: &[u8]) -> Result<usize> {
> > +        if *ppos < 0 {
> > +            return Err(EINVAL);
> > +        }
> > +        let Ok(pos) = usize::try_from(*ppos) else {
> > +            return Ok(0);
> > +        };
> > +        if pos >= contents.len() {
> > +            return Ok(0);
> > +        }
> > +
> > +        // BOUNDS: We just checked that `pos < contents.len()` above.
> > +        let num_written = self.copy_to_iter(&contents[pos..]);
> 
> This should use `contents.get(..pos)` instead of doing the bound check manually.

Using contents.get(pos..) does not have the same behavior as the bounds
check, because the bounds check exits early with Ok(0) if pos is equal
to contents.len(), whereas the proposed change would pass an empty array
to copy_to_iter.

Alice

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ