Received: from list by lists.gnu.org with archive (Exim 4.71) id 1hLZbq-0008K3-Vy for mharc-grub-devel@gnu.org; Tue, 30 Apr 2019 16:44:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55126) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLZbo-0008I7-Sc for grub-devel@gnu.org; Tue, 30 Apr 2019 16:44:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hLZbl-00073g-2D for grub-devel@gnu.org; Tue, 30 Apr 2019 16:44:12 -0400 Received: from zulu616.server4you.de ([188.138.100.120]:52370) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLZbh-0006ya-9j for grub-devel@gnu.org; Tue, 30 Apr 2019 16:44:06 -0400 Received: from server.alex.local (x4d0924b7.dyn.telefonica.de [77.9.36.183]) by csgraf.de (Postfix) with ESMTPSA id C610A3900429; Tue, 30 Apr 2019 22:43:58 +0200 (CEST) From: Alexander Graf To: grub-devel@gnu.org Cc: Daniel Kiper , Leif Lindholm , Heinrich Schuchardt , Julien ROBIN , Steve McIntyre , Colin Watson Subject: [PATCH v2 1/2] arm: Move trampolines into code section Date: Tue, 30 Apr 2019 22:43:56 +0200 Message-Id: <20190430204357.25059-2-agraf@csgraf.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190430204357.25059-1-agraf@csgraf.de> References: <20190430204357.25059-1-agraf@csgraf.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 188.138.100.120 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Apr 2019 20:44:14 -0000 When creating T32->A32 transition jumps, the relocation code in grub will generate trampolines. These trampolines live in the .data section of our PE binary which means they are not marked as executable. This misbehavior was unmasked by commit a51f953f4ee87 ("mkimage: Align efi sections on 4k boundary") which made the X/NX boundary more obvious because everything became page aligned. To put things into proper order, let's move the arm trampolines into the .text section instead. That way everyone knows they are executable. Fixes: a51f953f4ee87 ("mkimage: Align efi sections on 4k boundary") Reported-by: Julien ROBIN Reported-by: Leif Lindholm Signed-off-by: Alexander Graf Tested-by: Julien ROBIN --- v1 -> v2: - Take trampoline code size into account when calculating offsets --- util/grub-mkimagexx.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c index a79034e7b..470fbf4dd 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c @@ -2197,25 +2197,10 @@ SUFFIX (locate_sections) (Elf_Ehdr *e, const char *kernel_path, } } - layout->kernel_size = ALIGN_UP (layout->kernel_size + image_target->vaddr_offset, - image_target->section_align) - - image_target->vaddr_offset; - layout->exec_size = layout->kernel_size; - - /* .data */ - for (i = 0, s = smd->sections; - i < smd->num_sections; - i++, s = (Elf_Shdr *) ((char *) s + smd->section_entsize)) - if (SUFFIX (is_data_section) (s, image_target)) - layout->kernel_size = SUFFIX (put_section) (s, i, layout->kernel_size, smd, - image_target); - #ifdef MKIMAGE_ELF32 if (image_target->elf_target == EM_ARM) { grub_size_t tramp; - layout->kernel_size = ALIGN_UP (layout->kernel_size + image_target->vaddr_offset, - image_target->section_align) - image_target->vaddr_offset; layout->kernel_size = ALIGN_UP (layout->kernel_size, 16); @@ -2227,6 +2212,19 @@ SUFFIX (locate_sections) (Elf_Ehdr *e, const char *kernel_path, } #endif + layout->kernel_size = ALIGN_UP (layout->kernel_size + image_target->vaddr_offset, + image_target->section_align) + - image_target->vaddr_offset; + layout->exec_size = layout->kernel_size; + + /* .data */ + for (i = 0, s = smd->sections; + i < smd->num_sections; + i++, s = (Elf_Shdr *) ((char *) s + smd->section_entsize)) + if (SUFFIX (is_data_section) (s, image_target)) + layout->kernel_size = SUFFIX (put_section) (s, i, layout->kernel_size, smd, + image_target); + layout->bss_start = layout->kernel_size; layout->end = layout->kernel_size; -- 2.16.4