From patchwork Thu Aug 10 17:25:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9894307 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 6B02A60236 for ; Thu, 10 Aug 2017 17:28:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51948286CF for ; Thu, 10 Aug 2017 17:28:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 456A0288A7; Thu, 10 Aug 2017 17:28:49 +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 793C6286CF for ; Thu, 10 Aug 2017 17:28:48 +0000 (UTC) Received: (qmail 32623 invoked by uid 550); 10 Aug 2017 17:27:09 -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 32477 invoked from network); 10 Aug 2017 17:27:05 -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=XcdugCyINexHhiuz1aJf0Zvnvb6BthqzjaCDG+vK5o4=; b=pa00BV+l9uDoQD+3WqoWqn5UX/fWPCZ3dwTLWF3MPXfSc65pb3T+XYXZ7ut4IrMpk1 G8JMWgqLuspS3pLhv7N1sApG6aj5SN5oMwW/LKW03Fo0xdFmmvkou3Yx0amgF8gOQLqn EUW7TWxWAyalvNJMGbj2U2WtvkcEM7IY6h05AoG5fQVxqL4EH3+jTWY+5H2CzAA45QPS qPCWFTlPyzcMbUkemavdTwEJTfAbe2Z4WLPGUHDoOPZ8sw0PoDQZMfpVbecHWR1/YiHX vGcXk4v1OL+aTUxT2TkBYOcA8pcB4RpGx2dsOzAw3VCygfeGDmEl6BAr/F51w/C4nDrE Farw== 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=XcdugCyINexHhiuz1aJf0Zvnvb6BthqzjaCDG+vK5o4=; b=B16qKbwqplTvcbpOdzTeZUXzYr6r4TAx/0GNPtK6KqjXQdwdgsHA2BFj2TjGVhsUGC At4aCzD8WDr2LhlgT5R6agf/SssJ+M4HPloUl8aWK3EgWTXbDmHHsmBDiM22UnTDH28R cPhOXwA2zoDstpMxQv5fwFL9om5gD0DOVtwgqsMNfR7ZhhHQGa+MZAC/VSoGkU/sqI5W ciHu/TEtZrdiVCJQS5vytPp1AKOE3HNMJGVjY0uGdxrBdmHJIlis2Iw+4GiSeGlYiMTl LBWOp2xDKyghcV7Dk39XTyo+v/sPdGqgr5TP6/1R3Iwq9Qkb2Qux0o0GcBXYddhhvaxM ax4Q== X-Gm-Message-State: AHYfb5iPunznFvAUJl16qmQVNRpPVQ+zKo1EB388hccEgIxW6/LXKLtI c4+oVmi6rFWkxqf5 X-Received: by 10.98.200.151 with SMTP id i23mr13125624pfk.281.1502386013510; Thu, 10 Aug 2017 10:26:53 -0700 (PDT) From: Thomas Garnier To: Herbert Xu , "David S . Miller" , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Peter Zijlstra , Josh Poimboeuf , Arnd Bergmann , Thomas Garnier , Matthias Kaehlcke , Boris Ostrovsky , Juergen Gross , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Joerg Roedel , Tom Lendacky , Andy Lutomirski , Borislav Petkov , Brian Gerst , "Kirill A . Shutemov" , "Rafael J . Wysocki" , Len Brown , Pavel Machek , Tejun Heo , Christoph Lameter , Paul Gortmaker , Chris Metcalf , Andrew Morton , "Paul E . McKenney" , Nicolas Pitre , Christopher Li , "Rafael J . Wysocki" , Lukas Wunner , Mika Westerberg , Dou Liyang , Daniel Borkmann , Alexei Starovoitov , Masahiro Yamada , Markus Trippelsdorf , Steven Rostedt , Kees Cook , Rik van Riel , David Howells , Waiman Long , Kyle Huey , Peter Foley , Tim Chen , Catalin Marinas , Ard Biesheuvel , Michal Hocko , Matthew Wilcox , "H . J . Lu" , Paul Bolle , Rob Landley , Baoquan He , Daniel Micay Cc: x86@kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, linux-pm@vger.kernel.org, linux-arch@vger.kernel.org, linux-sparse@vger.kernel.org, kernel-hardening@lists.openwall.com Date: Thu, 10 Aug 2017 10:25:59 -0700 Message-Id: <20170810172615.51965-8-thgarnie@google.com> X-Mailer: git-send-email 2.14.0.434.g98096fd7a8-goog In-Reply-To: <20170810172615.51965-1-thgarnie@google.com> References: <20170810172615.51965-1-thgarnie@google.com> Subject: [kernel-hardening] [RFC v2 07/23] 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