From: Kees Cook Date: Tue, 20 Sep 2022 21:13:05 +0000 (-0700) Subject: coredump: Proactively round up to kmalloc bucket size X-Git-Tag: v6.6.17~5838^2~26 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6dd142d9013ca82155d0c069434c60a0d5755ec0;p=platform%2Fkernel%2Flinux-rpi.git coredump: Proactively round up to kmalloc bucket size Instead of discovering the kmalloc bucket size _after_ allocation, round up proactively so the allocation is explicitly made for the full size, allowing the compiler to correctly reason about the resulting size of the buffer through the existing __alloc_size() hint. Cc: Alexander Viro Cc: linux-fsdevel@vger.kernel.org Signed-off-by: Kees Cook --- diff --git a/fs/coredump.c b/fs/coredump.c index 7bad778..97eaee32 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -68,7 +68,10 @@ struct core_name { static int expand_corename(struct core_name *cn, int size) { - char *corename = krealloc(cn->corename, size, GFP_KERNEL); + char *corename; + + size = kmalloc_size_roundup(size); + corename = krealloc(cn->corename, size, GFP_KERNEL); if (!corename) return -ENOMEM; @@ -76,7 +79,7 @@ static int expand_corename(struct core_name *cn, int size) if (size > core_name_size) /* racy but harmless */ core_name_size = size; - cn->size = ksize(corename); + cn->size = size; cn->corename = corename; return 0; }