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: <20250813133343.7877-1-benoit@dugarreau.fr>
Date: Wed, 13 Aug 2025 15:33:39 +0200
From: Benoît du Garreau <benoit@...arreau.fr>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: Benoît du Garreau <benoit@...arreau.fr>,
	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, 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.

> +
> +        // OVERFLOW: `pos+num_written <= contents.len() <= isize::MAX <= i64::MAX`.
> +        *ppos = (pos + num_written) as i64;
> +
> +        Ok(num_written)
> +    }

Benoît du Garreau

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ