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: <alpine.LFD.0.999.0708180011570.3666@enigma.security.iitk.ac.in>
Date:	Sat, 18 Aug 2007 02:43:19 +0530 (IST)
From:	Satyam Sharma <satyam@...radead.org>
To:	Andrew Morton <akpm@...ux-foundation.org>
cc:	Arjan van de Ven <arjan@...radead.org>,
	Tim Bird <tim.bird@...sony.com>,
	linux kernel <linux-kernel@...r.kernel.org>,
	Christoph Lameter <clameter@....com>
Subject: Re: kfree(0) - ok?



On Fri, 17 Aug 2007, Andrew Morton wrote:

> On Wed, 15 Aug 2007 05:12:41 +0530 (IST)
> Satyam Sharma <satyam@...radead.org> wrote:
> 
> > [PATCH] {slub, slob}: use unlikely() for kfree(ZERO_OR_NULL_PTR) check
> > 
> > Considering kfree(NULL) would normally occur only in error paths and
> > kfree(ZERO_SIZE_PTR) is uncommon as well, so let's use unlikely() for
> > the condition check in SLUB's and SLOB's kfree() to optimize for the
> > common case. SLAB has this already.
> 
> I went through my current versions of slab/slub/slub and came up with this:
> 
> diff -puN mm/slob.c~slub-slob-use-unlikely-for-kfreezero_or_null_ptr-check mm/slob.c
> [...]
> @@ -484,7 +484,7 @@ size_t ksize(const void *block)
>  {
>  	struct slob_page *sp;
>  
> -	if (ZERO_OR_NULL_PTR(block))
> +	if (unlikely(ZERO_OR_NULL_PTR(block)))
>  		return 0;
>  
>  	sp = (struct slob_page *)virt_to_page(block);
> diff -puN mm/slub.c~slub-slob-use-unlikely-for-kfreezero_or_null_ptr-check mm/slub.c
> [...]
> @@ -2434,7 +2434,7 @@ size_t ksize(const void *object)
>  	struct page *page;
>  	struct kmem_cache *s;
>  
> -	if (ZERO_OR_NULL_PTR(object))
> +	if (unlikely(ZERO_OR_NULL_PTR(object)))
>  		return 0;
>  
>  	page = get_object_page(object);

Hmm, I didn't know ksize(NULL) was also allowed to succeed (and
return 0).

<checking around>

Oh yes, of course. We want krealloc(NULL) cases to behave
consistently as expected, and letting ksize(NULL) return 0 means
the code for krealloc() can lose an extra "if (!p)" check that
would otherwise have been required. Cool.


> Which is getting pretty idiotic:
> 
> akpm:/usr/src/25> grep ZERO_OR_NULL_PTR */*.c
> mm/slab.c:              BUG_ON(ZERO_OR_NULL_PTR(cachep->slabp_cache));
> mm/slab.c:      if (unlikely(ZERO_OR_NULL_PTR(cachep)))
> mm/slab.c:      if (unlikely(ZERO_OR_NULL_PTR(cachep)))
> mm/slab.c:      if (unlikely(ZERO_OR_NULL_PTR(objp)))
> mm/slab.c:      if (unlikely(ZERO_OR_NULL_PTR(objp)))
> mm/slob.c:      if (unlikely(ZERO_OR_NULL_PTR(block)))
> mm/slob.c:      if (unlikely(ZERO_OR_NULL_PTR(block)))
> mm/slob.c:      if (unlikely(ZERO_OR_NULL_PTR(block)))
> mm/slub.c:      if (unlikely(ZERO_OR_NULL_PTR(s)))
> mm/slub.c:      if (unlikely(ZERO_OR_NULL_PTR(s)))
> mm/slub.c:      if (unlikely(ZERO_OR_NULL_PTR(object)))
> mm/slub.c:      if (unlikely(ZERO_OR_NULL_PTR(x)))
> mm/slub.c:      if (unlikely(ZERO_OR_NULL_PTR(s)))
> mm/slub.c:      if (unlikely(ZERO_OR_NULL_PTR(s)))
> 
> are we seeing a pattern here?  We could stick the unlikely inside
> ZERO_OR_NULL_PTR() itself.  That's a little bit sleazy though - there might
> be future callsites at which it is likely, who knows?

Well, all the above callsites genuinely appear to benefit from unlikely.
And it's unlikely (English word, this here :-) ZERO_OR_NULL_PTR would grow
callsites outside of mm/ especially considering the implementation
(or even the knowledge) of the ZERO_SIZE_PTR concept is something we'd
ideally want to abstract away from other generic callsites, I imagine.


Satyam
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ