Received: from list by lists.gnu.org with archive (Exim 4.71) id 1go74k-000372-EE for mharc-grub-devel@gnu.org; Mon, 28 Jan 2019 08:35:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58618) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1go74i-00035k-KL for grub-devel@gnu.org; Mon, 28 Jan 2019 08:35:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1go74h-0000zW-Mi for grub-devel@gnu.org; Mon, 28 Jan 2019 08:35:44 -0500 Received: from mx2.suse.de ([195.135.220.15]:39744 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1go74h-0000MB-Br for grub-devel@gnu.org; Mon, 28 Jan 2019 08:35:43 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9BD62ABB1; Mon, 28 Jan 2019 13:35:29 +0000 (UTC) From: Alexander Graf To: grub-devel@gnu.org Cc: Daniel Kiper , Leif Lindholm , Peter Jones , Jon Masters Subject: [PATCH v6 2/3] mkimage: Align efi sections on 4k boundary Date: Mon, 28 Jan 2019 14:35:28 +0100 Message-Id: <20190128133529.82445-3-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20190128133529.82445-1-agraf@suse.de> References: <20190128133529.82445-1-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 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: Mon, 28 Jan 2019 13:35:45 -0000 There is UEFI firmware popping up in the wild now that implements stricter permission checks using NX and write protect page table entry bits. This means that firmware now may fail to load binaries if its individual sections are not page aligned, as otherwise it can not ensure permission boundaries. So let's bump all efi section alignments up to 4k (EFI page size). That way we will stay compatible going forward. Unfortunately our internals can't deal very well with a mismatch of alignment between the virtual and file offsets, so we have to also pad our target binary a bit. Signed-off-by: Alexander Graf --- v4 -> v5: - Use GRUB_EFI_PAGE_SIZE - Add include to have above const defined v5 -> v6: - Fix comment --- include/grub/efi/pe32.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h index 7d44732d2..207b0382e 100644 --- a/include/grub/efi/pe32.h +++ b/include/grub/efi/pe32.h @@ -20,6 +20,7 @@ #define GRUB_EFI_PE32_HEADER 1 #include +#include /* The MSDOS compatibility stub. This was copied from the output of objcopy, and it is not necessary to care about what this means. */ @@ -50,8 +51,14 @@ /* According to the spec, the minimal alignment is 512 bytes... But some examples (such as EFI drivers in the Intel Sample Implementation) use 32 bytes (0x20) instead, and it seems - to be working. For now, GRUB uses 512 bytes for safety. */ -#define GRUB_PE32_SECTION_ALIGNMENT 0x200 + to be working. + + However, there is firmware showing up in the field now with + page alignment constraints to guarantee that page protection + bits take effect. Because currently existing GRUB code can not + properly distinguish between in-memory and in-file layout, let's + bump all alignment to GRUB_EFI_PAGE_SIZE. */ +#define GRUB_PE32_SECTION_ALIGNMENT GRUB_EFI_PAGE_SIZE #define GRUB_PE32_FILE_ALIGNMENT GRUB_PE32_SECTION_ALIGNMENT struct grub_pe32_coff_header -- 2.12.3