From patchwork Tue Mar 13 20:59:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 10280773 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 D98A3602C2 for ; Tue, 13 Mar 2018 21:03:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAB7D284AA for ; Tue, 13 Mar 2018 21:03:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE239284BD; Tue, 13 Mar 2018 21:03:09 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_MED 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 B8293284AA for ; Tue, 13 Mar 2018 21:03:08 +0000 (UTC) Received: (qmail 20311 invoked by uid 550); 13 Mar 2018 21:00:46 -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 20177 invoked from network); 13 Mar 2018 21:00:40 -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=+5M2FaP3vfmPSEGTB3GVETrTQCHNNxealc15RUl+u6U=; b=Z5TtevK5XG0x6wkFteUpHAx39pjzD8QZZdLS8jMEIqqFP/RtKUbS3TKg8lmOfcTNpi cocOvUZgRKVHoyhYUKezWrLNa7eneNjOkggmi1JHPTtB3HVLuVuVia/e2p3hmdKrll9z 4liV4wk7pumHm3LOO1ecAXe6gnxb9cXDaXXeRyE4VvjZ7BxcNXSmQA1zYmV2oqjTRhgv mkaLN0irAXt6ST6flalWs40p2T6AL37yIAVUkV/+CKemlrz7qNcyWAGbLhwvsnoWA42c 0EbzGjz73RGRtgCbsDF/Y/3rKN/CtHfK4tJUd9MW4KMDhbBWmM0KNQ+cV9KJUhxHqxFe 8l/Q== 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=+5M2FaP3vfmPSEGTB3GVETrTQCHNNxealc15RUl+u6U=; b=AOTUenwA7DiAMeCpNU4aXY/v1t+fgjmbsRQCaALo8EE4If4rFq/y5C14z0G1gIOaGk RAQ7wZahhSfFXRyiG5tqieDFy31LtB8o8XDIgjbXNi10oqd5y6u4d0XU33ywhUVtIEbx qo7WASzu3e9wC4zGdWddevMbZQHihDyWuOW28z0Asv+N3mrxsASA9Ik7b1lAbTTmOyY3 O2EZXN0uh0hAOAFvFKINOj0BZ29uuWBshUIilKo9N5p+BztSLvtXh3EvGE55Andk925W cte4BYANakt0Wr+awie2a3fqmOjz/DubKRvfc5n5mIsbpVrx8OFCBv2urK3TsoRdrErT nH5Q== X-Gm-Message-State: AElRT7FNeS1Oz0TUqObeE08bD25LiEWzN9thFBUkWbJshZQBXgLzgsWv gGGCUWinOfRIXh9HzNWINtPiEg== X-Google-Smtp-Source: AG47ELuRdmqXLGKKl1PC4PR7zPkPKPxpWZW8c5JHEqNEEob2ZgBQfHXwfDsf2VSvQbsLF6GTrYMnjg== X-Received: by 2002:a17:902:ab93:: with SMTP id f19-v6mr1830954plr.180.1520974828020; Tue, 13 Mar 2018 14:00:28 -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 , Kate Stewart , Thomas Garnier , Arnd Bergmann , Philippe Ombredanne , Arnaldo Carvalho de Melo , Andrey Ryabinin , Matthias Kaehlcke , 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 , Tejun Heo , Christoph Lameter , Dennis Zhou , Boris Ostrovsky , David Woodhouse , Alexey Dobriyan , "Paul E . McKenney" , Andrew Morton , Nicolas Pitre , Randy Dunlap , "Luis R . Rodriguez" , Christopher Li , Jason Baron , Ashish Kalra , Kyle McMartin , Dou Liyang , Lukas Wunner , Petr Mladek , Sergey Senozhatsky , Masahiro Yamada , Ingo Molnar , Nicholas Piggin , Cao jin , "H . J . Lu" , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Joerg Roedel , Dave Hansen , Rik van Riel , Jia Zhang , Jiri Slaby , Kyle Huey , Jonathan Corbet , Matthew Wilcox , Michal Hocko , Rob Landley , Baoquan He , Daniel Micay , =?UTF-8?q?Jan=20H=20=2E=20Sch=C3=B6nherr?= 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 v2 08/27] x86/CPU: Adapt assembly for PIE support Date: Tue, 13 Mar 2018 13:59:26 -0700 Message-Id: <20180313205945.245105-9-thgarnie@google.com> X-Mailer: git-send-email 2.16.2.660.g709887971b-goog In-Reply-To: <20180313205945.245105-1-thgarnie@google.com> References: <20180313205945.245105-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 b0ccd4847a58..1b9488b1018a 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; } @@ -710,6 +710,7 @@ static inline void sync_core(void) : ASM_CALL_CONSTRAINT : : "memory"); #else unsigned int tmp; + unsigned long tmp2; asm volatile ( UNWIND_HINT_SAVE @@ -720,11 +721,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 }