From patchwork Thu Dec 10 14:26:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 341066 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp5842472jai; Thu, 10 Dec 2020 11:43:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwuQDUHU/GLijEJ2i/FZItlyykA4Bev5MUtOPPQV7JIEE4WC7VJ3zCjFG5W6/RO864vFFo2 X-Received: by 2002:a17:906:3187:: with SMTP id 7mr8013750ejy.225.1607629412717; Thu, 10 Dec 2020 11:43:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607629412; cv=none; d=google.com; s=arc-20160816; b=oh4Up6e/R90+dcWajIt/h/Q7XH1asteRhXwm9Em0UywsSTwZoEjkC8GwNXtXOR9Ok/ VTkcemvdIIXWR3p7IpKVGOpTNJHPHtv50JQFxKlY4Uj1aFP5BaJo5TINkuVs/WHwu8j2 XO0bc3JQujIR5/mGJiJD/uTD0RY1ekNeALvGLzMe/72uhvqEu2O1PXOxJjVoVoO3lOu7 cu5USFUOhDHwVpe93NGWoPuDKoww8VllOJP7Rd6YaULUKYphN4hbW5VWCMiumgARC3EZ SidAmeOyfwjrw7yxG7AM4QDE2QR6ALeh2h4TPbeH1wcAYJgP+tGL+/nzA9XALDK0O5A9 HBIw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=VvKl9VifyGUXg8kee/8/UfBiRh6H1E8k45A5PnnugoM=; b=CDYIN0RR27kkcZCrGl8UhFlbm8I3ZtlJELcKc9B3UNfK9f1cjwBMgG9cYW5wYVZ3Fk pgv5zG4CQMPTTwUlo7S1roV+6Oif4dhJ/BlISGfT67dQC1DxLOmy63zw6jxyi5hWGMK5 UiP+EjpfMqpylrV4G411oZPG3Izji89Z7xW2jfEDq13WYpGE/V3uSrtkbG+gPO0yU90O TLEBJBzrjSfc8HwsclHc9QNqA+El8TQqPBaEiZT4Q2fLeHPwbdWxJAB1BnC04wLuLMl7 +73B2HXuKlsJM92qPDxcLLInzNmb/AXHFT5wRdwMThdM2ykWcy8bjr6q0d7E8GoMONm6 wQdg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id zp23si1937600ejb.261.2020.12.10.11.43.32; Thu, 10 Dec 2020 11:43:32 -0800 (PST) Received-SPF: pass (google.com: domain of stable-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 stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390126AbgLJO2n (ORCPT + 14 others); Thu, 10 Dec 2020 09:28:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:36490 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390144AbgLJO2k (ORCPT ); Thu, 10 Dec 2020 09:28:40 -0500 From: Greg Kroah-Hartman Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Rutland , Will Deacon , Ard Biesheuvel , Catalin Marinas , dann frazier Subject: [PATCH 4.4 29/39] arm64: assembler: make adr_l work in modules under KASLR Date: Thu, 10 Dec 2020 15:26:40 +0100 Message-Id: <20201210142602.329774863@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201210142600.887734129@linuxfoundation.org> References: <20201210142600.887734129@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@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 Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/assembler.h | 36 +++++++++++++++++++++++++++--------- arch/arm64/kernel/head.S | 3 ++- 2 files changed, 29 insertions(+), 10 deletions(-) --- 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 /* --- 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