From 47c7e5bb4bbc0ae3970e85ed55b2991f1447e9b0 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 7 Apr 2010 19:23:40 +0300 Subject: [PATCH] --- yaml --- r: 189670 b: refs/heads/master c: fc1c183353a113c71675fecd0485e5aa0fe68d72 h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/include/linux/slab.h | 1 + trunk/mm/slab.c | 13 +------------ trunk/mm/util.c | 21 +++++++++++++++++++++ 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/[refs] b/[refs] index 3e4949f54bd7..f62233fe51f1 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 4dc86ae1f925b2121d4e75058675895f83e54c71 +refs/heads/master: fc1c183353a113c71675fecd0485e5aa0fe68d72 diff --git a/trunk/include/linux/slab.h b/trunk/include/linux/slab.h index 488446289cab..49d1247cd6d9 100644 --- a/trunk/include/linux/slab.h +++ b/trunk/include/linux/slab.h @@ -106,6 +106,7 @@ int kmem_cache_shrink(struct kmem_cache *); void kmem_cache_free(struct kmem_cache *, void *); unsigned int kmem_cache_size(struct kmem_cache *); const char *kmem_cache_name(struct kmem_cache *); +int kern_ptr_validate(const void *ptr, unsigned long size); int kmem_ptr_validate(struct kmem_cache *cachep, const void *ptr); /* diff --git a/trunk/mm/slab.c b/trunk/mm/slab.c index a9f325b28bed..bac0f4fcc216 100644 --- a/trunk/mm/slab.c +++ b/trunk/mm/slab.c @@ -3602,21 +3602,10 @@ EXPORT_SYMBOL(kmem_cache_alloc_notrace); */ int kmem_ptr_validate(struct kmem_cache *cachep, const void *ptr) { - unsigned long addr = (unsigned long)ptr; - unsigned long min_addr = PAGE_OFFSET; - unsigned long align_mask = BYTES_PER_WORD - 1; unsigned long size = cachep->buffer_size; struct page *page; - if (unlikely(addr < min_addr)) - goto out; - if (unlikely(addr > (unsigned long)high_memory - size)) - goto out; - if (unlikely(addr & align_mask)) - goto out; - if (unlikely(!kern_addr_valid(addr))) - goto out; - if (unlikely(!kern_addr_valid(addr + size - 1))) + if (unlikely(!kern_ptr_validate(ptr, size))) goto out; page = virt_to_page(ptr); if (unlikely(!PageSlab(page))) diff --git a/trunk/mm/util.c b/trunk/mm/util.c index 834db7be240f..f5712e8964be 100644 --- a/trunk/mm/util.c +++ b/trunk/mm/util.c @@ -186,6 +186,27 @@ void kzfree(const void *p) } EXPORT_SYMBOL(kzfree); +int kern_ptr_validate(const void *ptr, unsigned long size) +{ + unsigned long addr = (unsigned long)ptr; + unsigned long min_addr = PAGE_OFFSET; + unsigned long align_mask = sizeof(void *) - 1; + + if (unlikely(addr < min_addr)) + goto out; + if (unlikely(addr > (unsigned long)high_memory - size)) + goto out; + if (unlikely(addr & align_mask)) + goto out; + if (unlikely(!kern_addr_valid(addr))) + goto out; + if (unlikely(!kern_addr_valid(addr + size - 1))) + goto out; + return 1; +out: + return 0; +} + /* * strndup_user - duplicate an existing string from user space * @s: The string to duplicate