From patchwork Mon Jun 25 22:38:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 10488261 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AECFE601A0 for ; Tue, 26 Jun 2018 08:40:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C02A2889E for ; Tue, 26 Jun 2018 08:40:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F6E228896; Tue, 26 Jun 2018 08:40:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 7911128833 for ; Tue, 26 Jun 2018 08:40:04 +0000 (UTC) Received: (qmail 21965 invoked by uid 550); 26 Jun 2018 08:38:38 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 10081 invoked from network); 25 Jun 2018 22:41:20 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:in-reply-to:message-id:references:subject:from:to :cc; bh=lCTxE5lz0L47Pc05K8/9m/ry5J3JMywUVuCnYE96NS0=; b=lnO6g/IdbWSCN8e5QY+u5ZUmgm8HjsN0UqEy7Db1oroVaZvQbE2COyhlWKarF4hjGk 4jq2WgDHpxhflPw/XLbGBnaTyt24Y5lJDbzY3/I8qq14UsdxBQYXE7LVB0cPYySerrcR 3t/RgXsewHBsgrOo7LapcSVesPiz9B3K0QIAqhVQAFWsDZ38RE82ODXGRpsUonuEVUoS r+Agyq+K/OugM+erLr+iMazyeJDGjvSgqqKDY9Fr4w/qUdCcZvAMAqhQEaznM/PKgO3A HvkxkuvN96PEOa0nFh6d9KCM8L3e1wsRLkjaWGkOcADwhZZaI7Y9GTPDsO8BEjVMA05L avbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:in-reply-to:message-id :references:subject:from:to:cc; bh=lCTxE5lz0L47Pc05K8/9m/ry5J3JMywUVuCnYE96NS0=; b=WQTslPloV4ToYAtZhN0aKunnfcMv8Jei1c4uCafC19yob57HCgolRfEsgX758vmn1s MwEZOp5iTDtmwPL4+Pa5XfwX4nZz1e/JzayumoJjfySBBTH4/bRtV5+brtdYRinNfWVV RCNF4L8kxxs37iJXrFWCDk7pkaVzYyEglbOgDr4Szohill4ngyIoGfX9AHgjBF5vEGr6 d+kugzo/ecP860a4YpWktqFp5o2DNsVYx5OrYwThMN00jYVC1xoAispltoEqKBHQ4bkA FO0yChpo8kz6vTjXDRGHr8RIpMQZDvVT7mAAvI0a1HT5zc+9Ailw4IRgl/YW31ccFZMu KjSQ== X-Gm-Message-State: APt69E33+5xICDDtb1g1sR2hz3dfxGtOxzeQ3+GbviVmO52zzD+zQH85 K9vP+5qqNLbgJYQ6xWOrFZhUz0h3ULIYZowVv5FuiNk8UBTUUfn3cs/36YaWSudDoElgwD+hXPT yfvVzVRKfiUcRvs3A+QCFAE7+sU4M9LpfxFNjwHYcRHvWVfTxMJi0u8VvWGmXjIdsoqpWa2rswV wIUZBqJJPw X-Google-Smtp-Source: AAOMgpd4tZ9cGQvZmf2ZyxpLZ+yF9MAsCnCppU/Ftd7kOb3DNAVrK0GkCq/iob8uqaABFEa2ovUqGiMvDlnNaw== MIME-Version: 1.0 X-Received: by 2002:a24:74d0:: with SMTP id o199-v6mr1175909itc.11.1529966468641; Mon, 25 Jun 2018 15:41:08 -0700 (PDT) Date: Mon, 25 Jun 2018 15:38:53 -0700 In-Reply-To: <20180625224014.134829-1-thgarnie@google.com> Message-Id: <20180625224014.134829-6-thgarnie@google.com> References: <20180625224014.134829-1-thgarnie@google.com> X-Mailer: git-send-email 2.18.0.rc2.346.g013aa6912e-goog Subject: [PATCH v5 05/27] x86: relocate_kernel - Adapt assembly for PIE support From: Thomas Garnier To: kernel-hardening@lists.openwall.com Cc: Thomas Garnier , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, "Kirill A. Shutemov" , Tom Lendacky , linux-kernel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Change the assembly code to use only relative references of symbols for the kernel to be PIE compatible. Position Independent Executable (PIE) support will allow to extend the KASLR randomization range 0xffffffff80000000. Signed-off-by: Thomas Garnier --- arch/x86/kernel/relocate_kernel_64.S | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S index 11eda21eb697..a7227dfe1a2b 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -208,9 +208,11 @@ identity_mapped: movq %rax, %cr3 lea PAGE_SIZE(%r8), %rsp call swap_pages - movq $virtual_mapped, %rax - pushq %rax - ret + jmp *virtual_mapped_addr(%rip) + + /* Absolute value for PIE support */ +virtual_mapped_addr: + .quad virtual_mapped virtual_mapped: movq RSP(%r8), %rsp