From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932440AbdDRHbp (ORCPT ); Tue, 18 Apr 2017 03:31:45 -0400 Received: from terminus.zytor.com ([65.50.211.136]:51757 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932185AbdDRHag (ORCPT ); Tue, 18 Apr 2017 03:30:36 -0400 Date: Tue, 18 Apr 2017 00:25:14 -0700 From: tip-bot for Ard Biesheuvel Message-ID: Cc: peterz@infradead.org, hpa@zytor.com, tglx@linutronix.de, james.morse@arm.com, matt@codeblueprint.co.uk, mingo@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, linux-kernel@vger.kernel.org, ard.biesheuvel@linaro.org, torvalds@linux-foundation.org Reply-To: james.morse@arm.com, matt@codeblueprint.co.uk, mingo@kernel.org, peterz@infradead.org, hpa@zytor.com, tglx@linutronix.de, torvalds@linux-foundation.org, ard.biesheuvel@linaro.org, catalin.marinas@arm.com, mark.rutland@arm.com, linux-kernel@vger.kernel.org In-Reply-To: <20170417093201.10181-2-ard.biesheuvel@linaro.org> References: <20170417093201.10181-2-ard.biesheuvel@linaro.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:efi/core] efi/libstub/arm: Don't use TASK_SIZE when randomizing the RT space Git-Commit-ID: 197decefdb79d6f1350ba0316ce26ba737372d0c X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 197decefdb79d6f1350ba0316ce26ba737372d0c Gitweb: http://git.kernel.org/tip/197decefdb79d6f1350ba0316ce26ba737372d0c Author: Ard Biesheuvel AuthorDate: Mon, 17 Apr 2017 10:32:01 +0100 Committer: Ingo Molnar CommitDate: Mon, 17 Apr 2017 12:35:33 +0200 efi/libstub/arm: Don't use TASK_SIZE when randomizing the RT space As reported by James, Catalin and Mark, commit: e69176d68d26 ("ef/libstub/arm/arm64: Randomize the base of the UEFI rt services region") ... results in a crash in the firmware, regardless of whether KASLR is in effect or not and whether the firmware implements EFI_RNG_PROTOCOL or not. Mark has identified the root cause to be the inappropriate use of TASK_SIZE in the stub, which arm64 defines as: #define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \ TASK_SIZE_32 : TASK_SIZE_64) and testing thread flags at this point results in the dereference of pointers in uninitialized structures. So instead, introduce a preprocessor symbol EFI_RT_VIRTUAL_LIMIT and define it to TASK_SIZE_64 on arm64 and TASK_SIZE on ARM, both of which are compile time constants. Also, change the 'headroom' variable to static const to force an error if this might change in the future. Tested-by: Mark Rutland Tested-by: James Morse Tested-by: Catalin Marinas Signed-off-by: Ard Biesheuvel Cc: Linus Torvalds Cc: Matt Fleming Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-arm-kernel@lists.infradead.org Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20170417093201.10181-2-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar --- drivers/firmware/efi/libstub/arm-stub.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c index 1e45ec5..8181ac1 100644 --- a/drivers/firmware/efi/libstub/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -32,6 +32,12 @@ #define EFI_RT_VIRTUAL_BASE SZ_512M #define EFI_RT_VIRTUAL_SIZE SZ_512M +#ifdef CONFIG_ARM64 +# define EFI_RT_VIRTUAL_LIMIT TASK_SIZE_64 +#else +# define EFI_RT_VIRTUAL_LIMIT TASK_SIZE +#endif + static u64 virtmap_base = EFI_RT_VIRTUAL_BASE; efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, @@ -236,8 +242,9 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table, * shift of 21 bit positions into account when scaling * the headroom value using a 32-bit random value. */ - u64 headroom = TASK_SIZE - EFI_RT_VIRTUAL_BASE - - EFI_RT_VIRTUAL_SIZE; + static const u64 headroom = EFI_RT_VIRTUAL_LIMIT - + EFI_RT_VIRTUAL_BASE - + EFI_RT_VIRTUAL_SIZE; u32 rnd; status = efi_get_random_bytes(sys_table, sizeof(rnd),