The grub-mkimage does not add zero padding when creating core.elf with an
appended signature size that is not aligned to a multiple of 4 bytes.
Firmware is unable to read the magic string "~Module signature appended~"
from core.elf.

To fix this, round an appended signature size + appended signature ELF note
size up to the nearest multiple of a 4-byte alignment and truncate it to the
appended signature size.

Example:
grub-mkimage -O powerpc-ieee1275 -o core.elf -d grub-core -p /grub2 -x \
  kernel.der --appended-signature-size 490 ...

Signed-off-by: Sudhakar Kuppusamy <[email protected]>
---
 util/grub-mkimagexx.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c
index 7fe2e35e6..07a80a36d 100644
--- a/util/grub-mkimagexx.c
+++ b/util/grub-mkimagexx.c
@@ -248,7 +248,13 @@ SUFFIX (grub_mkimage_generate_elf) (const struct 
grub_install_image_target_desc
   if (appsig_size)
     {
       phnum++;
-      footer_size += ALIGN_UP (sizeof (struct grub_appended_signature_note), 
4);
+      /*
+       * Rounds a appended signature size + appended signature note size up to
+       * the nearest multiple of a 4-byte alignment.
+       */
+      footer_size += ALIGN_UP (sizeof (struct grub_appended_signature_note) + 
appsig_size, 4);
+      /* Truncating to appended signature size. */
+      footer_size -= appsig_size;
     }
 
   if (image_target->id != IMAGE_LOONGSON_ELF)
-- 
2.50.1 (Apple Git-155)


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to