]> git.proxmox.com Git - efi-boot-shim.git/commitdiff
mirror_one_mok_variable(): round allocation up to a full page
authorPeter Jones <pjones@redhat.com>
Tue, 4 Aug 2020 16:42:43 +0000 (12:42 -0400)
committerPeter Jones <pjones@redhat.com>
Tue, 4 Aug 2020 16:49:30 +0000 (12:49 -0400)
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>
mok.c

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