From patchwork Wed Feb 8 11:55:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 9562355 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1C0016047A for ; Wed, 8 Feb 2017 11:57:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E6EB284C9 for ; Wed, 8 Feb 2017 11:57:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02FE9284CF; Wed, 8 Feb 2017 11:57:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 17C40284C9 for ; Wed, 8 Feb 2017 11:57:15 +0000 (UTC) Received: (qmail 11633 invoked by uid 550); 8 Feb 2017 11:56:42 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 9963 invoked from network); 8 Feb 2017 11:56:32 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0cK7+Ar28vcoVuW/0Wuc/om69UhlFVxMa0GtSvxNHl0=; b=Ye7p26xVb9HSbT+TmLocgUr7EaVCiqcaRf1jmc6Nd9kjLeL+uu0PV3SuBHMhLTw+8b grKZPUc+aGi5wH2shGeVYkdfRhsrDctHiVkKpjE+bbmxYwDqGx+JEwd+nNhvLnwin9FQ 8fDmNeU75vcSluh0VnO5S9b+st64QlUpIuaWM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0cK7+Ar28vcoVuW/0Wuc/om69UhlFVxMa0GtSvxNHl0=; b=hIe83LtRcY9HWsvUv/Ldn9NGLg3WJEiY8VjOjqUt7nLho3M+dbORcAYnyGRawJAWsx nmD/m7K/vfG03mtawr6iSSKh/rztblHHppDJEvYV9ACkUvr6JhkC7kotKcUdWKvPAEKG rYuCwUVdpaU2mhMBDU8b9EftyJ70UOTCrSRHQLWcja+Wm2hFJ+r6jXUYZtc8sywDtrSM lzcB9KVSGe7oS+Kj2meF3qeGxXolloBjdde7C7Bf7QI/i19JDhPosujTKgMnJVBNMfz3 DSxDjB0mSv8nrY9MbEU8cqPGEL28N4+MLOL54a8uMnGuLCcLzUr61xK3qrwkRHlHwulY MhGw== X-Gm-Message-State: AIkVDXItecf7S4O3Nrf+pBxOjHhAoWLWs6dETVDmzXHayvcdy3K2QHZjH9m+F6GwbBW4nM5Z X-Received: by 10.223.154.114 with SMTP id z105mr18662738wrb.89.1486554981376; Wed, 08 Feb 2017 03:56:21 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, mark.rutland@arm.com, leif.lindholm@linaro.org Cc: catalin.marinas@arm.com, linux@armlinux.org.uk, kernel-hardening@lists.openwall.com, labbott@fedoraproject.org, Ard Biesheuvel Date: Wed, 8 Feb 2017 11:55:40 +0000 Message-Id: <1486554947-3964-8-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486554947-3964-1-git-send-email-ard.biesheuvel@linaro.org> References: <1486554947-3964-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [kernel-hardening] [PATCH v2 07/14] arm64: efi: replace open coded constants with symbolic ones X-Virus-Scanned: ClamAV using ClamSMTP Replace open coded constants with symbolic ones throughout the Image and the EFI headers. No binary level changes are intended. Signed-off-by: Ard Biesheuvel Acked-by: Mark Rutland --- arch/arm64/kernel/efi-header.S | 38 +++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/arch/arm64/kernel/efi-header.S b/arch/arm64/kernel/efi-header.S index 8786d58af2df..7637226ea9ca 100644 --- a/arch/arm64/kernel/efi-header.S +++ b/arch/arm64/kernel/efi-header.S @@ -7,22 +7,24 @@ * published by the Free Software Foundation. */ +#include +#include + .macro __EFI_PE_HEADER - .ascii "PE" - .short 0 + .long PE_MAGIC coff_header: - .short 0xaa64 // AArch64 - .short 1 // nr_sections + .short IMAGE_FILE_MACHINE_ARM64 // Machine + .short section_count // NumberOfSections .long 0 // TimeDateStamp .long 0 // PointerToSymbolTable .long 0 // NumberOfSymbols .short section_table - optional_header // SizeOfOptionalHeader - .short 0x206 // Characteristics. - // IMAGE_FILE_DEBUG_STRIPPED | - // IMAGE_FILE_EXECUTABLE_IMAGE | - // IMAGE_FILE_LINE_NUMS_STRIPPED + .short IMAGE_FILE_DEBUG_STRIPPED | \ + IMAGE_FILE_EXECUTABLE_IMAGE | \ + IMAGE_FILE_LINE_NUMS_STRIPPED // Characteristics + optional_header: - .short 0x20b // PE32+ format + .short PE_OPT_MAGIC_PE32PLUS // PE32+ format .byte 0x02 // MajorLinkerVersion .byte 0x14 // MinorLinkerVersion .long _end - efi_header_end // SizeOfCode @@ -33,7 +35,7 @@ optional_header: extra_header_fields: .quad 0 // ImageBase - .long 0x1000 // SectionAlignment + .long SZ_4K // SectionAlignment .long PECOFF_FILE_ALIGNMENT // FileAlignment .short 0 // MajorOperatingSystemVersion .short 0 // MinorOperatingSystemVersion @@ -48,7 +50,7 @@ extra_header_fields: // Everything before the kernel image is considered part of the header .long efi_header_end - _head // SizeOfHeaders .long 0 // CheckSum - .short 0xa // Subsystem (EFI application) + .short IMAGE_SUBSYSTEM_EFI_APPLICATION // Subsystem .short 0 // DllCharacteristics .quad 0 // SizeOfStackReserve .quad 0 // SizeOfStackCommit @@ -71,10 +73,7 @@ extra_header_fields: // Section table section_table: - .ascii ".text" - .byte 0 - .byte 0 - .byte 0 // end of 0 padding of section name + .ascii ".text\0\0\0" .long _end - efi_header_end // VirtualSize .long efi_header_end - _head // VirtualAddress .long _edata - efi_header_end // SizeOfRawData @@ -84,7 +83,12 @@ section_table: .long 0 // PointerToLineNumbers .short 0 // NumberOfRelocations .short 0 // NumberOfLineNumbers - .long 0xe0000020 // Characteristics + .long IMAGE_SCN_CNT_CODE | \ + IMAGE_SCN_MEM_EXECUTE | \ + IMAGE_SCN_MEM_READ | \ + IMAGE_SCN_MEM_WRITE // Characteristics + + .set section_count, (. - section_table) / 40 #ifdef CONFIG_DEBUG_EFI /* @@ -106,7 +110,7 @@ efi_debug_table: .long 0 // TimeDateStamp .short 0 // MajorVersion .short 0 // MinorVersion - .long 2 // Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW + .long IMAGE_DEBUG_TYPE_CODEVIEW // Type .long efi_debug_entry_size // SizeOfData .long 0 // RVA .long efi_debug_entry - _head // FileOffset