From f3fdbbfa92defb1f1d12c0038513b69b52baf33e Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Thu, 21 May 2020 14:36:00 +0100 Subject: [PATCH] Make sure aligned_alloc size is a multiply of alignment Fix a ASan complaint. Signed-off-by: Yuxuan Shui --- include/linux/slab.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index d77b7683..67d52c9e 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -20,9 +20,11 @@ static inline void *kmalloc(size_t size, gfp_t flags) run_shrinkers(); + size_t alignment = min(rounddown_pow_of_two(size), + (size_t)PAGE_SIZE); + size = roundup(size, alignment); p = size - ? aligned_alloc(min(rounddown_pow_of_two(size), - (size_t)PAGE_SIZE), size) + ? aligned_alloc(alignment, size) : malloc(0); if (p && (flags & __GFP_ZERO)) memset(p, 0, size);