mm/slab: refactor common ksize KASAN logic into slab_common.c
This refactors common code of ksize() between the various allocators into slab_common.c: __ksize() is the allocator-specific implementation without instrumentation, whereas ksize() includes the required KASAN logic. Link: http://lkml.kernel.org/r/20190626142014.141844-5-elver@google.com Signed-off-by: Marco Elver <elver@google.com> Acked-by: Christoph Lameter <cl@linux.com> Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Alexander Potapenko <glider@google.com> Cc: Andrey Konovalov <andreyknvl@google.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: David Rientjes <rientjes@google.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Kees Cook <keescook@chromium.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:

committed by
Linus Torvalds

parent
bb104ed785
commit
10d1f8cb39
@@ -1597,6 +1597,32 @@ void kzfree(const void *p)
|
||||
}
|
||||
EXPORT_SYMBOL(kzfree);
|
||||
|
||||
/**
|
||||
* ksize - get the actual amount of memory allocated for a given object
|
||||
* @objp: Pointer to the object
|
||||
*
|
||||
* kmalloc may internally round up allocations and return more memory
|
||||
* than requested. ksize() can be used to determine the actual amount of
|
||||
* memory allocated. The caller may use this additional memory, even though
|
||||
* a smaller amount of memory was initially specified with the kmalloc call.
|
||||
* The caller must guarantee that objp points to a valid object previously
|
||||
* allocated with either kmalloc() or kmem_cache_alloc(). The object
|
||||
* must not be freed during the duration of the call.
|
||||
*
|
||||
* Return: size of the actual memory used by @objp in bytes
|
||||
*/
|
||||
size_t ksize(const void *objp)
|
||||
{
|
||||
size_t size = __ksize(objp);
|
||||
/*
|
||||
* We assume that ksize callers could use whole allocated area,
|
||||
* so we need to unpoison this area.
|
||||
*/
|
||||
kasan_unpoison_shadow(objp, size);
|
||||
return size;
|
||||
}
|
||||
EXPORT_SYMBOL(ksize);
|
||||
|
||||
/* Tracepoints definitions. */
|
||||
EXPORT_TRACEPOINT_SYMBOL(kmalloc);
|
||||
EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc);
|
||||
|
Reference in New Issue
Block a user