mirror_one_mok_variable(): round allocation up to a full page

The code currently computes the size of the MoK variable in ram and
rounds up to a full page, but then actually allocates the exact size,
rather than the rounded up version.  This should be completely safe, but
the intent was to round up to at least the page size boundary, and to
always guarantee rounding up /some/, to ensure extra 0-bytes at the end
of the buffer.

Signed-off-by: Peter Jones <pjones@redhat.com>
This commit is contained in:
Peter Jones 2020-08-04 12:42:43 -04:00
parent 65be350308
commit 63f7943dbe

9
mok.c
View File

@ -616,9 +616,12 @@ mirror_one_mok_variable(struct mok_state_variable *v,
* make sure we've got some zeroes at the end, just * make sure we've got some zeroes at the end, just
* in case. * in case.
*/ */
UINTN allocsz = FullDataSize + sizeof(EFI_SIGNATURE_LIST); UINTN new, allocsz;
allocsz = ALIGN_VALUE(allocsz, 4096);
FullData = AllocateZeroPool(FullDataSize); allocsz = FullDataSize + sizeof(EFI_SIGNATURE_LIST);
new = ALIGN_VALUE(allocsz, 4096);
allocsz = new == allocsz ? new + 4096 : new;
FullData = AllocateZeroPool(allocsz);
if (!FullData) { if (!FullData) {
perror(L"Failed to allocate %lu bytes for %s\n", perror(L"Failed to allocate %lu bytes for %s\n",
FullDataSize, v->name); FullDataSize, v->name);