lkml.org 
[lkml]   [2007]   [Jun]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: SLUB: Return ZERO_SIZE_PTR for kmalloc(0)
On Fri, 1 Jun 2007, Linus Torvalds wrote:

> So when I suggested the uglier
>
> if ((unsigned long)x <= 16)
> return;
>
> I really did mean to use that ugly cast.. Yours is prettier, but sadly,
> yours is simply not safe: a signed comparison might end up making _all_
> kernel pointers trigger that test.

Maybe we can have a compromise? Lets at least keep the ZERO_SIZE_PTR
reference in there.


SLUB: Make sure that the comparision with ZERO_SIZE_PTR is unsigned

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


---
mm/slub.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

Index: slub/mm/slub.c
===================================================================
--- slub.orig/mm/slub.c 2007-06-01 20:00:56.000000000 -0700
+++ slub/mm/slub.c 2007-06-01 20:04:26.000000000 -0700
@@ -2338,7 +2338,13 @@ void kfree(const void *x)
struct kmem_cache *s;
struct page *page;

- if (x <= ZERO_SIZE_PTR)
+ /*
+ * This has to be an unsigned comparison. According to Linus
+ * some gcc version tread a pointer as a signed entity. Then
+ * this comparison would be true for all "negative" pointers
+ * (which would cover the whole upper half of the address space).
+ */
+ if ((unsigned long)x <= (unsigned long)ZERO_SIZE_PTR)
return;

page = virt_to_head_page(x);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2007-06-02 05:09    [W:0.124 / U:0.244 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site