We're supposed to zero everything in the kernel bootparams that we don't
explicitly initialise, other than the setup_header from 0x1f1 onwards
for a precisely defined length, which is copied from the bzImage.

We're *not* supposed to just pass the garbage that we happened to find
in the bzImage file surrounding the setup_header.

While we're at it, fix the checks for relocatable kernel. Boot proto
2.05 just means that the relocatable_kernel field is present in the
header. We should *also* check that it's actually set.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: David Woodhouse <david.woodho...@intel.com>

diff --git a/edk2/OvmfPkg/Library/LoadLinuxLib/Linux.c 
b/edk2/OvmfPkg/Library/LoadLinuxLib/Linux.c
index 96c985b..ebf14b6 100644
--- a/edk2/OvmfPkg/Library/LoadLinuxLib/Linux.c
+++ b/edk2/OvmfPkg/Library/LoadLinuxLib/Linux.c
@@ -47,6 +47,7 @@ LoadLinuxCheckKernelSetup (
   )
 {
   struct boot_params        *Bp;
+  UINTN                     SetupEnd;
 
   if (KernelSetup == NULL) {
     return EFI_INVALID_PARAMETER;
@@ -60,12 +61,21 @@ LoadLinuxCheckKernelSetup (
 
   if ((Bp->hdr.signature != 0xAA55) || // Check boot sector signature
       (Bp->hdr.header != SETUP_HDR) ||
-      (Bp->hdr.version < 0x205)        // We only support relocatable kernels
+      (Bp->hdr.version < 0x205) || // We only support relocatable kernels
+      (!Bp->hdr.relocatable_kernel)
      ) {
     return EFI_UNSUPPORTED;
-  } else {
-    return EFI_SUCCESS;
   }
+
+  SetupEnd = 0x202 + (Bp->hdr.jump & 0xff);
+  if (SetupEnd > KernelSetupSize) {
+    return EFI_UNSUPPORTED;
+  }
+
+  // Clear all but the setup_header
+  SetMem (KernelSetup, 0x1f1, 0);
+  SetMem (((UINT8 *)KernelSetup) + SetupEnd, KernelSetupSize - SetupEnd, 0);
+  return EFI_SUCCESS;
 }
 
 
@@ -606,7 +616,7 @@ LoadLinux (
 
   Bp = (struct boot_params *) KernelSetup;
 
-  if (Bp->hdr.version < 0x205) {
+  if (Bp->hdr.version < 0x205 || !Bp->hdr.relocatable_kernel) {
     //
     // We only support relocatable kernels
     //

-- 
dwmw2

Attachment: smime.p7s
Description: S/MIME cryptographic signature

------------------------------------------------------------------------------
Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122612 
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to