From patchwork Thu Aug 10 17:26:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9894353 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 4717D603B4 for ; Thu, 10 Aug 2017 17:29:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BE2C28A42 for ; Thu, 10 Aug 2017 17:29:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F43328A93; Thu, 10 Aug 2017 17:29:28 +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 53C8628A42 for ; Thu, 10 Aug 2017 17:29:27 +0000 (UTC) Received: (qmail 1376 invoked by uid 550); 10 Aug 2017 17:27:15 -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 32649 invoked from network); 10 Aug 2017 17:27:09 -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=Zli9/SXT1UdthmGduQUpx2eVK+1laHeC2UX0z3RFvbM=; b=MRwzC6uVrS1GcpfhCSVA2GnHeiej6GXDzKXdsVk+zaOLl9r2/XgtHIy8qRxsAws8t9 GGKjIFw6AttiLDJMm8toiBqYNiUWBkBzWLd+S7aiwQSEJ1kN4zMI43Ei4DBPDo66a1x0 BSrS8TCRsHvSLRqZTlF59ayjwGdN7LapsKTdoD8OmbgTuy2BO+xrd2ajKgTptkgA50j3 EjG/Gtp/xnFhxrLKJROlpUgMTR3sb91sEzoDGPfThulXMlIS5yebrcDV0C2gzfY08Kiv VhCMgiyLHigd+uVLbJKZrbb6gZJCMg3Q4rW3GzqQGgh5ioXK2/ukP4LRR8K1PWGf+AbI 89Aw== 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=Zli9/SXT1UdthmGduQUpx2eVK+1laHeC2UX0z3RFvbM=; b=Byf42E/v4/a5a9VL1XvhdFR4gBV+EB9plv9E66EJFIcFBU2gGWcwxiTT8iGsDvNtE8 LQHgFRdtHmM2oUuhQPtM5OBuHHNgvF/OHL917y94njoZPU24xrb28b8luuf9izVi1x5G ZZaXMao6D4SzviHBXbL49/MBkrAZfMFLZH+wmXNJK4g8C9nsJZgt2F7AixAnhdYqV1qb FLbeQARv3FlMvI8ivOpr1mggcuIfdyeaHZWJcN3iLD0gjOD5BDiZC4t0SVMUsnwmwC2t iDBhhQOYJCj/jfyL9Sa69IDddRuA77JPe+h8jXiHo9ojrar/nBDuUm/wqs5pg3Kk6CxT dGTw== X-Gm-Message-State: AHYfb5hHbFOwCFFDqYoH0qhhuSwIrzxLBMa/VcLgGaHH1+nRdFBtL9C2 V/UK2NY93mFnZTKt X-Received: by 10.84.224.134 with SMTP id s6mr14489609plj.4.1502386017745; Thu, 10 Aug 2017 10:26:57 -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 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: Thu, 10 Aug 2017 10:26:02 -0700 Message-Id: <20170810172615.51965-11-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> Subject: [kernel-hardening] [RFC v2 10/23] 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 c1352771b2f6..14fc21e2df08 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -49,7 +49,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; } @@ -689,6 +689,7 @@ static inline void sync_core(void) : "+r" (__sp) : : "memory"); #else unsigned int tmp; + unsigned long tmp2; asm volatile ( UNWIND_HINT_SAVE @@ -699,11 +700,12 @@ 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), "+r" (__sp) : : "cc", "memory"); + : "=&r" (tmp), "=&r" (tmp2), "+r" (__sp) : : "cc", "memory"); #endif }