From patchwork Wed Oct 11 20:30:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 10000547 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 7F8AE6037F for ; Wed, 11 Oct 2017 20:33:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 742EC28B37 for ; Wed, 11 Oct 2017 20:33:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6782E28B6A; Wed, 11 Oct 2017 20:33:19 +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 377EA28B37 for ; Wed, 11 Oct 2017 20:33:17 +0000 (UTC) Received: (qmail 14222 invoked by uid 550); 11 Oct 2017 20:31:30 -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 14135 invoked from network); 11 Oct 2017 20:31:28 -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=3uOmiI/axdNlOpH2ZSDAGunl+iOqbLNzf9TymuS4Tnc=; b=NwrIqW+/avjPH22JCMTKZH7mZgwo5PNJpUMP1RE/0TNdwQ9uokCKC/ZqK83Z+QyMFD v7wbUrl4DbnvgTKZrzAlwyuKNHN0eOvHeUxgocFnOrk6iMGxVFfaeoSWZEMzDg3XNiCF eyng/PPsXTtgUSMgpfKEiK01vcqtJqnNtrNcbbFatrWtvwlz6Q8mjCUkfIKidY1iXWDO 2qQ2BrPsKYn7tsRY04kiKd1+QjW/s3u8xmkqvs1nGz663lqqIaewxECmj0pAPwzco/aN vIa/RFK77vhwAJpEum1P/2a1ED0MeJhcqaxxo4qNF9LPG3QKKn4gJUBO2KPTqczkByON JzoA== 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=3uOmiI/axdNlOpH2ZSDAGunl+iOqbLNzf9TymuS4Tnc=; b=MwITPU0mATeo7XleiVg/9ejskgxdFVCeGoUEgTwCXxK+kIWxih+sXB6yyQ80MAM8zx 0KQnOmUd9vzz8kTTe3uaulY96bnRNv9j59DhEZaMrP+hFKddWD1jFz6ILXOZrCIB8375 efTPlvgz5JjE+kckE5zgU58Aommy5oIgF1LsHurs0zAfTX5a84NkXIcP4r8zfmrnqZjO ElHCHor8Ay8JdcnP6kq0Z9Cy9MdgFk6Xah4L/PXnsE+gjHq8L53vVHR8ttLtiarHB52M a2PPS0JBZc5f8tgAqxUTyuPCDU+qXeZ9lJ34X9glAaFns2yzmdAaU5/ZEcmFHpigjkhj teOg== X-Gm-Message-State: AMCzsaUaE9vwCabJBRiwbd71gJzbY5We1LchDFJnUtBzMEQVhs0GSn+3 P8xfxB+z13uSoZqL8WZF9+W2Lw== X-Google-Smtp-Source: AOwi7QAkz3Ih+xV50/Op8JsW3KSJvrZSu3M1EwnwUc8XERdThZt1Va1o4O70ZH90vUXJBVGB0D8Hrg== X-Received: by 10.98.78.202 with SMTP id c193mr162522pfb.295.1507753876331; Wed, 11 Oct 2017 13:31:16 -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 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, 11 Oct 2017 13:30:08 -0700 Message-Id: <20171011203027.11248-9-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> Subject: [kernel-hardening] [PATCH v1 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 }