[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CALNs47sMJzeZ0yEF9sc-VO_QEu4=jc3QBa1_fhnhX9gdETYaNA@mail.gmail.com>
Date: Sun, 29 Sep 2024 19:16:14 -0400
From: Trevor Gross <tmgross@...ch.edu>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: Miguel Ojeda <ojeda@...nel.org>, Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Kees Cook <kees@...nel.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@...sung.com>,
Carlos Llamas <cmllamas@...gle.com>, rust-for-linux@...r.kernel.org,
linux-hardening@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/2] rust: harden index manipulation using ownership
On Fri, Sep 13, 2024 at 5:01 PM Alice Ryhl <aliceryhl@...gle.com> wrote:
> +//! Utilities for working with ranges of indices.
> +
> +/// A range of indices.
> +///
> +/// This utility is useful for ensuring that no index in the range is used more than once.
> +#[derive(Debug)]
> +pub struct Range {
> + offset: usize,
> + length: usize,
> +}
Would a name like "DataRange" or "CheckedRange" be better here, to
avoid confusion with core::ops::Range?
> + /// Use this range of indices.
> + ///
> + /// This destroys the `Range` object, so these indices cannot be used again after this call.
> + pub fn use_range(self) -> UsedRange {
Maybe just `.use()`?
> + /// Assert that this range is aligned properly.
> + pub fn assert_aligned(&self, alignment: usize) -> Result<(), RangeError> {
It would probably be good to warn that this alignment is relative to
the offset, i.e. if you split a range at an unaligned point then this
may not be useful.
This is a pretty cool API idea.
- Trevor
Powered by blists - more mailing lists