From patchwork Wed Oct 11 20:30:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 10000571 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 E792D6037F for ; Wed, 11 Oct 2017 20:33:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC4E228B37 for ; Wed, 11 Oct 2017 20:33:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFFD928B6A; Wed, 11 Oct 2017 20:33:39 +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 7022E28B37 for ; Wed, 11 Oct 2017 20:33:39 +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 1e2Nf9-0000aJ-1G; Wed, 11 Oct 2017 20:31:31 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2Nf7-0000Xv-2E for xen-devel@lists.xenproject.org; Wed, 11 Oct 2017 20:31:29 +0000 Received: from [193.109.254.147] by server-10.bemta-6.messagelabs.com id 73/87-07499-0AF7ED95; Wed, 11 Oct 2017 20:31:28 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrJIsWRWlGSWpSXmKPExsVyMfTAVt359fc iDWbclLb4vmUykwOjx+EPV1gCGKNYM/OS8isSWDN23XnLUjCTt+LpnitsDYxd3F2MXBxCAjMY Jdb0vGTpYuTkYBF4xSJx5Wc4SEJCoJ9V4u+OS2wgCQmBLInHj/sYIew0iSn32pkg7AqJGWuOs 4LYQgJKEls3LGWGmPqPUeLIt69gRWwCWhJ7GuYzgSREBE4IS2z68JsRxGEWOMMkcbzvJFi7sI CPRNejT2wQd6hKzDq3BOwmXgFLiXV3nzNDrLOQOHbsMFicEyj+feMhZojVFhIrZ51nncAouIC RYRWjenFqUVlqka6ZXlJRZnpGSW5iZo6uoYGZXm5qcXFiempOYlKxXnJ+7iZGYNAxAMEOxnkn /A8xSnIwKYnyPoy5FynEl5SfUpmRWJwRX1Sak1p8iFGGg0NJgnd6HVBOsCg1PbUiLTMHGP4wa QkOHiUR3iaQNG9xQWJucWY6ROoUoyXHhTuX/jBxHNhzC0h23Lz7h0mIJS8/L1VKnPchSIMASE NGaR7cOFiMXmKUlRLmZQQ6UIinILUoN7MEVf4VozgHo5Iw72GQKTyZeSVwW18BHcQEdJBo2h2 Qg0oSEVJSDYyXLsbeuGWxNmbTZwvnprdRF95zuFxiPKVrxqe9uZBF2utnRJdKxo2KaX/81d+3 HVY4rSaqvOam06cn/tvN74h+3L9y+5QShvnL+qeHF9dumcdzseJPTWPDPCnv77c2a8QInmZce jVMqWz6BuYrEv+yvQ+en2Ki9fLv1MsSy2eVMrLLGK9kPfVZiaU4I9FQi7moOBEATyh3kMwCAA A= X-Env-Sender: thgarnie@google.com X-Msg-Ref: server-4.tower-27.messagelabs.com!1507753886!110447234!1 X-Originating-IP: [209.85.192.181] 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 20739 invoked from network); 11 Oct 2017 20:31:27 -0000 Received: from mail-pf0-f181.google.com (HELO mail-pf0-f181.google.com) (209.85.192.181) by server-4.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 11 Oct 2017 20:31:27 -0000 Received: by mail-pf0-f181.google.com with SMTP id e64so1941464pfk.9 for ; Wed, 11 Oct 2017 13:31:27 -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=3Ft4Jh8g1gQFyUUcYublbR5eYiJL0UmIMd/NfUNtJQs=; b=Pj3Mui4uIXMR2rRzN0KyInO3hwMjpRcMrwt33LmWwxUz+CiOItvyTDGNoz9d9pGQC+ 7eBuoz3Ha69+dIiggXDQJjFhzdCYZC3937k/sCKAa0poFbvrEbJxjOwk56pz/b93zxW8 iImFwArFky6ALhCtLiKtc/hY8qhnyKRWgnIRph8M4VaKRm2DaUekoL74k1aCEPZTkJyQ u9yuXQ3r2Y2eVi/fqqcpUeZs4MyeN68Z1Gom76yIrH5Y/zj2nJAHiE1Kn+YfA9yXcQPX 70F3pj65I/uXZepfU8fRc3k/fbp3CECaDPXiTYbaDgHoJwaKF1i9eBhS08pG9YZvfD5c aGdg== 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=3Ft4Jh8g1gQFyUUcYublbR5eYiJL0UmIMd/NfUNtJQs=; b=cncCyEkiBx0pywnQCcFwkjsv0IMZK7aRhH4Av5mE0gkVjNlYKBfinkzM96qjwEQNOZ 5B1SaYkIraZCcGhpF7kovTmGncTFrT1ovbOKlnzLdppZPNRpEsGFqFdsP5b/wrRrTeUS KuNb3Iy9gfmimD0C3kih6J9MJWk5V0N6P9soyFBCPqyNRriFx7AgpGuRXmPjZubRZ2wI SCR7ENDOcFGjGPo40ww5zuHEgNtTK2wZUPtGlYeXNmG/zEG1U23h+eF5Ry8I42Ws4ZFH Opvld3TbRPFDY80BszoyectZitpGFWrF+uF5htXpIJ8zM3SHn5eUSaA4w9GRcciOrP90 pV/Q== X-Gm-Message-State: AMCzsaVg5iBumxFQJnvEAz+fv1KggZfL9nI3AEiM+mKGD3KsRjO+D3U1 Fn2+vuP1r7Az7x9cQ+55No7Apw== X-Google-Smtp-Source: AOwi7QBrGexlXWEm0meZycNITEryeyYk8fjcawESP+O5bt/pw0KC1uV7w+zRm4wMecXop1XRctzmBg== X-Received: by 10.84.134.164 with SMTP id 33mr161310plh.323.1507753884518; Wed, 11 Oct 2017 13:31:24 -0700 (PDT) Received: from skynet.sea.corp.google.com ([172.31.92.33]) by smtp.gmail.com with ESMTPSA id n12sm20691913pfb.149.2017.10.11.13.31.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Oct 2017 13:31:23 -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 , Kees Cook , Andrey Ryabinin , 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 , Paul Gortmaker , Andrew Morton , Alexey Dobriyan , "Paul E . McKenney" , Nicolas Pitre , Borislav Petkov , "Luis R . Rodriguez" , Greg Kroah-Hartman , Christopher Li , Steven Rostedt , Jason Baron , Mika Westerberg , Dou Liyang , "Rafael J . Wysocki" , 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 , Jonathan Corbet , Michal Hocko , Peter Foley , Paul Bolle , Jiri Kosina , "H . J . Lu" , Rob Landley , Baoquan He , =?UTF-8?q?Jan=20H=20=2E=20Sch=C3=B6nherr?= , Daniel Micay Date: Wed, 11 Oct 2017 13:30:13 -0700 Message-Id: <20171011203027.11248-14-thgarnie@google.com> X-Mailer: git-send-email 2.15.0.rc0.271.g36b669edcc-goog In-Reply-To: <20171011203027.11248-1-thgarnie@google.com> References: <20171011203027.11248-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] [PATCH v1 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)