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: 119200 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp845037qgn; Fri, 17 Nov 2017 10:24:14 -0800 (PST) X-Google-Smtp-Source: AGs4zMbkefPfUTcDqYQYsex70H8gk5pOjqUnpqE5lYABWN0W9MyBSMLPAyINYoETqGZaOp/35gFd X-Received: by 10.159.252.11 with SMTP id n11mr6094196pls.207.1510943054310; Fri, 17 Nov 2017 10:24:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510943054; cv=none; d=google.com; s=arc-20160816; b=ciGEl4pgbZkXS0DiCBARDV4GDfvWbGi5kHqirimHPtA0QwL7K4v9MPwBgu/ni6I6sj j9MnHmsDK6z4h4WHWx7NUKV3+GPsOTm8l1hTMc0Sbz7WW3dNfQMRumU2an7MN8d2gy4k ZnraTVcbwmw9XgozZimJv6Acn2UthcnNvzkYhGB2RlPXi56WZpvoSiSsllXNJgsRSuhL 8IsS+NJdbj0CrqnkJFcCayg3NTl2djzai0FZaF3WMD+rT/1KnIc0UNeL4q+Hwo/HH8Bz qZTPo+aqxYlCK3hwQ3d4cnvzuzwv6owUEzv61G4ON0svZKwxTNnymghzejlGm4KQ4WwN DCZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=UrTemSpdZXVKugSbACUYRYNejcJnpujb/ZMFHTSiHDw=; b=HwhgTRcGbU31RSQhP7I7GHapb0Pl96OsMzNCYfUe/QUpAUEfu09DaLaOePyRwIiqLT 9tvamUFjRRFPRnqta2ol/tUSZkeIc60Utaj41s146haX/nIb7sx2Kb0/oOY7TXQA+0ab CAZnPU6KMGpKNNDFV1MlSUZMmH6ueCozYBa694vUAC/MvUxgr8ancsG0KIK9xbgQc6hc oW4COA1YJqWvsiofBgJ1LoOAsLACmO+TE5DU80ty4DleCAO2Fg0HhosctCntoA9Yp1mk 59Z/GpaIbXw16lnTpbnjd9roS7BJtnj06qvb2nhFEJUZ4OWa3rYWvXe2ElRukQ9cGAye USrA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l5si3219397pli.480.2017.11.17.10.24.14; Fri, 17 Nov 2017 10:24:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760358AbdKQSYM (ORCPT + 28 others); 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 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 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 Precedence: bulk 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(-) -- 2.1.4 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