Re: kfree(0) - ok?

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Pekka Enberg <penberg@...>
Cc: Satyam Sharma <satyam@...>, Andrew Morton <akpm@...>, Arjan van de Ven <arjan@...>, Tim Bird <tim.bird@...>, linux kernel <linux-kernel@...>
Date: Friday, August 17, 2007 - 7:22 pm

On Sat, 18 Aug 2007, Pekka Enberg wrote:




Slab allocators: Fail if ksize is called with a NULL parameter

A NULL pointer means that the object was not allocated. One cannot
determine the size of an object that has not been allocated. Currently
we return 0 but we really should BUG() on attempts to determine the size
of something nonexistent.

krealloc() interprets NULL to mean a zero sized object. Handle that
separately in krealloc().

Signed-off-by: Christoph Lameter <clameter@sgi.com>

Index: linux-2.6/mm/slab.c
===================================================================
--- linux-2.6.orig/mm/slab.c	2007-08-17 16:17:41.000000000 -0700
+++ linux-2.6/mm/slab.c	2007-08-17 16:18:15.000000000 -0700
@@ -4436,7 +4436,8 @@ const struct seq_operations slabstats_op
  */
 size_t ksize(const void *objp)
 {
-	if (unlikely(ZERO_OR_NULL_PTR(objp)))
+	BUG_ON(!objp);
+	if (unlikely(objp == ZERO_SIZE_PTR))
 		return 0;
 
 	return obj_size(virt_to_cache(objp));
Index: linux-2.6/mm/slob.c
===================================================================
--- linux-2.6.orig/mm/slob.c	2007-08-17 16:18:19.000000000 -0700
+++ linux-2.6/mm/slob.c	2007-08-17 16:18:40.000000000 -0700
@@ -484,7 +484,8 @@ size_t ksize(const void *block)
 {
 	struct slob_page *sp;
 
-	if (ZERO_OR_NULL_PTR(block))
+	BUG_ON(!block);
+	if (block == ZERO_SIZE_PTR)
 		return 0;
 
 	sp = (struct slob_page *)virt_to_page(block);
Index: linux-2.6/mm/slub.c
===================================================================
--- linux-2.6.orig/mm/slub.c	2007-08-17 16:16:36.000000000 -0700
+++ linux-2.6/mm/slub.c	2007-08-17 16:17:36.000000000 -0700
@@ -2426,7 +2426,8 @@ size_t ksize(const void *object)
 	struct page *page;
 	struct kmem_cache *s;
 
-	if (ZERO_OR_NULL_PTR(object))
+	BUG_ON(!object);
+	if (object == ZERO_SIZE_PTR)
 		return 0;
 
 	page = get_object_page(object);
Index: linux-2.6/mm/util.c
===================================================================
--- linux-2.6.orig/mm/util.c	2007-08-17 16:16:29.000000000 -0700
+++ linux-2.6/mm/util.c	2007-08-17 16:16:32.000000000 -0700
@@ -81,14 +81,16 @@ EXPORT_SYMBOL(kmemdup);
 void *krealloc(const void *p, size_t new_size, gfp_t flags)
 {
 	void *ret;
-	size_t ks;
+	size_t ks = 0;
 
 	if (unlikely(!new_size)) {
 		kfree(p);
 		return ZERO_SIZE_PTR;
 	}
 
-	ks = ksize(p);
+	if (p)
+		ks = ksize(p);
+
 	if (ks >= new_size)
 		return (void *)p;
 
 
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
kfree(0) - ok?, Tim Bird, (Tue Aug 14, 6:59 pm)
Re: kfree(0) - ok?, Satyam Sharma, (Tue Aug 14, 7:13 pm)
Re: kfree(0) - ok?, Arjan van de Ven, (Tue Aug 14, 6:55 pm)
Re: kfree(0) - ok?, Satyam Sharma, (Tue Aug 14, 7:42 pm)
Re: kfree(0) - ok?, Andrew Morton, (Fri Aug 17, 2:22 pm)
Re: kfree(0) - ok?, Satyam Sharma, (Fri Aug 17, 5:13 pm)
Re: kfree(0) - ok?, Christoph Lameter, (Fri Aug 17, 5:14 pm)
Re: kfree(0) - ok?, Satyam Sharma, (Fri Aug 17, 5:46 pm)
Re: kfree(0) - ok?, Pekka Enberg, (Fri Aug 17, 5:42 pm)
Re: kfree(0) - ok?, Thomas Gleixner, (Fri Aug 17, 7:40 pm)
Re: kfree(0) - ok?, Jan Engelhardt, (Sat Aug 18, 4:21 am)
Re: kfree(0) - ok?, Pekka Enberg, (Sat Aug 18, 4:10 am)
Re: kfree(0) - ok?, Christoph Lameter, (Fri Aug 17, 9:03 pm)
Re: kfree(0) - ok?, Satyam Sharma, (Fri Aug 17, 8:02 pm)
Re: kfree(0) - ok?, Christoph Lameter, (Fri Aug 17, 7:22 pm)
Re: kfree(0) - ok?, Christoph Lameter, (Fri Aug 17, 4:43 pm)
Re: kfree(0) - ok?, Satyam Sharma, (Fri Aug 17, 5:17 pm)
Re: kfree(0) - ok?, Satyam Sharma, (Fri Aug 17, 5:32 pm)
Re: kfree(0) - ok?, Jan Engelhardt, (Fri Aug 17, 2:37 pm)
Re: kfree(0) - ok?, Arjan van de Ven, (Fri Aug 17, 2:31 pm)
Re: kfree(0) - ok?, Satyam Sharma, (Fri Aug 17, 2:50 pm)
Re: kfree(0) - ok?, Christoph Lameter, (Tue Aug 14, 8:19 pm)
Re: kfree(0) - ok?, Jason Uhlenkott, (Tue Aug 14, 7:21 pm)
Re: kfree(0) - ok?, Jan Engelhardt, (Wed Aug 15, 3:28 am)
Re: kfree(0) - ok?, Giacomo A. Catenazzi, (Wed Aug 15, 5:32 am)
Re: kfree(0) - ok?, Andreas Schwab, (Wed Aug 15, 5:18 am)
Re: kfree(0) - ok?, Jason Uhlenkott, (Wed Aug 15, 4:52 am)
Re: kfree(0) - ok?, Rene Herman, (Wed Aug 15, 4:37 am)
Re: kfree(0) - ok?, Jan Engelhardt, (Wed Aug 15, 5:20 am)
Re: kfree(0) - ok?, Rene Herman, (Wed Aug 15, 5:58 am)
Re: kfree(0) - ok?, Jan Engelhardt, (Wed Aug 15, 6:20 am)
Re: kfree(0) - ok?, H. Peter Anvin, (Wed Aug 15, 12:01 pm)
Re: kfree(0) - ok?, Kyle Moffett, (Wed Aug 15, 9:58 am)
Re: kfree(0) - ok?, Jan Engelhardt, (Wed Aug 15, 10:06 am)
Re: kfree(0) - ok?, Kyle Moffett, (Wed Aug 15, 10:34 am)
Re: kfree(0) - ok?, Rene Herman, (Wed Aug 15, 6:27 am)
Re: kfree(0) - ok?, Jason Uhlenkott, (Wed Aug 15, 5:43 am)