Skip to content

Commit 6dd142d

Browse files
committed
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 <[email protected]> Cc: [email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 905889b commit 6dd142d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/coredump.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,18 @@ struct core_name {
6868

6969
static int expand_corename(struct core_name *cn, int size)
7070
{
71-
char *corename = krealloc(cn->corename, size, GFP_KERNEL);
71+
char *corename;
72+
73+
size = kmalloc_size_roundup(size);
74+
corename = krealloc(cn->corename, size, GFP_KERNEL);
7275

7376
if (!corename)
7477
return -ENOMEM;
7578

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

79-
cn->size = ksize(corename);
82+
cn->size = size;
8083
cn->corename = corename;
8184
return 0;
8285
}

0 commit comments

Comments
 (0)