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: <20240104065744.GA6055@wunner.de>
Date: Thu, 4 Jan 2024 07:57:44 +0100
From: Lukas Wunner <lukas@...ner.de>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Dan Williams <dan.j.williams@...el.com>, linux-coco@...ts.linux.dev,
	Andrew Morton <akpm@...ux-foundation.org>, x86@...nel.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 4/5] mm/slab: Add __free() support for kvfree

On Mon, Aug 14, 2023 at 06:17:31PM +0200, Peter Zijlstra wrote:
> On Mon, Aug 14, 2023 at 05:31:27PM +0200, Greg Kroah-Hartman wrote:
> > On Mon, Aug 14, 2023 at 12:43:32AM -0700, Dan Williams wrote:
> > > Allow for the declaration of variables that trigger kvfree() when they
> > > go out of scope.
> > > 
> > > Cc: Andrew Morton <akpm@...ux-foundation.org>
> > > Cc: Peter Zijlstra <peterz@...radead.org>
> > > Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
> > > Signed-off-by: Dan Williams <dan.j.williams@...el.com>
> > > ---
> > >  include/linux/slab.h |    2 ++
> > >  1 file changed, 2 insertions(+)
> > > 
> > > diff --git a/include/linux/slab.h b/include/linux/slab.h
> > > index 848c7c82ad5a..241025367943 100644
> > > --- a/include/linux/slab.h
> > > +++ b/include/linux/slab.h
> > > @@ -746,6 +746,8 @@ static inline __alloc_size(1, 2) void *kvcalloc(size_t n, size_t size, gfp_t fla
> > >  extern void *kvrealloc(const void *p, size_t oldsize, size_t newsize, gfp_t flags)
> > >  		      __realloc_size(3);
> > >  extern void kvfree(const void *addr);
> > > +DEFINE_FREE(kvfree, void *, if (_T) kvfree(_T))
> > 
> > No need to check _T before calling this, right (as was also pointed out
> > earlier).
> 
> Well, that does mean you get an unconditional call to kvfree() in the
> success case. Linus argued against this.
> 
> This way the compiler sees:
> 
> 	buf = NULL;
> 	if (buf)
> 		kvfree(buf);
> 
> and goes: 'let me clean that up for you'. And all is well.

Have you actually verified that assumption in the generated Assembler code?

The kernel is compiled with -fno-delete-null-pointer-checks since commit
a3ca86aea507 ("Add '-fno-delete-null-pointer-checks' to gcc CFLAGS").

So NULL pointer checks are *not* optimized away even if the compiler
knows that a pointer is NULL.

Background story:
https://lwn.net/Articles/342330/

Thanks,

Lukas

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ