From patchwork Tue Dec 8 01:10:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dann frazier X-Patchwork-Id: 339683 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp3278651jai; Mon, 7 Dec 2020 17:13:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJzPKVtFLiken37G372T60OjqsLqXhKVqBgZU0gKxQPubdu5TxfX38bd7XRdRNwgZBpJrfUY X-Received: by 2002:a17:906:b309:: with SMTP id n9mr21356954ejz.365.1607389980122; Mon, 07 Dec 2020 17:13:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607389980; cv=none; d=google.com; s=arc-20160816; b=SaOZgu2y4a7HWynHHgO6uq3c1JY++XgD5frQAe8jDHFspQrjA6LCG3reu7r03JJf+y sFDFqjshUwGaoME3gLh2hr6bWLSJ7pAOtk725KPFE5SaG23o5Kkx4eY6uNa+UAL4CYmu 0tt8zBfZHXEG+IvVcC/Kt0welno123g58WTYMoY0bYsh5ohQo9avNeJiV3rDFfYq9eR1 xzzOk11Y0pFPrkX4k5oVb2Ylp7ylSeSnG5SLfv36XLi5eHSTIpW9vvDtDZrw8FUh2Tkk WC2rIk/ie+E0RSTAagjRelltRSkx+3NqmtdNBpyMndZ8bPXQYOkMlZ1BHoFCznLWF5kE N9nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=3rrHxglEYf1EWV0oQ4opXyzaL9bwHBdjK/R9l/KBjhA=; b=MWe05HnYwRhc+PTLltzzYjghRLjGDefZ7snYc5ocXYPaR53aEsFLjugRKS/4we7QBW O1iCnhu2r+7+o1B2hd5COb6G1tfrn972vHzD3wTzU3IMFQFdcT9VMMRsuis9KwL+2+x9 TM82qBnfnGmiVeMKF5X9pOycP+qqUHDx7DeRsfYNrrlWtFq20ExDD2x6/ykf+45+032R 970voaI7wjgLkNNL2RBtfdNp99zulxN7h58drVPjMXM08U23SSZTlYYZ1HAgmRHwRPAt pE2y6tocroBTlWClLvN5uCXU0ISY67apCwtH6vHJdy7LzBa2WmoA+EIVD6XVhuG2iSIp cxsA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-efi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i16si7587877eja.375.2020.12.07.17.12.59; Mon, 07 Dec 2020 17:13:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-efi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-efi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726207AbgLHBLb (ORCPT + 1 other); Mon, 7 Dec 2020 20:11:31 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:53245 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725877AbgLHBLa (ORCPT ); Mon, 7 Dec 2020 20:11:30 -0500 Received: from 2.general.dannf.us.vpn ([10.172.65.1] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kmRWh-0005Ox-52; Tue, 08 Dec 2020 01:10:47 +0000 From: dann frazier To: stable@vger.kernel.org, Michael Schaller , Ard Biesheuvel , Greg Kroah-Hartman Cc: Matthew Garrett , Jeremy Kerr , linux-efi@vger.kernel.org Subject: [PATCH 4.4] arm64: assembler: make adr_l work in modules under KASLR Date: Mon, 7 Dec 2020 18:10:34 -0700 Message-Id: <20201208011034.3015079-1-dann.frazier@canonical.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Ard Biesheuvel commit 41c066f2c4d436c535616fe182331766c57838f0 upstream When CONFIG_RANDOMIZE_MODULE_REGION_FULL=y, the offset between loaded modules and the core kernel may exceed 4 GB, putting symbols exported by the core kernel out of the reach of the ordinary adrp/add instruction pairs used to generate relative symbol references. So make the adr_l macro emit a movz/movk sequence instead when executing in module context. While at it, remove the pointless special case for the stack pointer. Acked-by: Mark Rutland Acked-by: Will Deacon Signed-off-by: Ard Biesheuvel Signed-off-by: Catalin Marinas [ dannf: backported to v4.4 by replacing the 3-arg adr_l macro in head.S with it's output, as this commit drops the 3-arg variant ] Fixes: c042dd600f4e ("crypto: arm64/sha - avoid non-standard inline asm tricks") Signed-off-by: dann frazier --- arch/arm64/include/asm/assembler.h | 36 +++++++++++++++++++++++++++--------- arch/arm64/kernel/head.S | 3 ++- 2 files changed, 29 insertions(+), 10 deletions(-) -- 2.7.4 diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index f68abb1..7c28791 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -148,22 +148,25 @@ lr .req x30 // link register /* * Pseudo-ops for PC-relative adr/ldr/str , where - * is within the range +/- 4 GB of the PC. + * is within the range +/- 4 GB of the PC when running + * in core kernel context. In module context, a movz/movk sequence + * is used, since modules may be loaded far away from the kernel + * when KASLR is in effect. */ /* * @dst: destination register (64 bit wide) * @sym: name of the symbol - * @tmp: optional scratch register to be used if == sp, which - * is not allowed in an adrp instruction */ - .macro adr_l, dst, sym, tmp= - .ifb \tmp + .macro adr_l, dst, sym +#ifndef MODULE adrp \dst, \sym add \dst, \dst, :lo12:\sym - .else - adrp \tmp, \sym - add \dst, \tmp, :lo12:\sym - .endif +#else + movz \dst, #:abs_g3:\sym + movk \dst, #:abs_g2_nc:\sym + movk \dst, #:abs_g1_nc:\sym + movk \dst, #:abs_g0_nc:\sym +#endif .endm /* @@ -174,6 +177,7 @@ lr .req x30 // link register * the address */ .macro ldr_l, dst, sym, tmp= +#ifndef MODULE .ifb \tmp adrp \dst, \sym ldr \dst, [\dst, :lo12:\sym] @@ -181,6 +185,15 @@ lr .req x30 // link register adrp \tmp, \sym ldr \dst, [\tmp, :lo12:\sym] .endif +#else + .ifb \tmp + adr_l \dst, \sym + ldr \dst, [\dst] + .else + adr_l \tmp, \sym + ldr \dst, [\tmp] + .endif +#endif .endm /* @@ -190,8 +203,13 @@ lr .req x30 // link register * while needs to be preserved. */ .macro str_l, src, sym, tmp +#ifndef MODULE adrp \tmp, \sym str \src, [\tmp, :lo12:\sym] +#else + adr_l \tmp, \sym + str \src, [\tmp] +#endif .endm /* diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 6299a8a..504bcc3 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -424,7 +424,8 @@ __mmap_switched: str xzr, [x6], #8 // Clear BSS b 1b 2: - adr_l sp, initial_sp, x4 + adrp x4, initial_sp + add sp, x4, :lo12:initial_sp str_l x21, __fdt_pointer, x5 // Save FDT pointer str_l x24, memstart_addr, x6 // Save PHYS_OFFSET mov x29, #0