From patchwork Wed Feb 8 11:55:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 93639 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2689313qgi; Wed, 8 Feb 2017 05:44:42 -0800 (PST) X-Received: by 10.98.89.195 with SMTP id k64mr26162043pfj.126.1486561482595; Wed, 08 Feb 2017 05:44:42 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z43si7118737plh.253.2017.02.08.05.44.42; Wed, 08 Feb 2017 05:44:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753604AbdBHNom (ORCPT + 2 others); Wed, 8 Feb 2017 08:44:42 -0500 Received: from mail-wm0-f41.google.com ([74.125.82.41]:34904 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752739AbdBHNol (ORCPT ); Wed, 8 Feb 2017 08:44:41 -0500 Received: by mail-wm0-f41.google.com with SMTP id v186so48009120wmd.0 for ; Wed, 08 Feb 2017 05:44:40 -0800 (PST) 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=T6phON+cw6Yvguzp/2IUEoYgMcUEfBfLYE98/QgxkE8=; b=feYqr/bH147jWz2N4+TfsgH47OZbwr6mxrsFZb315dz4URxOYxh9esuCFBtleZFw8c qk2d+3taREaehE4O6H0gzQYgklaAa14HffQ/B7u2GLn29ikJXpaFteCClZ+vXCApzfLp cMMnqJXmNaQrYH3upSV0aUeKR/J3HB9JlV4Gk= 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=T6phON+cw6Yvguzp/2IUEoYgMcUEfBfLYE98/QgxkE8=; b=oCjDgSIVOnRK1hagbsEb/GN7f9NbGgMR7mRc/7Z7FLsd5eM6XXMMyGioi9I38iHpNj 2RvqfFGibQVwaUCAuqo/kV8KkJ4kiE1r92lCwv4dxon4yaNsSTGabxR4MfGonNsBy6Yx si5nA4b4iIeGtnxrmzmYrFh+8CQkJY242/92q+EHR2QrM+pwFjFqK2NZDzwyKAuyaQEP TVaOAiX8VjmfZTW3pTU4ZPC2TBxosOW+AOkOx7V6dx+rasnlNxFTwtuoFrYks80pXFL5 05jUaBRzP/3bEo6mjyo1LH9Y7W6WypWDnBX12o4cKQlQI1GW6GaTKnGXqMqYe3Ybmac5 p4Bw== X-Gm-Message-State: AMke39m4kB8hkcQXmEorxYfE8e9guyyMkYTbqW586BMA1GGiJKu4fmkq3QiYnHelIeGiA0yI X-Received: by 10.28.52.19 with SMTP id b19mr18080283wma.134.1486554983540; Wed, 08 Feb 2017 03:56:23 -0800 (PST) Received: from localhost.localdomain ([160.169.163.122]) by smtp.gmail.com with ESMTPSA id 123sm2974815wml.6.2017.02.08.03.56.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Feb 2017 03:56:22 -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 Subject: [PATCH v2 08/14] arm64: efi: split Image code and data into separate PE/COFF sections Date: Wed, 8 Feb 2017 11:55:41 +0000 Message-Id: <1486554947-3964-9-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> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org To prevent unintended modifications to the kernel text (malicious or otherwise) while running the EFI stub, describe the kernel image as two separate sections: a .text section with read-execute permissions, covering .text, .rodata and .init.text, and a .data section with read-write permissions, covering .init.data, .data and .bss. This relies on the firmware to actually take the section permission flags into account, but this is something that is currently being implemented in EDK2, which means we will likely start seeing it in the wild between one and two years from now. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/efi-header.S | 23 +++++++++++++++----- arch/arm64/kernel/vmlinux.lds.S | 5 +++++ 2 files changed, 23 insertions(+), 5 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/arm64/kernel/efi-header.S b/arch/arm64/kernel/efi-header.S index 7637226ea9ca..5870bd611498 100644 --- a/arch/arm64/kernel/efi-header.S +++ b/arch/arm64/kernel/efi-header.S @@ -27,8 +27,8 @@ optional_header: .short PE_OPT_MAGIC_PE32PLUS // PE32+ format .byte 0x02 // MajorLinkerVersion .byte 0x14 // MinorLinkerVersion - .long _end - efi_header_end // SizeOfCode - .long 0 // SizeOfInitializedData + .long __pecoff_data_start - efi_header_end // SizeOfCode + .long __pecoff_data_size // SizeOfInitializedData .long 0 // SizeOfUninitializedData .long __efistub_entry - _head // AddressOfEntryPoint .long efi_header_end - _head // BaseOfCode @@ -74,9 +74,9 @@ extra_header_fields: // Section table section_table: .ascii ".text\0\0\0" - .long _end - efi_header_end // VirtualSize + .long __pecoff_data_start - efi_header_end // VirtualSize .long efi_header_end - _head // VirtualAddress - .long _edata - efi_header_end // SizeOfRawData + .long __pecoff_data_start - efi_header_end // SizeOfRawData .long efi_header_end - _head // PointerToRawData .long 0 // PointerToRelocations @@ -84,7 +84,20 @@ section_table: .short 0 // NumberOfRelocations .short 0 // NumberOfLineNumbers .long IMAGE_SCN_CNT_CODE | \ - IMAGE_SCN_MEM_EXECUTE | \ + IMAGE_SCN_MEM_READ | \ + IMAGE_SCN_MEM_EXECUTE // Characteristics + + .ascii ".data\0\0\0" + .long __pecoff_data_size // VirtualSize + .long __pecoff_data_start - _head // VirtualAddress + .long __pecoff_data_rawsize // SizeOfRawData + .long __pecoff_data_start - _head // PointerToRawData + + .long 0 // PointerToRelocations + .long 0 // PointerToLineNumbers + .short 0 // NumberOfRelocations + .short 0 // NumberOfLineNumbers + .long IMAGE_SCN_CNT_INITIALIZED_DATA | \ IMAGE_SCN_MEM_READ | \ IMAGE_SCN_MEM_WRITE // Characteristics diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index b8deffa9e1bf..a93cc2b6f50b 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -149,6 +149,9 @@ SECTIONS ARM_EXIT_KEEP(EXIT_TEXT) } + . = ALIGN(SZ_4K); + __pecoff_data_start = .; + .init.data : { INIT_DATA INIT_SETUP(16) @@ -206,6 +209,7 @@ SECTIONS } PECOFF_EDATA_PADDING + __pecoff_data_rawsize = ABSOLUTE(. - __pecoff_data_start); _edata = .; BSS_SECTION(0, 0, 0) @@ -221,6 +225,7 @@ SECTIONS . += RESERVED_TTBR0_SIZE; #endif + __pecoff_data_size = ABSOLUTE(. - __pecoff_data_start); _end = .; STABS_DEBUG