From patchwork Wed Oct 4 21:19:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9985529 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 7285660586 for ; Wed, 4 Oct 2017 21:23:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62CA328C2C for ; Wed, 4 Oct 2017 21:23:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 56D1428C2F; Wed, 4 Oct 2017 21:23:07 +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 582BF28C2C for ; Wed, 4 Oct 2017 21:23:06 +0000 (UTC) Received: (qmail 15636 invoked by uid 550); 4 Oct 2017 21:21:16 -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 15476 invoked from network); 4 Oct 2017 21:21:11 -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=PCJKT4rjVH4EM4bq/0M1IWsxOAMYjKIEbfsGvIKF65M=; b=jlUNHGoM94FS6l6Y48w89nxNQg2adrhZU9qc3oE5+vWT+ZHFAknI4JpzpIVJ4MqpdA SBLcIfyN3M6pBoH3wdVyQ9xbbrfKsrmOJQFgjjnP1kyvCiQ+2iGfGh30SiNcQjC3gnQy dhdBMZM4S05Z3tHwcYyMc1VEG3iiq87Tjju3H6hl+lZXt0rMAVwniZh6dvCDCmOX9rdD KqG2wT3vW/i3h6WuOYNfxrSoWlTDU17CdoJEL85uY0JXLVilbWftHhyXvFggg8UMIcEB SBoLmXvFuUnjkNqXvHfgKAVLDoE8vLTkOFj7BBR9MaW44s2GjX7cvJPd9OQa7qt0Hl2z aANA== 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=PCJKT4rjVH4EM4bq/0M1IWsxOAMYjKIEbfsGvIKF65M=; b=m2YjdimECi8ZgfgCrDhtHQKBDuDpJ9KAvOKgfvCr+J+ppnz3YnNslQ7Qd3xmWgDx8Z YNweDKwDsi4+7xKVhRyiWmJJ1iA384vvO0KXIt67HMDDnhx3oqEbzu+oJ4GEsMa3FMl3 xLO61ElcyXPx44WYK1e7vW2jTQN+gMr21ZRqml7UjdDIgtF1tkKb5/PRstWnfsTxr+mJ VYY8KuXPmw7FWgRyHrv0ZH3tvsiKWnWHOf7FzLozP0ctPiV23eVFaLbkVKsBND9jvrE3 g1AQ6cG+cCNv+RKweLSwpiMAMg132Z/JgAMfME788nXI+mA4c8ZKKzhECThMukVz/EmF obdQ== X-Gm-Message-State: AHPjjUg6bDiNXjgSPqxGGzTCHD/SWqA0xDMcIsQBIpWGOgLhY0FUf/ZN I4dbbuS7t5YjskJz4DULPPYZgA== X-Google-Smtp-Source: AOwi7QAJAjcfTPDKhKVF7kIRCcl7mMqH0oPakFtaP4kyHPsJIMmhRJ2E7ApNNmQJtub8F4uv5Rrx+g== X-Received: by 10.98.112.68 with SMTP id l65mr21366539pfc.292.1507152059556; Wed, 04 Oct 2017 14:20:59 -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 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 Date: Wed, 4 Oct 2017 14:19:44 -0700 Message-Id: <20171004212003.28296-9-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> Subject: [kernel-hardening] [RFC v3 08/27] 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 | 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 b446c5a082ad..b09bd50b06c7 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; } @@ -695,6 +695,7 @@ static inline void sync_core(void) : ASM_CALL_CONSTRAINT : : "memory"); #else unsigned int tmp; + unsigned long tmp2; asm volatile ( UNWIND_HINT_SAVE @@ -705,11 +706,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 }