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: <CAH5fLgj+U_9_GsFk5cJw_t6UdOsZsQkBtRz5cG-iHgTuj=qY7g@mail.gmail.com>
Date: Tue, 3 Sep 2024 13:34:05 +0200
From: Alice Ryhl <aliceryhl@...gle.com>
To: Benno Lossin <benno.lossin@...ton.me>
Cc: 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>, 
	Andreas Hindborg <a.hindborg@...sung.com>, rust-for-linux@...r.kernel.org, 
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/2] rust: sync: require `Sync` for `Backend::GuardState`

On Tue, Sep 3, 2024 at 12:06 PM Benno Lossin <benno.lossin@...ton.me> wrote:
>
> On 03.09.24 11:32, Alice Ryhl wrote:
> > On Tue, Sep 3, 2024 at 11:17 AM Benno Lossin <benno.lossin@...ton.me> wrote:
> >>
> >> `Guard<T, B>` implements `Sync` when `T` is `Sync`. Since this does not
> >> depend on `B`, creating a `Guard` that is `Sync`, but with `!Sync` state
> >> is possible. This is a soundness issue, thus add the bounds to the
> >> respective impls.
> >>
> >> Signed-off-by: Benno Lossin <benno.lossin@...ton.me>
> >
> > Right now, a `&Guard<T, B>` has exactly the same powers as &T, as the
> > only thing you can do on the guard with only a shared reference is
> > deref to a &T. So the bounds are correct as they are, unless new APIs
> > are added (which seems unlikely?).
>
> Right, but I thought it was strange not to require that. Since that
> would be the default behavior of the `Sync` auto-trait. And the only
> reason why we have to implement `Sync` is because we want it to be
> `!Send` with the `PhantomData<*mut ()>`.
>
> All of our locks currently use `()` as the guard state, so we don't lose
> anything.
>
> Maybe it might make sense to instead have a marker type that is `!Send`
> but `Sync` that can be used here instead, since then we could avoid the
> `unsafe impl Sync`.

I think it's actually quite reasonable to `unsafe impl Sync` for lock
guards. The lock guard in std is also rather special in regards to its
Sync implementation, since it also has a situation where Send deals
with special details of the guard, but Sync does not.

Alice

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ