]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
xnu: Supply random seed.
authorVladimir Serbinenko <phcoder@gmail.com>
Fri, 12 Feb 2016 11:40:10 +0000 (12:40 +0100)
committerVladimir Serbinenko <phcoder@gmail.com>
Fri, 12 Feb 2016 11:40:10 +0000 (12:40 +0100)
Now we're able to load kernels up to El Capitan.

grub-core/Makefile.core.def
grub-core/loader/i386/xnu.c

index 18e3208be724ead5722a09e09c1a820e6fb525ef..58438c48d5a75eeb55543a4fa7c942a73b7a7e58 100644 (file)
@@ -1685,8 +1685,17 @@ module = {
   x86 = loader/i386/xnu.c;
   x86 = loader/xnu.c;
 
-  enable = x86;
-}
+  /* Code is pretty generic but relies on RNG which
+     is available only on few platforms. It's not a
+     big deal as xnu needs ACPI anyway and we have
+     RNG on all platforms with ACPI.
+   */
+  enable = i386_multiboot;
+  enable = i386_coreboot;
+  enable = i386_pc;
+  enable = i386_efi;
+  enable = x86_64_efi;
+};
 
 module = {
   name = random;
index 7b11c65f0ec6f8285d45f4abd7a266c024cadaf1..59ef73a73850bdca6b78efd3807042b7260f0557 100644 (file)
@@ -35,6 +35,7 @@
 #include <grub/i18n.h>
 #include <grub/bitmap_scale.h>
 #include <grub/cpu/io.h>
+#include <grub/random.h>
 
 #define min(a,b) (((a) < (b)) ? (a) : (b))
 #define max(a,b) (((a) > (b)) ? (a) : (b))
@@ -577,11 +578,31 @@ static grub_err_t
 grub_cpu_xnu_fill_devicetree (grub_uint64_t *fsbfreq_out)
 {
   struct grub_xnu_devtree_key *efikey;
+  struct grub_xnu_devtree_key *chosenkey;
   struct grub_xnu_devtree_key *cfgtablekey;
   struct grub_xnu_devtree_key *curval;
   struct grub_xnu_devtree_key *runtimesrvkey;
   struct grub_xnu_devtree_key *platformkey;
   unsigned i, j;
+  grub_err_t err;
+
+  chosenkey = grub_xnu_create_key (&grub_xnu_devtree_root, "chosen");
+  if (! chosenkey)
+    return grub_errno;
+
+  /* Random seed. */
+  curval = grub_xnu_create_value (&(chosenkey->first_child), "random-seed");
+  if (! curval)
+    return grub_errno;
+  curval->datasize = 64;
+  curval->data = grub_malloc (curval->datasize);
+  if (! curval->data)
+    return grub_errno;
+  /* Our random is not peer-reviewed but xnu uses this seed only for
+     ASLR in kernel.  */
+  err = grub_crypto_get_random (curval->data, curval->datasize);
+  if (err)
+    return err;
 
   /* The value "model". */
   /* FIXME: may this value be sometimes different? */