Skip to content

Commit

Permalink
coredump: Proactively round up to kmalloc bucket size
Browse files Browse the repository at this point in the history
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 <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
  • Loading branch information
Kees Cook committed Nov 1, 2022
1 parent 905889b commit 6dd142d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fs/coredump.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,18 @@ 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;

if (size > core_name_size) /* racy but harmless */
core_name_size = size;

cn->size = ksize(corename);
cn->size = size;
cn->corename = corename;
return 0;
}
Expand Down

0 comments on commit 6dd142d

Please sign in to comment.