ed1787d
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
ed1787d
From: Peter Jones <pjones@redhat.com>
ed1787d
Date: Tue, 11 Oct 2022 17:00:50 -0400
ed1787d
Subject: [PATCH] x86-efi: Fix an incorrect array size in kernel allocation
ed1787d
ed1787d
In 81a6ebf62bbe166ddc968463df2e8bd481bf697c ("efi: split allocation
ed1787d
policy for kernel vs initrd memories."), I introduced a split in the
ed1787d
kernel allocator to allow for different dynamic policies for the kernel
ed1787d
and the initrd allocations.
ed1787d
ed1787d
Unfortunately, that change increased the size of the policy data used to
ed1787d
make decisions, but did not change the size of the temporary storage we
ed1787d
use to back it up and restore.  This results in some of .data getting
ed1787d
clobbered at runtime, and hilarity ensues.
ed1787d
ed1787d
This patch makes the size of the backup storage be based on the size of
ed1787d
the initial policy data.
ed1787d
ed1787d
Signed-off-by: Peter Jones <pjones@redhat.com>
ed1787d
---
ed1787d
 grub-core/loader/i386/efi/linux.c | 2 +-
ed1787d
 1 file changed, 1 insertion(+), 1 deletion(-)
ed1787d
ed1787d
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
ed1787d
index ac5ef50bdb..9854b0defa 100644
ed1787d
--- a/grub-core/loader/i386/efi/linux.c
ed1787d
+++ b/grub-core/loader/i386/efi/linux.c
ed1787d
@@ -92,7 +92,7 @@ static struct allocation_choice max_addresses[] =
ed1787d
       { INITRD_MEM, GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS },
ed1787d
     { NO_MEM, 0, 0 }
ed1787d
   };
ed1787d
-static struct allocation_choice saved_addresses[4];
ed1787d
+static struct allocation_choice saved_addresses[sizeof(max_addresses) / sizeof(max_addresses[0])];
ed1787d
 
ed1787d
 #define save_addresses() grub_memcpy(saved_addresses, max_addresses, sizeof(max_addresses))
ed1787d
 #define restore_addresses() grub_memcpy(max_addresses, saved_addresses, sizeof(max_addresses))