From patchwork Wed Aug 13 17:53:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 35385 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oi0-f70.google.com (mail-oi0-f70.google.com [209.85.218.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0C8B1203C5 for ; Wed, 13 Aug 2014 17:55:06 +0000 (UTC) Received: by mail-oi0-f70.google.com with SMTP id u20sf457387oif.1 for ; Wed, 13 Aug 2014 10:55:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id:cc :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=gKaWcwuLNMCiTpbfath+rHCZm/G1rjam06nr1kf4+xk=; b=kmOKawch71bSM0nWN+tbJ4Xmv41J03Y87fFeZIkjgpciZvnXYRZ/VWrbDKC1ull8/m nWHypXy4hhZ/4Lv7FMNLImP6Fluyo7Hm76w3HvFjhNevh5lITTNN26BMpq4DmKYV9fKc 4yhJoxIrlQk2Wx18dLqbtu6Q5kNAVusksErTBoUSNBEyA2u1YbRKxJl+vapFwaKncoEG IvXG9KtYLN2iZd6hCo1cQlwCA1+QOfEaQiWF6YV77kUbojYDT+1rQf2U3iySq6MhSSwx ZNXz4tRU9OnLLUNneQVq+fRUsj3hfIbzrfh2qDTwv+HFXvNqsxyYgSnPWjijQZwFVBR4 jp7A== X-Gm-Message-State: ALoCoQm5yQ9QWyj3uDiezVBXTt2VXOawFXsWSiBmw9y8lK6AMiBuACSYgoF4zubmcwzO4W6wfsOP X-Received: by 10.182.32.1 with SMTP id e1mr3182179obi.11.1407952505635; Wed, 13 Aug 2014 10:55:05 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.39.148 with SMTP id v20ls679533qgv.93.gmail; Wed, 13 Aug 2014 10:55:05 -0700 (PDT) X-Received: by 10.220.166.207 with SMTP id n15mr2258831vcy.75.1407952505483; Wed, 13 Aug 2014 10:55:05 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id t10si1542992vcj.42.2014.08.13.10.55.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 13 Aug 2014 10:55:05 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id lf12so111572vcb.40 for ; Wed, 13 Aug 2014 10:55:05 -0700 (PDT) X-Received: by 10.221.5.137 with SMTP id og9mr5263231vcb.18.1407952505390; Wed, 13 Aug 2014 10:55:05 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp349784vcb; Wed, 13 Aug 2014 10:55:04 -0700 (PDT) X-Received: by 10.66.123.75 with SMTP id ly11mr5417737pab.82.1407952504498; Wed, 13 Aug 2014 10:55:04 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id bl4si2040412pdb.31.2014.08.13.10.55.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Aug 2014 10:55:04 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XHcjx-0002VQ-4z; Wed, 13 Aug 2014 17:53:37 +0000 Received: from mail-wg0-f49.google.com ([74.125.82.49]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XHcju-0002Td-76 for linux-arm-kernel@lists.infradead.org; Wed, 13 Aug 2014 17:53:34 +0000 Received: by mail-wg0-f49.google.com with SMTP id k14so76455wgh.32 for ; Wed, 13 Aug 2014 10:53:11 -0700 (PDT) X-Received: by 10.180.81.103 with SMTP id z7mr39443249wix.23.1407952391401; Wed, 13 Aug 2014 10:53:11 -0700 (PDT) Received: from ards-macbook-pro.local ([109.227.30.102]) by mx.google.com with ESMTPSA id lh15sm10723726wic.10.2014.08.13.10.53.08 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 13 Aug 2014 10:53:09 -0700 (PDT) From: Ard Biesheuvel To: mark.rutland@arm.com, leif.lindholm@linaro.org, catalin.marinas@arm.com, will.deacon@arm.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH] arm64: align randomized TEXT_OFFSET on 4 kB boundary Date: Wed, 13 Aug 2014 19:53:03 +0200 Message-Id: <1407952383-1214-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140813_105334_414046_0D65C5EE X-CRM114-Status: GOOD ( 12.97 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.49 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [74.125.82.49 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Ard Biesheuvel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 When booting via UEFI, the kernel Image is loaded at a 4 kB boundary and the embedded EFI stub is executed in place. The EFI stub relocates the Image to reside TEXT_OFFSET bytes above a 2 MB boundary, and jumps into the kernel proper. In AArch64, PC relative symbol references are emitted using adrp/add or adrp/ldr pairs, where the offset into a 4 kB page is resolved using a separate :lo12: relocation. This implicitly assumes that the code will always be executed at the same relative offset with respect to a 4 kB boundary, or the references will point to the wrong address. This means we should link the kernel at a 4 kB aligned base address in order to remain compatible with the base address the UEFI loader uses when doing the initial load of Image. So update the code that generates TEXT_OFFSET to choose a multiple of 4 kB. At the same time, update the code so it chooses from the interval [0..2MB) as the author originally intended. Signed-off-by: Ard Biesheuvel Reviewed-by: Mark Rutland --- arch/arm64/Makefile | 2 +- arch/arm64/kernel/head.S | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 57833546bf00..2df5e5daeebe 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -39,7 +39,7 @@ 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%04x0\n", int(65535 * rand())}') +TEXT_OFFSET := $(shell awk 'BEGIN {srand(); printf "0x%03x000\n", int(512 * rand())}') else TEXT_OFFSET := 0x00080000 endif diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index b6ca95aee348..ae055a18b04a 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -38,11 +38,11 @@ #define KERNEL_RAM_VADDR (PAGE_OFFSET + TEXT_OFFSET) -#if (TEXT_OFFSET & 0xf) != 0 -#error TEXT_OFFSET must be at least 16B aligned -#elif (PAGE_OFFSET & 0xfffff) != 0 +#if (TEXT_OFFSET & 0xfff) != 0 +#error TEXT_OFFSET must be at least 4kB aligned +#elif (PAGE_OFFSET & 0x1fffff) != 0 #error PAGE_OFFSET must be at least 2MB aligned -#elif TEXT_OFFSET > 0xfffff +#elif TEXT_OFFSET > 0x1fffff #error TEXT_OFFSET must be less than 2MB #endif