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: 9894321 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 3814860236 for ; Thu, 10 Aug 2017 17:29:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F94A27C05 for ; Thu, 10 Aug 2017 17:29:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13B9928635; Thu, 10 Aug 2017 17:29:12 +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=-3.6 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9DF7B27C05 for ; Thu, 10 Aug 2017 17:29:11 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dfrEY-0007d8-39; Thu, 10 Aug 2017 17:26:58 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dfrEX-0007b3-6t for xen-devel@lists.xenproject.org; Thu, 10 Aug 2017 17:26:57 +0000 Received: from [85.158.137.68] by server-5.bemta-3.messagelabs.com id CB/27-02181-0679C895; Thu, 10 Aug 2017 17:26:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrHIsWRWlGSWpSXmKPExsXiVRuspRs/vSf SYOtNCYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNaP9yymmgi3sFafen2RuYNzO1sXIxSEkMJ1R YsuubiYQh0XgFYvE/WvdzCCOhEA/q8SrptlADieQEydxeeNfdgi7WmLHn5esILaQgJLE1g1Lm SFG/WOU6P1wmg0kwSagJbGnYT7YWBGBpYISJ1uvMYI4zAItTBJP/m1jAqkSFvCVaPr1DmwFi4 CqxK+FnxlBbF4BC4mf138zQawzkXjSOgkszilgKTFt2UxmiNUWElN/rWSawCiwgJFhFaN6cWp RWWqRroVeUlFmekZJbmJmjq6hgbFebmpxcWJ6ak5iUrFecn7uJkZgeDEAwQ7GC+3OhxglOZiU RHmLP3VHCvEl5adUZiQWZ8QXleakFh9ilOHgUJLgnTy1J1JIsCg1PbUiLTMHGOgwaQkOHiUR3 q0gad7igsTc4sx0iNQpRkuOpg9bvjBxTDqwHUi+mvD/G5MQS15+XqqUOO9OkAYBkIaM0jy4cb BovMQoKyXMywh0oBBPQWpRbmYJqvwrRnEORiVh3n6QKTyZeSVwW18BHcQEdFCEbyfIQSWJCCm pBkYlR8FcyY3zOU8YnM7glOc+HnLq/NKCOg/+vI5JrpXrPih0SbQFpXGb22x4cPr+o0DFMs+f +rv/T7y4QERkk/F3o0stosJTd34MDNwqdtD/l81C5Xlr96heTLrSOYn33hulv9KT2v58stjjO CfmiuRb1bm5+7xKVraZ/zEJXRK74HPJNZXHVreVWIozEg21mIuKEwGThcRLwQIAAA== X-Env-Sender: thgarnie@google.com X-Msg-Ref: server-12.tower-31.messagelabs.com!1502386014!92685345!1 X-Originating-IP: [74.125.83.42] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 55764 invoked from network); 10 Aug 2017 17:26:55 -0000 Received: from mail-pg0-f42.google.com (HELO mail-pg0-f42.google.com) (74.125.83.42) by server-12.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 10 Aug 2017 17:26:55 -0000 Received: by mail-pg0-f42.google.com with SMTP id l64so5397165pge.5 for ; Thu, 10 Aug 2017 10:26:55 -0700 (PDT) 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=LWb6LThE4h+SXeDH/BzX2GUWb3rywLdYd5CRDkFAmqwI39pMvXBhq6ds4r6eV0P7BM 8/B6wGUHDGPVb/Qics2uMH0C6GnJU83oeVYtzIGi1m7+vbyxezJ5kEuiumFwgsZDTm35 yR+zTGojzneVm02keLGbjkrwFs/KuAs3RufO7vf/IuKtwlIogIZWJzBFHyUOnXaZeXcc lYwD4asXdRs8wcR7p2EtnaNKcF4i0n4LZ4esDFp+YAQcCKgwFgttvzJIYcNWGdx1dXgX h1lL4XrwaRlgUUAIcVN5OTrRpEEOEhwfoGPm16Q9gtxQxQ9hXLYungrHcsX5BRAXxzH1 chrQ== X-Gm-Message-State: AHYfb5gdSUxM/W1xFVPQmlf66sr0TuxJ39QeiMCSXVpSDHmRNnPpasV3 yjWsbbr8leLqjmp/ X-Received: by 10.98.200.151 with SMTP id i23mr13125624pfk.281.1502386013510; Thu, 10 Aug 2017 10:26:53 -0700 (PDT) Received: from skynet.sea.corp.google.com ([172.31.92.33]) by smtp.gmail.com with ESMTPSA id p77sm11894925pfi.153.2017.08.10.10.26.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Aug 2017 10:26:52 -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 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> Cc: linux-arch@vger.kernel.org, kvm@vger.kernel.org, linux-pm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, linux-sparse@vger.kernel.org, linux-crypto@vger.kernel.org, kernel-hardening@lists.openwall.com, xen-devel@lists.xenproject.org Subject: [Xen-devel] [RFC v2 07/23] x86: relocate_kernel - Adapt assembly for PIE support X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" 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