mkimage/appendedsig: Fix grub-mkimage with an unaligned appended signature size

Related: #RHEL-24510
Signed-off-by: Nicolas Frayer <nfrayer@redhat.com>
This commit is contained in:
Nicolas Frayer 2025-12-03 11:18:30 +01:00
parent 17ffd9b3e0
commit d5ce85e0f9
3 changed files with 49 additions and 1 deletions

View File

@ -0,0 +1,43 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Date: Wed, 3 Dec 2025 13:19:57 +0530
Subject: [PATCH] appendedsig: Fix grub-mkimage with an unaligned appended
signature size
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 <sudhakar@linux.ibm.com>
---
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 d185246f1010..c99c7f99c787 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)

View File

@ -406,3 +406,4 @@ Patch0406: 0406-docs-grub-Document-appended-signature.patch
Patch0407: 0407-libtasn1-Fix-include-path-for-grub.patch
Patch0408: 0408-docs-fix-duplicated-entries.patch
Patch0409: 0409-powerpc-ieee1275-Add-support-for-signing-GRUB-with-a.patch
Patch0410: 0410-appendedsig-Fix-grub-mkimage-with-an-unaligned-appen.patch

View File

@ -17,7 +17,7 @@
Name: grub2
Epoch: 1
Version: 2.12
Release: 34%{?dist}
Release: 35%{?dist}
Summary: Bootloader with support for Linux, Multiboot and more
License: GPL-3.0-or-later
URL: http://www.gnu.org/software/grub/
@ -574,6 +574,10 @@ fi
%endif
%changelog
* Wed Dec 03 2025 Nicolas Frayer <nfrayer@redhat.com> 2.12-35
- mkimage/appendedsig: Fix grub-mkimage with an unaligned appended signature size
- Related: #RHEL-24510
* Fri Nov 21 2025 Nicolas Frayer <nfrayer@redhat.com> 2.12-34
- powerpc: Add appended signature feature
- Resolves: #RHEL-24510