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: <682b9957.050a0220.3d035.a5e1@mx.google.com>
Date: Mon, 19 May 2025 13:49:25 -0700
From: Boqun Feng <boqun.feng@...il.com>
To: Jann Horn <jannh@...gle.com>
Cc: Burak Emir <bqe@...gle.com>, 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>, 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>,
	rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
	linux-hardening@...r.kernel.org
Subject: Re: [PATCH v8 3/5] rust: add bitmap API.

On Mon, May 19, 2025 at 10:36:52PM +0200, Jann Horn wrote:
> On Mon, May 19, 2025 at 10:08 PM Burak Emir <bqe@...gle.com> wrote:
> > On Mon, May 19, 2025 at 9:01 PM Jann Horn <jannh@...gle.com> wrote:
> > > On Mon, May 19, 2025 at 6:24 PM Burak Emir <bqe@...gle.com> wrote:
> > > > +    /// Set bit with index `index`, atomically.
> > > > +    ///
> > > > +    /// ATTENTION: The naming convention differs from C, where the corresponding
> > > > +    /// function is called `set_bit`.
> > > > +    ///
> > > > +    /// # Safety
> > > > +    ///
> > > > +    /// This is a relaxed atomic operation (no implied memory barriers, no
> > > > +    /// ordering guarantees). The caller must ensure that this is safe, as
> > > > +    /// the compiler cannot prevent code with an exclusive reference from
> > > > +    /// calling atomic operations.
> > >
> > > How can atomic operations through an exclusive reference be unsafe?
> > > You can't have a data race between two atomic operations, and an
> > > exclusive reference should anyway prevent any concurrency, right?
> >
> > The atomic operations take a &self (shared reference).
> >
> > The patch is missing the implementation of Sync for now. With that,
> > one would get concurrent write access through shared references.
> >
> > The "unsafe" here should serve as reminder to argue why it is ok to
> > not have any ordering guarantees.

I don't think ordering is safety related. For example, relaxed atomics
are still safe function. I think it's wrong to mark this as unsafe, do
you have an example that you can construct an UB with pure safe code?

Regards,
Boqun

> >
> > The last sentence is supposed to say: when you have a &mut bitmap, you
> > can reborrow it as &bitmap, and then happily call this atomic op.
> > Even though it is unnecessary.
> 
> But using an atomic op when you have a &mut reference is not a safety
> issue, right? You wrote a comment about behavior with exclusive
> references in the "# Safety" comment block. If that's not supposed to
> be a safety problem, this should probably not be in the "# Safety"
> section?

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ