From patchwork Tue Jul 18 22:33:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9850039 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 5ADE360392 for ; Tue, 18 Jul 2017 22:36:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46934285B7 for ; Tue, 18 Jul 2017 22:36:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39A91285CD; Tue, 18 Jul 2017 22:36:21 +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 6BC4C285B7 for ; Tue, 18 Jul 2017 22:36:20 +0000 (UTC) Received: (qmail 27800 invoked by uid 550); 18 Jul 2017 22:34:41 -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 26558 invoked from network); 18 Jul 2017 22:34:37 -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=iVsPDOvE/4mnM/CtOnJOylcb3dK/g+Y8XTzVwzqYYyY=; b=rGqLw0Zu31U1Fi+jIq4EqjosMuK/swb2ORNY9mXFb4vZJL18DqHyjVvzf9LRCet7wY zEujxE+ktMIvqUWxN//5Z7IAb1MI3fBujPaH7GL2YdsPI2YciCJYWLtNBOxvcB0KS15s nYf3PN5srJcq4i3yTxC5WxrelAz7143ftNCw3cqdTDJT/Z/XkqCwdSi546g1jiqQxGas 2oSP15jQMWMOT/0EQ7K0xsg/iCcI3dy9PJJIv8pUiGOwY3J3WO4ibbKhV8j4/akTtFO4 5Tz3G5jErJjyLZ1lrNVS9vf8Jr+2YPpbJ41Yf47MV4qTkmEUjltGJ9hqMpsWKV7ZZZik O26w== 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=iVsPDOvE/4mnM/CtOnJOylcb3dK/g+Y8XTzVwzqYYyY=; b=uMBUlk2Z82OY2gAvkJ2M2sQRzkcI3eCKI+kQKD+fYSc8V+S/17nQIzjoeVAwJ003PC VQWUv2+FdaGYiadof16Xey0mypbZk80YI+MiVGiW0QC09mKGSCzoXnJYodASQqILRfbk 1ropSJ0ZEpM2SZwG7nbhRbNqhKTNRXtm17hGbk2+jzgnk/b/6TqFOFG5NyNBQhClR6Ft SNr5+BODXdNdbU2p6bH9zaaOAb9pAQ2Vrbec/cMtYznwRoquTACKAMRp0bXXdtjTMiCI oNSlRB4IV5bVv4bSxgnAzbQbSnh009BsqtrQCrZoJ5djAWoHnpY3Vrk+7k2LNeaL3/xh 2C0g== X-Gm-Message-State: AIVw1125oCm0vkyV8nCdWaXkTLPoWpNEXdsCBWl/4i5y0yTvrWR40uFm NKgRXWf4043G959y X-Received: by 10.84.193.129 with SMTP id f1mr4102715pld.158.1500417265151; Tue, 18 Jul 2017 15:34:25 -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 , Matthias Kaehlcke , Boris Ostrovsky , Juergen Gross , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Joerg Roedel , Andy Lutomirski , Borislav Petkov , "Kirill A . Shutemov" , Brian Gerst , Borislav Petkov , Christian Borntraeger , "Rafael J . Wysocki" , Len Brown , Pavel Machek , Tejun Heo , Christoph Lameter , Kees Cook , Paul Gortmaker , Chris Metcalf , "Paul E . McKenney" , Andrew Morton , Christopher Li , Dou Liyang , Masahiro Yamada , Daniel Borkmann , Markus Trippelsdorf , Peter Foley , Steven Rostedt , Tim Chen , Ard Biesheuvel , Catalin Marinas , Matthew Wilcox , Michal Hocko , Rob Landley , Jiri Kosina , "H . J . Lu" , Paul Bolle , 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: Tue, 18 Jul 2017 15:33:21 -0700 Message-Id: <20170718223333.110371-11-thgarnie@google.com> X-Mailer: git-send-email 2.13.2.932.g7449e964c-goog In-Reply-To: <20170718223333.110371-1-thgarnie@google.com> References: <20170718223333.110371-1-thgarnie@google.com> Subject: [kernel-hardening] [RFC 10/22] x86/CPU: 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. Use the new _ASM_GET_PTR macro instead of the 'mov $symbol, %dst' construct to not have an absolute reference. 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 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index 028245e1c42b..1adea8c4436e 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -47,7 +47,7 @@ static inline void *current_text_addr(void) { void *pc; - asm volatile("mov $1f, %0; 1:":"=r" (pc)); + asm volatile(_ASM_GET_PTR(1f, %0) "; 1:":"=r" (pc)); return pc; } @@ -682,6 +682,7 @@ static inline void sync_core(void) : "+r" (__sp) : : "memory"); #else unsigned int tmp; + unsigned long tmp2; asm volatile ( "mov %%ss, %0\n\t" @@ -691,10 +692,11 @@ 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" "1:" - : "=&r" (tmp), "+r" (__sp) : : "cc", "memory"); + : "=&r" (tmp), "=&r" (tmp2), "+r" (__sp) : : "cc", "memory"); #endif }