mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 11:11:45 -04:00
slab: Generify kernel pointer validation
As suggested by Linus, introduce a kern_ptr_validate() helper that does some sanity checks to make sure a pointer is a valid kernel pointer. This is a preparational step for fixing SLUB kmem_ptr_validate(). Cc: Andrew Morton <[email protected]> Cc: Christoph Lameter <[email protected]> Cc: David Rientjes <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Matt Mackall <[email protected]> Cc: Nick Piggin <[email protected]> Signed-off-by: Pekka Enberg <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
4dc86ae1f9
commit
fc1c183353
3 changed files with 23 additions and 12 deletions
21
mm/util.c
21
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue