From patchwork Wed Oct 4 21:19:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9985579 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 8286160586 for ; Wed, 4 Oct 2017 21:23:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7319428C2C for ; Wed, 4 Oct 2017 21:23:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6736E28C2F; Wed, 4 Oct 2017 21:23:45 +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 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 EC16328C2E for ; Wed, 4 Oct 2017 21:23:44 +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 1dzr6P-0002wv-Gz; Wed, 04 Oct 2017 21:21:13 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzr6O-0002ur-EJ for xen-devel@lists.xenproject.org; Wed, 04 Oct 2017 21:21:12 +0000 Received: from [85.158.143.35] by server-6.bemta-6.messagelabs.com id 31/2E-03435-7C055D95; Wed, 04 Oct 2017 21:21:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrGIsWRWlGSWpSXmKPExsVyMfTAat3jAVc jDT44WXzfMpnJgdHj8IcrLAGMUayZeUn5FQmsGe8OrWEsmMpb8X/vErYGxjbuLkYuDiGBGYwS W3+8ZANxWAResUic2buLpYuRk0NCoJ9VYu3GVAg7S2LKvXNAcQ4gO03iyCtBiHClxJuJt5hBb CEBJYmtG5YyQwz9yyjxadICJpAEm4CWxJ6G+UwgCRGBWSISt173gG1jFjjDJHG87yQryFRhAS +JN+sdQUwWAVWJ9xfzQHp5BSwllrxdyAyxzETi4ZFrrCA2J1D8yIk3UIstJFrP3GeawCi4gJF hFaNGcWpRWWqRrqGhXlJRZnpGSW5iZo6uoYGZXm5qcXFiempOYlKxXnJ+7iZGYLgxAMEOxk/L Ag4xSnIwKYnybvK9GinEl5SfUpmRWJwRX1Sak1p8iFGGg0NJgneOP1BOsCg1PbUiLTMHGPgwa QkOHiUR3skgad7igsTc4sx0iNQpRkuOC3cu/WHiOLDnFpDsuHn3D5MQS15+XqqUOO9mkAYBkI aM0jy4cbDovMQoKyXMywh0oBBPQWpRbmYJqvwrRnEORiVhXllgrAvxZOaVwG19BXQQE9BBc5q ugBxUkoiQkmpgzP/02PIiTyx/TWugx4v4yunyi2I8K3/alklsbda6Yjn/14TEHemXuIW4i7Uq 6o4fkfTKOXs8g1uhZvaF2DcnxHWC5mw8y+2fUtbj8vCzsJHGun+V9U+223ucE3uWFF6/eUKr6 Nd6Mb8JX2cJnns2d4bs52rOL29bP9RfvGO+/fdF+6JvZvPfKLEUZyQaajEXFScCAMLoSiLJAg AA X-Env-Sender: thgarnie@google.com X-Msg-Ref: server-5.tower-21.messagelabs.com!1507152069!68396381!1 X-Originating-IP: [209.85.192.171] 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 65288 invoked from network); 4 Oct 2017 21:21:10 -0000 Received: from mail-pf0-f171.google.com (HELO mail-pf0-f171.google.com) (209.85.192.171) by server-5.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 4 Oct 2017 21:21:10 -0000 Received: by mail-pf0-f171.google.com with SMTP id n14so4998356pfh.8 for ; Wed, 04 Oct 2017 14:21:10 -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=SkOiE4XJ1I4cgeMk+K4tjeBaHCtXE2onqUAnPBH1uu0=; b=cLtw4g0iH8TyAZfPU4yp4+JKeCaOaUwzzx1zyLXmdTK6eY1z2CLEoMht22SIb2L+zS avMQuRnWMG+jqVy3T0VCtL9S0HNEIp7mndKa0pPQQdDpKWsg8KYYRhkc8iYzCuhdgC8y FueBFQXF8SzOQs7P2U9U3Bz7wLrDSxVvVdDg3n4PA99L3VI00rSF/VB5P5yckIDtbq6h 4qvAieGuuZWNQc81zUCZCgO8XSi67LVY19dcMH9mHrgfztKJ9Eb4JRldIaeMBAQEMVqT ftXGX6YoikRljBFwa7ebnq7XZ3S1Z2VpaHHTwC587e/d8XZzcqn1ZiOMvVUyHB+ko2o0 S5pQ== 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=SkOiE4XJ1I4cgeMk+K4tjeBaHCtXE2onqUAnPBH1uu0=; b=Y2nK6guY2nNlrWcFfG17CrpDVLg/fXTkkVm406RAHSRpFQjx/o5oG5kPUUbT02e3DI xMtsH3l7lBvKwJ0M2KmUYXsTkfwVNAJu3fJd1glxdJUJidxPf5Ef4UoiV7RWhFbo0rRC /qWem9EBpIvufbQojXGUZLmOQPyHwoE1WNfjrm5Uv+3i0m4WkFDjps8XlrA5iVHqWaDj 80oBfAfSMWUpA/kslXnlXsEXLp3KfUMiuAHhWgGJihNTRaEF6OchBdpq/4YWZunEFTns /Kqf9dSvuGTSMkpVfp6fVAkFYpldZvx6PSN0eFnvhcbY+ZLFTIdIC1HdScZBIQEXgucV GVNw== X-Gm-Message-State: AMCzsaUkGcHQ6oswLN4vBzGJWnInoYMaGuBZsnw42Ea6S6jtcCGQtmnK +hfMU7seOOccCxFgSYCPjQnz2A== X-Google-Smtp-Source: AOwi7QDN0b8B+tdQhMRHDzwP7/Xr5HJAcIKLqraeOkhkG4FvxdPw1DSr+ae4hhsbU/R8AHUNbWChlQ== X-Received: by 10.98.109.69 with SMTP id i66mr8829735pfc.200.1507152068640; Wed, 04 Oct 2017 14:21:08 -0700 (PDT) Received: from skynet.sea.corp.google.com ([172.31.92.33]) by smtp.gmail.com with ESMTPSA id s68sm30204019pfd.72.2017.10.04.14.21.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Oct 2017 14:21:07 -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 Date: Wed, 4 Oct 2017 14:19:49 -0700 Message-Id: <20171004212003.28296-14-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> Cc: linux-arch@vger.kernel.org, kvm@vger.kernel.org, linux-pm@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.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 v3 13/27] x86/boot/64: Use _text in a global 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 By default PIE generated code create only relative references so _text points to the temporary virtual address. Instead use a global variable so the relocation is done as expected. 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/head64.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index bab4fa579450..675f1dba3b21 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -45,8 +45,14 @@ static void __head *fixup_pointer(void *ptr, unsigned long physaddr) return ptr - (void *)_text + (void *)physaddr; } -unsigned long __head __startup_64(unsigned long physaddr, - struct boot_params *bp) +/* + * Use a global variable to properly calculate _text delta on PIE. By default + * a PIE binary do a RIP relative difference instead of the relocated address. + */ +unsigned long _text_offset = (unsigned long)(_text - __START_KERNEL_map); + +unsigned long __head notrace __startup_64(unsigned long physaddr, + struct boot_params *bp) { unsigned long load_delta, *p; unsigned long pgtable_flags; @@ -65,7 +71,7 @@ unsigned long __head __startup_64(unsigned long physaddr, * Compute the delta between the address I am compiled to run at * and the address I am actually running at. */ - load_delta = physaddr - (unsigned long)(_text - __START_KERNEL_map); + load_delta = physaddr - _text_offset; /* Is the address not 2M aligned? */ if (load_delta & ~PMD_PAGE_MASK)