From patchwork Fri Nov 17 18:22:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 10063199 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 07A7A6023A for ; Fri, 17 Nov 2017 18:26:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC2672A9C2 for ; Fri, 17 Nov 2017 18:26:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E108C2ACBE; Fri, 17 Nov 2017 18:26:20 +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.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 523852ACB3 for ; Fri, 17 Nov 2017 18:26:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Phv9N929dz0Z4fbHJBb+KlRHioA0kQJf3jUWDKmW0UE=; b=mG5nf6biaA+QGSmcE4MFsxnijk Tp8PPh4alx3kBXVxKMe+d/ThPPpcAYXz5rBzluRzaROL3lMgn8eTiBDevS3BOiBDO4NrQFlXLtw/k If9qoepkvO1GLxOAl7le9xzglRO4kRGRc/wUwplE/W0JhTpnK80L2osmwgJPl+COPTAFobqvKp+jk D/4lhDVZZ9hgsRdKDznlWIJAebt2oK71RoqNTRfOGzOBvwFToR+blOjKO4PfzN1Sz62R37WucHFPG gs3BjO80KsZy7zlIMgDDxk2eJPzGvVbyRVVZQCo7GyyxTJR1O0qUrbb5gkUxn1JHF1FkXy/OcJgAv vJjdaClA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eFlLA-0001zX-7X; Fri, 17 Nov 2017 18:26:12 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eFlHj-0005qN-BM for linux-arm-kernel@lists.infradead.org; Fri, 17 Nov 2017 18:22:49 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 685BE19F6; Fri, 17 Nov 2017 10:21:55 -0800 (PST) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3A3DC3F246; Fri, 17 Nov 2017 10:21:55 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id E7D211AE10AF; Fri, 17 Nov 2017 18:22:03 +0000 (GMT) From: Will Deacon To: linux-arm-kernel@lists.infradead.org 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171117_102239_565304_6FAF57D0 X-CRM114-Status: GOOD ( 10.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, keescook@chromium.org, ard.biesheuvel@linaro.org, catalin.marinas@arm.com, dave.hansen@linux.intel.com, sboyd@codeaurora.org, linux-kernel@vger.kernel.org, Will Deacon MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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