From patchwork Sat Jun 17 22:24:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Levin, Alexander \(Sasha Levin\)" X-Patchwork-Id: 105785 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp258059qgd; Sat, 17 Jun 2017 15:31:45 -0700 (PDT) X-Received: by 10.84.217.15 with SMTP id o15mr5605181pli.31.1497738705184; Sat, 17 Jun 2017 15:31:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497738705; cv=none; d=google.com; s=arc-20160816; b=Zf7AdLMGXHa3wI0kRQTidoFYqp5u9DAfA2SGpYZy234oaKNWUDHSODq9Nv6qzp3OJ+ tRl5XPAuQjoc2NZjjxpr+O2qdU7zkqM9JA5h2yVizjOEsRgUvfLl1X9P5IMfxtcGC/UR +TfKnH4YOJERNbCGc4q3294/8DWS/xdACoAgbLmeozoa6FwAgEQIa97PA37nuw2fgdQF /sdImWKpI66Z4KvfTFr/qrQKbf9CqmX1afuGbwPd5tIRjChsV6VckfUNaBGBr0LZVxQc d1msyo6XEdoHiUJKAq8r92AWqyeUML7fODgCXgUenwQfwC1qrED3hGmSqIVvzkOqRXX4 g9Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:to:dkim-signature :dkim-signature:cc:from:dkim-signature:arc-authentication-results; bh=T1GhBYRAZVGYF5xUuwZf/bxt6Ebzex89PzN2dRczQZA=; b=HXd0a1Ltnx72gOC/Sq4IXDVAyhtfs4OrwCkDoca4N8xzFcTVdgVw/EcVtGwAs+QTib g+H7CaRYrrqut3y6W4ZGQZLb2BBLQbU+tKOBi2uK6oNQU5eSkMbCm3xKbyh1Q4ADKCxv sXN8nyFolil4aDFkn1xp/xhiYTLdF8e2R+DdFo+w5DYKHQ7HcGgC6YvySN3ZJfbYZX0J yuAWyksbIUZsTBRtGuxqGt3QA0qrIoH11PQ3LxcGGz661aJLf3dD5ZS/bubvRX+WdSeY NNjJL8EupftsQzhdLFd8TyI01rGLghVH2CZqjZ5F34Lf5d8n0omMzqtqPJ373luk6k2V QgSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@verizon.com header.b=JZeI5+M+; dkim=fail header.i=@verizon.com header.b=Jvju4egh; dkim=fail header.i=@verizon.com header.b=pCC3jQbB; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=verizon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y15si274553pli.569.2017.06.17.15.31.44; Sat, 17 Jun 2017 15:31:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@verizon.com header.b=JZeI5+M+; dkim=fail header.i=@verizon.com header.b=Jvju4egh; dkim=fail header.i=@verizon.com header.b=pCC3jQbB; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=verizon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753491AbdFQWbh (ORCPT + 6 others); Sat, 17 Jun 2017 18:31:37 -0400 Received: from omzsmtpe02.verizonbusiness.com ([199.249.25.209]:19922 "EHLO omzsmtpe02.verizonbusiness.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753488AbdFQW0l (ORCPT ); Sat, 17 Jun 2017 18:26:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1497738401; x=1529274401; h=from:cc:to:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=0xbJpLFEhsnD3HfW9/66KeKEC/Ie1IMkEg2aczn7Z/c=; b=JZeI5+M+4SARdA5bBlq5y3nJLHDZs9YL4n2P6C0h3Lio0hfavHptEsTT kNJwHk3WZPqtlfcLGt9Y3f+7Ewv5HfBz2UNoUOo0qjOhnAdy64zuCf9/d 0UnPYO3AzzNf5AHDPdC7Mxon8acGy4TRNdTA1ZSHkXESVz6ytEaVa0JCG Q=; X-IronPort-Anti-Spam-Filtered: false Received: from unknown (HELO fldsmtpi03.verizon.com) ([166.68.71.145]) by omzsmtpe02.verizonbusiness.com with ESMTP; 17 Jun 2017 22:26:33 +0000 From: "Levin, Alexander (Sasha Levin)" Cc: Ard Biesheuvel , Catalin Marinas , "Levin, Alexander (Sasha Levin)" X-IronPort-AV: E=Sophos;i="5.39,316,1493683200"; d="scan'208";a="372653931" Received: from rogue-10-255-192-101.rogue.vzwcorp.com (HELO apollo.verizonwireless.com) ([10.255.192.101]) by fldsmtpi03.verizon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 17 Jun 2017 22:26:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1497738368; x=1529274368; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=0xbJpLFEhsnD3HfW9/66KeKEC/Ie1IMkEg2aczn7Z/c=; b=Jvju4egh/o4E3MvfbxqaPQ8k27y7X913umK8MwmT/IA4Y6Hpg8++Icgx iaoZ55W3+myaeBeXvtKpCoZ5ZgjrbeqA8etFfubXhG4TnDRqmjAIDEMNn v9oTx80O5pqNqwTBJyOT8RdFcdnJGmkhdWGoPFBdkUJP7ID2qWGxlqYNt g=; Received: from viking.odc.vzwcorp.com (HELO mercury.verizonwireless.com) ([10.255.240.26]) by apollo.verizonwireless.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 17 Jun 2017 18:26:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1497738367; x=1529274367; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=0xbJpLFEhsnD3HfW9/66KeKEC/Ie1IMkEg2aczn7Z/c=; b=pCC3jQbBkokBRiycSzhEHsvQ7BU9YetGrNsVf26CqAU8r6s4pXMfBvvx GFHzchWylz1OCMiorarp7iFC7ZA+t58ldrmtIUH+3dW2l5ssdRvsJP7M7 bkDVE0DvtU5fh/EFz48TBaX5i4/zP+HTEmGOkPSXYLQk4o21D66Q6bvfN Q=; X-Host: viking.odc.vzwcorp.com Received: from casac1exh003.uswin.ad.vzwcorp.com ([10.11.218.45]) by mercury.verizonwireless.com with ESMTP/TLS/AES128-SHA256; 17 Jun 2017 22:26:07 +0000 Received: from scwexch15apd.uswin.ad.vzwcorp.com (153.114.130.34) by CASAC1EXH003.uswin.ad.vzwcorp.com (10.11.218.45) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sat, 17 Jun 2017 15:26:06 -0700 Received: from OMZP1LUMXCA16.uswin.ad.vzwcorp.com (144.8.22.194) by scwexch15apd.uswin.ad.vzwcorp.com (153.114.130.34) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Sat, 17 Jun 2017 15:26:06 -0700 Received: from OMZP1LUMXCA17.uswin.ad.vzwcorp.com (144.8.22.195) by OMZP1LUMXCA16.uswin.ad.vzwcorp.com (144.8.22.194) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Sat, 17 Jun 2017 17:26:05 -0500 Received: from OMZP1LUMXCA17.uswin.ad.vzwcorp.com ([144.8.22.195]) by OMZP1LUMXCA17.uswin.ad.vzwcorp.com ([144.8.22.195]) with mapi id 15.00.1263.000; Sat, 17 Jun 2017 17:26:05 -0500 To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH for v4.9 LTS 62/86] arm64: assembler: make adr_l work in modules under KASLR Thread-Topic: [PATCH for v4.9 LTS 62/86] arm64: assembler: make adr_l work in modules under KASLR Thread-Index: AQHS57iIWfkfNIeRqUWLqmI38cjY2w== Date: Sat, 17 Jun 2017 22:24:49 +0000 Message-ID: <20170617222420.19316-62-alexander.levin@verizon.com> References: <20170617222420.19316-1-alexander.levin@verizon.com> In-Reply-To: <20170617222420.19316-1-alexander.levin@verizon.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.144.60.250] MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Ard Biesheuvel [ Upstream commit 41c066f2c4d436c535616fe182331766c57838f0 ] 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 Signed-off-by: Sasha Levin --- arch/arm64/include/asm/assembler.h | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) -- 2.11.0 diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index 28bfe6132eb6..851290d2bfe3 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -155,22 +155,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 /* @@ -181,6 +184,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] @@ -188,6 +192,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 /* @@ -197,8 +210,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 /*