fix slub krealloc()
Subsystems (3)
RFC 1/1 fix slub krealloc()
Commit ef2ad80c7d255ed0449eda947c2d700635b7e0f5 breaks krealloc(NULL, ...) badly, it BUG_ON()s.
This patch fixes it but the fix should probably be in mm/util.c because the documentation says that krealloc(NULL, x, gfp) is equivalent to kmalloc(x, gfp) and that's not true any more even after this patch when you do krealloc(NULL, 0, gfp)
johannes
--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/slub.c +1 -1
@@ -2394,7 +2394,7 @@ size_t ksize(const void *object)struct page *page;struct kmem_cache *s; -if (object ==ZERO_SIZE_PTR ) +if (object ==ZERO_SIZE_PTR || !object)return 0 ; page =get_object_page (object);
Quoted 7 lines · On Wed, 18 Jul 2007 17:42:11 +0200 Johannes Berg <[email protected]>…
Commit
ef2ad80c7d255ed0449eda947c2d700635b7e0f5breakskrealloc(NULL, ...)badly, it BUG_ON()s.This patch fixes it but the fix should probably be in
mm/util.cbecause the documentation says thatkrealloc(NULL, x, gfp)is equivalent tokmalloc(x, gfp)and that's not true any more even after this patch when you dokrealloc(NULL, 0, gfp)
Right. We need to fix util.c. ksize should not be called with a NULL parameter.
mm/util.c +5 -1
@@ -88,7 +88,11 @@ void *krealloc(const void *p, size_t newreturn ZERO_SIZE_PTR ; } - ks =ksize (p); +if (p) + ks =ksize (p); +else + ks =0 ; +if (ks >= new_size)return (void *)p;
Andrew Morton
maintainerQuoted 20 lines · On Mon, 23 Jul 2007 13:32:06 -0700 Christoph Lameter <[email protected]> wrote:
Quoted 7 lines · On Wed, 18 Jul 2007 17:42:11 +0200 Johannes Berg <[email protected]>…
Commit
ef2ad80c7d255ed0449eda947c2d700635b7e0f5breakskrealloc(NULL, ...)badly, it BUG_ON()s.This patch fixes it but the fix should probably be in
mm/util.cbecause the documentation says thatkrealloc(NULL, x, gfp)is equivalent tokmalloc(x, gfp)and that's not true any more even after this patch when you dokrealloc(NULL, 0, gfp)Right. We need to fix
util.c. ksize should not be called with a NULL parameter.
Index:linux-2.6/mm/util.c
===================================================================mm/util.c +0
-0@@ -88,7 +88,11 @@ void *krealloc(const void *p, size_t newreturn ZERO_SIZE_PTR ; }
mm/util.c void *krealloc(const void *p, size_t new · line 98
Quoted 10 lines
mm/util.c +5
-1- ks =ksize (p); +if (p) + ks =ksize (p); +else + ks =0 ; +if (ks >= new_size)return (void *)p;
I think we already fixed this?
commit 1d4ec7b1d6f130818f9b62dea3411d9ee2ff6ff6
Author: Roland Dreier <[email protected]> Date: Fri Jul 20 12:13:20 2007 -0700
Fix ZERO_OR_NULL_PTR(ZERO_SIZE_PTR)
The comparison with ZERO_SIZE_PTR in ZERO_OR_NULL_PTR() needs to be <= (not just <) so that ZERO_OR_NULL_PTR(ZERO_SIZE_PTR) is 1.
include/linux/slab.h +1 -1
@@ -40,7 +40,7 @@ #define SLAB_TRACE 0x00200000UL /* Trac*/ #define ZERO_SIZE_PTR ((void *)16) -#define ZERO_OR_NULL_PTR (x) ((unsigned long)(x) < \ +#define ZERO_OR_NULL_PTR (x) ((unsigned long)(x) <= \ (unsigned long)ZERO_SIZE_PTR)/*
Quoted 22 lines · On Mon, 23 Jul 2007 13:47:13 -0700 Andrew Morton <[email protected]>…
Quoted 9 lines
Right. We need to fix
util.c. ksize should not be called with a NULL parameter.
Index:linux-2.6/mm/util.c
===================================================================
---linux-2.6.orig/mm/util.c2007-07-23 13:29:42.000000000
-0700 +++linux-2.6/mm/util.c2007-07-23 13:31:28.000000000
-0700 @@ -88,7 +88,11 @@ void *krealloc(const void *p,size_tnew(quoted diff) +0
-0return ZERO_SIZE_PTR;Review
Quoted 10 lines
(quoted diff) +5
-1} - ks = ksize(p); + if (p) + ks = ksize(p); + else + ks = 0; + if (ks >= new_size) return (void *)p;I think we already fixed this?
Quoted 5 lines
commit
1d4ec7b1d6f130818f9b62dea3411d9ee2ff6ff6Author: Roland Dreier <[email protected]> Date: Fri Jul 20 12:13:20 2007 -0700Fix
ZERO_OR_NULL_PTR(ZERO_SIZE_PTR)
There is no use of ZERO_OR_NULL ptr in krealloc. Linus added a check to ksize() instead so that ksize(NULL) returns 0 instead of failing.
Quoted 7 lines
Quoted 4 lines
I think we already fixed this?
Fix
ZERO_OR_NULL_PTR(ZERO_SIZE_PTR)There is no use of
ZERO_OR_NULLptr in krealloc. Linus added a check toksize()instead so that ksize(NULL) returns 0 instead of failing.
However, this still doesn't fix the other corner case I pointed out:krealloc(NULL, 0, GFP_KERNEL) will give you a NULL pointer instead of a ZERO_SIZE_PTR afaict.
johannes
Quoted 7 lines · Johannes Berg
Quoted 3 lines
There is no use of
ZERO_OR_NULLptr in krealloc. Linus added a check toksize()instead so that ksize(NULL) returns 0 instead of failing.However, this still doesn't fix the other corner case I pointed out:
krealloc(NULL, 0, GFP_KERNEL)will give you a NULL pointer instead of aZERO_SIZE_PTRafaict.
It will give you a ZERO_SIZE_PTR
void *krealloc(const void *p, size_t new_size, gfp_t flags)
{
void *ret;
size_t ks;
if (unlikely(!new_size)) {
kfree(p);
return ZERO_SIZE_PTR;
}Quoted 11 lines · Christoph Lameter
It will give you a
ZERO_SIZE_PTRvoid *krealloc(const void *p,
size_tnew_size,gfp_tflags){ void *ret; size_t ks; if (unlikely(!new_size)) { kfree(p); return ZERO_SIZE_PTR; }
Oh, I thought looked and it returned NULL. Did it change or did I just look wrong? :)
johannes