efi/libstub/random: Align allocate size to EFI_ALLOC_ALIGN
authorArd Biesheuvel <ardb@kernel.org>
Mon, 13 Apr 2020 14:01:05 +0000 (16:01 +0200)
committerArd Biesheuvel <ardb@kernel.org>
Thu, 23 Apr 2020 18:15:06 +0000 (20:15 +0200)
commite1df73e2d18b3b7d66f2ec38d81d9566b3a7fb21
tree1d6d857d63c742eb4d590f9c5aed8f7e7a55189d
parent45d97a749e9fec6d5324b19561ce5fbfa937d60b
efi/libstub/random: Align allocate size to EFI_ALLOC_ALIGN

The EFI stub uses a per-architecture #define for the minimum base
and size alignment of page allocations, which is set to 4 KB for
all architecures except arm64, which uses 64 KB, to ensure that
allocations can always be (un)mapped efficiently, regardless of
the page size used by the kernel proper, which could be a kexec'ee

The API wrappers around page based allocations assume that this
alignment is always taken into account, and so efi_free() will
also round up its size argument to EFI_ALLOC_ALIGN.

Currently, efi_random_alloc() does not honour this alignment for
the allocated size, and so freeing such an allocation may result
in unrelated memory to be freed, potentially leading to issues
after boot. So let's round up size in efi_random_alloc() as well.

Fixes: 2ddbfc81eac84a29 ("efi: stub: add implementation of efi_random_alloc()")
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/libstub/randomalloc.c