[PATCH] bg_gen_unified_kernel: Validate kernel image

6 views
Skip to first unread message

Jan Kiszka

unread,
Dec 14, 2022, 4:55:50 AM12/14/22
to efibootguard-dev, Michael Adler
From: Jan Kiszka <jan.k...@siemens.com>

Extract the PE headers from the provided kernel image to make sure that
it is actually coming with an EFI stub. Avoids surprises and crashes
later on when trying to run the unified kernel image.

Reported-by: Michael Adler <michae...@siemens.com>
Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---

Gives "Invalid kernel, bad DOS header magic" if selecting a "normal"
kernel as input, at least for me here.

tools/bg_gen_unified_kernel | 3 +++
1 file changed, 3 insertions(+)

diff --git a/tools/bg_gen_unified_kernel b/tools/bg_gen_unified_kernel
index afda8ce..1d426e1 100755
--- a/tools/bg_gen_unified_kernel
+++ b/tools/bg_gen_unified_kernel
@@ -258,6 +258,9 @@ def main():

kernel = args.kernel.read()

+ # Just to perform an integrity test for the kernel image
+ PEHeaders('kernel', kernel)
+
current_offs = cmdline_section.data_offs + cmdline_section.data_size
sect_size = align(len(kernel), file_align)
kernel_section = Section(b'.kernel', sect_size, 0x2000000,
--
2.35.3
Reply all
Reply to author
Forward
0 new messages