[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CANiq72m1DyAVx4=bg9Hmiayp8jsQsYBirb33S=YN8ptmEu3XsQ@mail.gmail.com>
Date: Mon, 2 Sep 2024 11:39:05 +0200
From: Miguel Ojeda <miguel.ojeda.sandonis@...il.com>
To: Boqun Feng <boqun.feng@...il.com>
Cc: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Wedson Almeida Filho <wedsonaf@...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>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>
Subject: Re: [RFC PATCH] rust: Provide correct provenance when constructing THIS_MODULE
On Wed, Aug 28, 2024 at 8:02 PM Boqun Feng <boqun.feng@...il.com> wrote:
>
> Currently while defining `THIS_MODULE` symbol in `module!()`, the
> pointer used to contruct `ThisModule` is derived from an immutable
> reference of `__this_module`, which means the pointer doesn't have
> the provenance for writting, and that means any write to that pointer
> is UB regardless of data races or not. However, the usage of
> `THIS_MODULE` includes passing this pointer to functions that may write
> to it (probably in unsafe code), and this will create soundness issues.
>
> One way to fix this is using `addr_of_mut!()` but that requires the
> unstable feature "const_mut_refs". So instead of `addr_of_mut()!`,
> an extern static `Opaque` is used here: since `Opaque<T>` is transparent
> to `T`, an extern static `Opaque` will just wrap the C symbol (defined
> in a C compile unit) in an `Opaque`, which provides a pointer with
> writable provenance via `Opaque::get()`. This fix the potential UBs
> because of pointer provenance unmatched.
>
> Reported-by: Alice Ryhl <aliceryhl@...gle.com>
> Signed-off-by: Boqun Feng <boqun.feng@...il.com>
Applied to `rust-fixes` -- thanks everyone!
Closes: https://rust-for-linux.zulipchat.com/#narrow/stream/x/topic/x/near/465412664
Fixes: 1fbde52bde73 ("rust: add `macros` crate")
Cc: stable@...r.kernel.org # 6.6.x: be2ca1e03965: ("rust: types:
Make Opaque::get const")
[ Fixed two typos, reworded title. - Miguel ]
For 6.1 we will send a targeted patch via Option 3 instead of
cherry-picking `Opaque` and a bunch of other bits that would be
required.
Cheers,
Miguel
Powered by blists - more mailing lists