f2b28b6
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f2b28b6
From: Alexander Graf <agraf@csgraf.de>
f2b28b6
Date: Tue, 30 Apr 2019 22:43:56 +0200
f2b28b6
Subject: [PATCH] arm: Move trampolines into code section
f2b28b6
f2b28b6
When creating T32->A32 transition jumps, the relocation code in grub
f2b28b6
will generate trampolines. These trampolines live in the .data section
f2b28b6
of our PE binary which means they are not marked as executable.
f2b28b6
f2b28b6
This misbehavior was unmasked by commit a51f953f4ee87 ("mkimage: Align
f2b28b6
efi sections on 4k boundary") which made the X/NX boundary more obvious
f2b28b6
because everything became page aligned.
f2b28b6
f2b28b6
To put things into proper order, let's move the arm trampolines into the
f2b28b6
.text section instead. That way everyone knows they are executable.
f2b28b6
f2b28b6
Fixes: a51f953f4ee87 ("mkimage: Align efi sections on 4k boundary")
f2b28b6
Reported-by: Julien ROBIN <julien.robin28@free.fr>
f2b28b6
Reported-by: Leif Lindholm <leif.lindholm@linaro.org>
f2b28b6
Signed-off-by: Alexander Graf <agraf@csgraf.de>
f2b28b6
Tested-by: Julien ROBIN <julien.robin28@free.fr>
f2b28b6
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
f2b28b6
Tested-by: Leif Lindholm <leif.lindholm@linaro.org>
f2b28b6
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
f2b28b6
---
f2b28b6
 util/grub-mkimagexx.c | 32 +++++++++++++++-----------------
f2b28b6
 1 file changed, 15 insertions(+), 17 deletions(-)
f2b28b6
f2b28b6
diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c
f2b28b6
index a483c674c49..86e6254a27e 100644
f2b28b6
--- a/util/grub-mkimagexx.c
f2b28b6
+++ b/util/grub-mkimagexx.c
f2b28b6
@@ -1900,6 +1900,21 @@ SUFFIX (locate_sections) (Elf_Ehdr *e, const char *kernel_path,
f2b28b6
 	  }
f2b28b6
       }
f2b28b6
 
f2b28b6
+#ifdef MKIMAGE_ELF32
f2b28b6
+  if (image_target->elf_target == EM_ARM)
f2b28b6
+    {
f2b28b6
+      grub_size_t tramp;
f2b28b6
+
f2b28b6
+      layout->kernel_size = ALIGN_UP (layout->kernel_size, 16);
f2b28b6
+
f2b28b6
+      tramp = arm_get_trampoline_size (e, smd->sections, smd->section_entsize,
f2b28b6
+				       smd->num_sections, image_target);
f2b28b6
+
f2b28b6
+      layout->tramp_off = layout->kernel_size;
f2b28b6
+      layout->kernel_size += ALIGN_UP (tramp, 16);
f2b28b6
+    }
f2b28b6
+#endif
f2b28b6
+
f2b28b6
   layout->kernel_size = ALIGN_UP (layout->kernel_size + image_target->vaddr_offset,
f2b28b6
 			      image_target->section_align)
f2b28b6
     - image_target->vaddr_offset;
f2b28b6
@@ -1913,23 +1928,6 @@ SUFFIX (locate_sections) (Elf_Ehdr *e, const char *kernel_path,
f2b28b6
       layout->kernel_size = SUFFIX (put_section) (s, i, layout->kernel_size, smd,
f2b28b6
 						  image_target);
f2b28b6
 
f2b28b6
-#ifdef MKIMAGE_ELF32
f2b28b6
-  if (image_target->elf_target == EM_ARM)
f2b28b6
-    {
f2b28b6
-      grub_size_t tramp;
f2b28b6
-      layout->kernel_size = ALIGN_UP (layout->kernel_size + image_target->vaddr_offset,
f2b28b6
-				      image_target->section_align) - image_target->vaddr_offset;
f2b28b6
-
f2b28b6
-      layout->kernel_size = ALIGN_UP (layout->kernel_size, 16);
f2b28b6
-
f2b28b6
-      tramp = arm_get_trampoline_size (e, smd->sections, smd->section_entsize,
f2b28b6
-				       smd->num_sections, image_target);
f2b28b6
-
f2b28b6
-      layout->tramp_off = layout->kernel_size;
f2b28b6
-      layout->kernel_size += ALIGN_UP (tramp, 16);
f2b28b6
-    }
f2b28b6
-#endif
f2b28b6
-
f2b28b6
   layout->bss_start = layout->kernel_size;
f2b28b6
   layout->end = layout->kernel_size;
f2b28b6