From patchwork Wed Oct 4 21:19:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9985505 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 6400060586 for ; Wed, 4 Oct 2017 21:22:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54E2628450 for ; Wed, 4 Oct 2017 21:22:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 483CD28C2E; Wed, 4 Oct 2017 21:22:38 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID 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 6B45A28450 for ; Wed, 4 Oct 2017 21:22:37 +0000 (UTC) Received: (qmail 15415 invoked by uid 550); 4 Oct 2017 21:21:08 -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 Received: (qmail 14326 invoked from network); 4 Oct 2017 21:21:06 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gf1F74HWnMPo0JFrTQOThqxyCM9hwFtsVlhgQ37bznE=; b=gUjc0dHQHoOPv+wiL+5xTmAAi9k2mcjfcfPi04l+ikTUxvX8ikmPfmby5ODZJyu8MF luVSAtW2o9JGqPxt1yx0i9M7wu2hpNGWA/OM8A2tZLiz6WfdWssDz0CkZCbmlgAUWhJi GTofjxZKKHBHkM/+pddBwKSwgPZEhMznSPmNLfiioQmUlmNLG1Zi49q9BogvvWx1VaPP hSLkGqPkeN0YEunIIq+rPcxRzJnMK+G6ZaaDx3hTld0rmfiZH0ScywZC/+rJFWYLkTIx Bi2dDb71KJHrUoTksAJm9MsEQBgyE1qzpZ7MWuQTVrCdx1F/QhNo78HFxe0Cx4uECU8a 4G2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gf1F74HWnMPo0JFrTQOThqxyCM9hwFtsVlhgQ37bznE=; b=tkQe1m8T6i8va8TFd8S0X0M6ZleotL0JmbP3pFuuAW+cxNspmZzcS1N2nDkrXd6FEo GGeoH32rwh8weO9ASaG9rqcuQSoUW/9FvFmVOxCKZDMoqZb4JeTpPHICgGV6kn9DWbi7 Gr89Kh0tTEqP56Zc317w5J22l60Xf3DCK+isCFMjUSo/n+WauFkwbUWfsRUuN2cMUihL BMWxUhmDaJbXt2vEyNOtUltINdasm/QtHpMzAA72G0J4/iJy4o7dXeGc9qCG4UYqc1AO GVbhoiNrdv7Znd/D+o4WXLA8EmF7lqEtPhCX3mNnqXvzObkUKDkvivKdTP7eq6Q5JdLY 0LvQ== X-Gm-Message-State: AHPjjUgsYR8sNF2cJmZqxIMtwXkrhwfxdp8qytTxt2NH30uy98mLaMYG 462Bsqzcz2ehQQ8gZfqFK2t6nw== X-Google-Smtp-Source: AOwi7QBXEEkOiw40moQsxjXiC69XWNDaj1/ZLj3oArE0CoxZRLt0qW20cC5DHUCC1hZNcxJf880mmw== X-Received: by 10.99.157.74 with SMTP id i71mr19956713pgd.238.1507152054070; Wed, 04 Oct 2017 14:20:54 -0700 (PDT) From: Thomas Garnier To: Herbert Xu , "David S . Miller" , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Peter Zijlstra , Josh Poimboeuf , Thomas Garnier , Arnd Bergmann , Kees Cook , Matthias Kaehlcke , Tom Lendacky , Andy Lutomirski , "Kirill A . Shutemov" , Borislav Petkov , "Rafael J . Wysocki" , Len Brown , Pavel Machek , Juergen Gross , Chris Wright , Alok Kataria , Rusty Russell , Tejun Heo , Christoph Lameter , Boris Ostrovsky , Alexey Dobriyan , Andrew Morton , Paul Gortmaker , Chris Metcalf , "Paul E . McKenney" , Nicolas Pitre , Borislav Petkov , "Luis R . Rodriguez" , Greg Kroah-Hartman , Christopher Li , Steven Rostedt , Jason Baron , Dou Liyang , "Rafael J . Wysocki" , Mika Westerberg , Lukas Wunner , Masahiro Yamada , Alexei Starovoitov , Daniel Borkmann , Markus Trippelsdorf , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Joerg Roedel , Rik van Riel , David Howells , Ard Biesheuvel , Waiman Long , Kyle Huey , Andrey Ryabinin , Jonathan Corbet , Matthew Wilcox , Michal Hocko , Peter Foley , Paul Bolle , Jiri Kosina , Rob Landley , "H . J . Lu" , Baoquan He , =?UTF-8?q?Jan=20H=20=2E=20Sch=C3=B6nherr?= , Daniel Micay Cc: x86@kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, virtualization@lists.linux-foundation.org, xen-devel@lists.xenproject.org, linux-arch@vger.kernel.org, linux-sparse@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, kernel-hardening@lists.openwall.com Date: Wed, 4 Oct 2017 14:19:41 -0700 Message-Id: <20171004212003.28296-6-thgarnie@google.com> X-Mailer: git-send-email 2.14.2.920.gcf0c67979c-goog In-Reply-To: <20171004212003.28296-1-thgarnie@google.com> References: <20171004212003.28296-1-thgarnie@google.com> Subject: [kernel-hardening] [RFC v3 05/27] x86: relocate_kernel - Adapt assembly for PIE support 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 extended the KASLR randomization range below the -2G memory limit. 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 307d3bac5f04..2ecbdcbe985b 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -200,9 +200,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