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: <ZvK_Q0jsZ0cwnhQK@pollux>
Date: Tue, 24 Sep 2024 15:31:47 +0200
From: Danilo Krummrich <dakr@...nel.org>
To: Gary Guo <gary@...yguo.net>
Cc: Alice Ryhl <aliceryhl@...gle.com>, ojeda@...nel.org,
	alex.gaynor@...il.com, wedsonaf@...il.com, boqun.feng@...il.com,
	bjorn3_gh@...tonmail.com, benno.lossin@...ton.me,
	a.hindborg@...sung.com, akpm@...ux-foundation.org,
	daniel.almeida@...labora.com, faith.ekstrand@...labora.com,
	boris.brezillon@...labora.com, lina@...hilina.net,
	mcanal@...lia.com, zhiw@...dia.com, cjia@...dia.com,
	jhubbard@...dia.com, airlied@...hat.com, ajanulgu@...hat.com,
	lyude@...hat.com, linux-kernel@...r.kernel.org,
	rust-for-linux@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [RFC PATCH] rust: alloc: pass `old_layout` to `Allocator`

On Mon, Sep 23, 2024 at 05:13:15PM +0100, Gary Guo wrote:
> On Mon, 23 Sep 2024 15:56:28 +0200
> Alice Ryhl <aliceryhl@...gle.com> wrote:
> 
> > On Sat, Sep 21, 2024 at 5:33 PM Danilo Krummrich <dakr@...nel.org> wrote:
> > > @@ -84,11 +92,18 @@ unsafe fn call(
> > >          &self,
> > >          ptr: Option<NonNull<u8>>,
> > >          layout: Layout,
> > > +        old_layout: Layout,
> > >          flags: Flags,
> > >      ) -> Result<NonNull<[u8]>, AllocError> {
> > >          let size = aligned_size(layout);
> > >          let ptr = match ptr {
> > > -            Some(ptr) => ptr.as_ptr(),
> > > +            Some(ptr) => {
> > > +                if old_layout.size() == 0 {
> > > +                    ptr::null()
> > > +                } else {
> > > +                    ptr.as_ptr()
> > > +                }
> > > +            }  
> > 
> > This is making Allocator work with zero-sized types, which deviates
> > from std. We should not do that without a reason. What is the reason?
> > 
> > Alice
> 
> As Benno said, this makes the API closer to Rust `allocator_api`
> Allocator trait as opposed to deviation.
> 
> There's one benefit of doing this (discussed with Danilo off-list),
> which is it removes ZST special casing from caller. This RFC patch
> simplifies `Box` handling, and if we add this line to the safety doc
> 
> 	`ptr` does not need to be a pointer returned by this
> 	allocator if the layout is zero-sized.
> 
> then the `Vec` can also be simplified, removing all logics handling ZST
> specially, except for `Vec::new()` which it forges a well-aligned
> dangling pointer from nowhere.

Partially, we still need the additional `Layout` for `Allocator::free`, which
in `Vec::drop` and `IntoIter::drop` looks like this:

`let layout = Layout::array::<T>(self.cap).unwrap();`

I really dislike that this can potentially transform into `BUG()`, but that's
probably unrelated to this patch series.

> 
> Best,
> Gary
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ