[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CACQBu=UqBHD6XfVbjGfc+0i93TLJNrrHCrzHuzkd=vVU8H+RVQ@mail.gmail.com>
Date: Wed, 11 Jun 2025 20:55:12 +0200
From: Burak Emir <bqe@...gle.com>
To: Pekka Ristola <pekkarr@...tonmail.com>
Cc: Yury Norov <yury.norov@...il.com>, Kees Cook <kees@...nel.org>,
Rasmus Villemoes <linux@...musvillemoes.dk>, Viresh Kumar <viresh.kumar@...aro.org>,
Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
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>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
"Gustavo A . R . Silva" <gustavoars@...nel.org>, Carlos LLama <cmllamas@...gle.com>,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-hardening@...r.kernel.org
Subject: Re: [PATCH v11 4/5] rust: add find_bit_benchmark_rust module.
On Thu, Jun 5, 2025 at 11:37 PM Pekka Ristola <pekkarr@...tonmail.com> wrote:
>
> On Monday, June 2nd, 2025 at 16.53, Burak Emir <bqe@...gle.com> wrote:
[...]
> > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> > index f9051ab610d5..3f826a73bdbf 100644
> > --- a/lib/Kconfig.debug
> > +++ b/lib/Kconfig.debug
> > @@ -2605,6 +2605,19 @@ config FIND_BIT_BENCHMARK
> >
> > If unsure, say N.
> >
> > +config FIND_BIT_BENCHMARK_RUST
> > + tristate "Test find_bit functions in Rust"
> > + depends on CONFIG_RUST
>
> The `CONFIG_` prefix should be removed.
Done.
[...]
> > diff --git a/rust/kernel/bitmap.rs b/rust/kernel/bitmap.rs
> > index 28c11e400d1e..9fefb2473099 100644
> > --- a/rust/kernel/bitmap.rs
> > +++ b/rust/kernel/bitmap.rs
> > @@ -252,6 +252,20 @@ pub fn new(nbits: usize, flags: Flags) -> Result<Self, AllocError> {
> > pub fn len(&self) -> usize {
> > self.nbits
> > }
> > +
> > + /// Fills this `Bitmap` with random bits.
> > + #[cfg(CONFIG_FIND_BIT_BENCHMARK_RUST)]
> > + pub fn fill_random(&mut self) {
> > + // SAFETY: `self.as_mut_ptr` points to either an array of the
> > + // appropriate length or one usize.
> > + unsafe {
> > + bindings::get_random_bytes(
> > + self.as_mut_ptr() as *mut ffi::c_void,
> > + usize::div_ceil(self.nbits, bindings::BITS_PER_LONG as usize)
> > + * bindings::BITS_PER_LONG as usize,
>
> I think the second argument to `get_random_bytes` should be in bytes, not
> bits. So it should be multiplied by "bytes per long", not "bits per long".
Thanks for catching this. At least I had memory safety in mind when I
overflowed the buffer (facepalm)!
Fixed.
Cheers,
-- Burak
Powered by blists - more mailing lists