From patchwork Wed May 23 19:54:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 10422267 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 5511960224 for ; Wed, 23 May 2018 19:57:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43560291D5 for ; Wed, 23 May 2018 19:57:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 373D3291D6; Wed, 23 May 2018 19:57:46 +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=-12.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, USER_IN_DEF_DKIM_WL 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 3251A291DA for ; Wed, 23 May 2018 19:57:44 +0000 (UTC) Received: (qmail 23582 invoked by uid 550); 23 May 2018 19:55:35 -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 22447 invoked from network); 23 May 2018 19:55:29 -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=Pf68dfXa+B/GiZdRwKUBHs8dnRUioU0sT3PhnCrGBuk=; b=hDEQ4p47W8oHjmDwdpqJ10Mx96onFeKuD907tCal8l4rNFD6hB44SGmZE4D8jt3SOv B+Dbv7YSDtSMMG0/XRoyp7Fou7uAi/uvaLByY6U65uKt/sVuhL5XmKkmpf80ignvD1S1 CK5hkyh1pF5dESILbz3cYUCSXVn9htZVAhrsrmZtj1MO0KxSR1wsrWiYQaRCaiJ4FREG xwOmmGpBbwkod06nFTwy0DXwY0X90sq4eZMfNnK6nqAO5Mh7Mu4Dvsjrnop9G1rWpmwh +MBI7sgkXlTH5bkK3WjIRlYEg9+cAke3HBp/yeQdfY1sYCnwrDpIwawmXThyc8OxbBAV WvTQ== 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=Pf68dfXa+B/GiZdRwKUBHs8dnRUioU0sT3PhnCrGBuk=; b=SHzCVr/+d0gZ5trz1wEagZfcWRHcjV6AmbQDRuWM3kYxN+APAo/PNBAhljVN1LuKok Tfkc2OR0qW4wTtJQ/7/rdFPWMf7e/aHl8DtwbSNBm1ad20Wuc4uc/28CyxmsK20PNtBG PpPNs6Hegr0EGgAwduONMyJyKlurYx7tCecKY5cXtwOISmwH8uMNzkp+YJ3KkA/N4dVf ZKYa/+18UNaOuAksTp+AFCGbjIjZvHymtgugB/wi8C3RrNFXgNs+RYHkhIEiEEcfMVMm JwO/Z5IXxIzbmH+rbwSYaeH25uGrZYi3dTaWlZ5EnVOArWblwZJYSClXjXwyeqE1mXZe Lpsg== X-Gm-Message-State: ALKqPwcrtopUBkYvGgyb5Z8jQzd547H6qL3DYhyX1EBiwB8j89idHoQS Rd91REl+Zsceb0mj4UwExSKacg== X-Google-Smtp-Source: AB8JxZrMqoEu1WYJg7RfTLoIwRH//UKy8I0MztxinizTl2TFvcqLwn49So6AckN/zZO/NFKNQLSTwg== X-Received: by 2002:a62:dfcd:: with SMTP id d74-v6mr4198791pfl.114.1527105316358; Wed, 23 May 2018 12:55:16 -0700 (PDT) From: Thomas Garnier To: Herbert Xu , "David S . Miller" , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Peter Zijlstra , Josh Poimboeuf , Greg Kroah-Hartman , Thomas Garnier , Philippe Ombredanne , Kate Stewart , Arnaldo Carvalho de Melo , Yonghong Song , Andrey Ryabinin , Kees Cook , Tom Lendacky , "Kirill A . Shutemov" , Andy Lutomirski , Dominik Brodowski , Borislav Petkov , Borislav Petkov , "Rafael J . Wysocki" , Len Brown , Pavel Machek , Juergen Gross , Alok Kataria , Steven Rostedt , Jan Kiszka , Tejun Heo , Christoph Lameter , Dennis Zhou , Boris Ostrovsky , Alexey Dobriyan , Masami Hiramatsu , Cao jin , Francis Deslauriers , "Paul E . McKenney" , Nicolas Pitre , Andrew Morton , Randy Dunlap , "Luis R . Rodriguez" , Arnd Bergmann , Christopher Li , Jason Baron , Mika Westerberg , Lukas Wunner , Dou Liyang , Sergey Senozhatsky , Petr Mladek , Masahiro Yamada , Ingo Molnar , Nicholas Piggin , "H . J . Lu" , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Joerg Roedel , David Woodhouse , Dave Hansen , Rik van Riel , Jia Zhang , Ricardo Neri , Jonathan Corbet , Jan Beulich , Matthias Kaehlcke , 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 Subject: [PATCH v3 08/27] x86/CPU: Adapt assembly for PIE support Date: Wed, 23 May 2018 12:54:02 -0700 Message-Id: <20180523195421.180248-9-thgarnie@google.com> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog In-Reply-To: <20180523195421.180248-1-thgarnie@google.com> References: <20180523195421.180248-1-thgarnie@google.com> X-Virus-Scanned: ClamAV using ClamSMTP Change the assembly code to use only relative references of symbols for the kernel to be PIE compatible. Use the new _ASM_MOVABS macro instead of the 'mov $symbol, %dst' construct. 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/include/asm/processor.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index c119d423eacb..81ae6877df29 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -50,7 +50,7 @@ static inline void *current_text_addr(void) { void *pc; - asm volatile("mov $1f, %0; 1:":"=r" (pc)); + asm volatile(_ASM_MOVABS " $1f, %0; 1:":"=r" (pc)); return pc; } @@ -718,6 +718,7 @@ static inline void sync_core(void) : ASM_CALL_CONSTRAINT : : "memory"); #else unsigned int tmp; + unsigned long tmp2; asm volatile ( UNWIND_HINT_SAVE @@ -728,11 +729,13 @@ static inline void sync_core(void) "pushfq\n\t" "mov %%cs, %0\n\t" "pushq %q0\n\t" - "pushq $1f\n\t" + "leaq 1f(%%rip), %1\n\t" + "pushq %1\n\t" "iretq\n\t" UNWIND_HINT_RESTORE "1:" - : "=&r" (tmp), ASM_CALL_CONSTRAINT : : "cc", "memory"); + : "=&r" (tmp), "=&r" (tmp2), ASM_CALL_CONSTRAINT + : : "cc", "memory"); #endif }