From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760356AbdKQSYM (ORCPT ); Fri, 17 Nov 2017 13:24:12 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:39476 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760307AbdKQSWA (ORCPT ); Fri, 17 Nov 2017 13:22:00 -0500 From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, ard.biesheuvel@linaro.org, sboyd@codeaurora.org, dave.hansen@linux.intel.com, keescook@chromium.org, Will Deacon Subject: [PATCH 17/18] arm64: makefile: Ensure TEXT_OFFSET doesn't overlap with trampoline Date: Fri, 17 Nov 2017 18:22:00 +0000 Message-Id: <1510942921-12564-18-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1510942921-12564-1-git-send-email-will.deacon@arm.com> References: <1510942921-12564-1-git-send-email-will.deacon@arm.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET=y, we could end up with a TEXT_OFFSET of less than 2 * PAGE_SIZE, which would result in an overlap with the trampoline and a panic on boot. Fix this by restricting the minimum value of the random TEXT_OFFSET value so that it is not less than 2 pages when CONFIG_UNMAP_KERNEL_AT_EL0 is enabled. I do wonder whether we should just remove CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET completely, since we're realistically never going to be able to change our offset from 0x80000, but this keeps the dream alive for now. Signed-off-by: Will Deacon --- arch/arm64/Makefile | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 939b310913cf..b60ac6c43ccd 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -87,9 +87,21 @@ head-y := arch/arm64/kernel/head.o # The byte offset of the kernel image in RAM from the start of RAM. ifeq ($(CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET), y) -TEXT_OFFSET := $(shell awk "BEGIN {srand(); printf \"0x%06x\n\", \ - int(2 * 1024 * 1024 / (2 ^ $(CONFIG_ARM64_PAGE_SHIFT)) * \ - rand()) * (2 ^ $(CONFIG_ARM64_PAGE_SHIFT))}") +TEXT_OFFSET := $(shell awk \ + "BEGIN { \ + srand(); \ + page_size = 2 ^ $(CONFIG_ARM64_PAGE_SHIFT); \ + tramp_size = 0; \ + if (\" $(CONFIG_UNMAP_KERNEL_AT_EL0)\" == \" y\") { \ + tramp_size = 2 * page_size; \ + } \ + offset = int(2 * 1024 * 1024 / page_size * rand()); \ + offset *= page_size; \ + if (offset < tramp_size) { \ + offset = tramp_size; \ + } \ + printf \"0x%06x\n\", offset; \ + }") else TEXT_OFFSET := 0x00080000 endif -- 2.1.4