From patchwork Mon Jun 25 22:38:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 10488269 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 630BB602B3 for ; Tue, 26 Jun 2018 08:42:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 305AF28938 for ; Tue, 26 Jun 2018 08:42:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F1EE28800; Tue, 26 Jun 2018 08:41:47 +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=-12.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, USER_IN_DEF_DKIM_WL 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 C565A28A07 for ; Tue, 26 Jun 2018 08:41:13 +0000 (UTC) Received: (qmail 24384 invoked by uid 550); 26 Jun 2018 08:39:07 -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 Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 11309 invoked from network); 25 Jun 2018 22:41:32 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:in-reply-to:message-id:references:subject:from:to :cc; bh=D75bzu57Vb+Gc0Gy/OAz1HCmAwb32W6lqiuANod/EaU=; b=nTFep+/ODWuqgiYZs2NxMthfQltjLNJJqhsZ6YtZV2bVhdZ3qNx54YXAyvGQ7OzJ1X kNnI8Q1CBuaXBduBXB8U21AlIxEn6kHhZqR/6R9uww86qMpRlNaWsugAdJ0wVgj2uEDS 0CZzHhFmCpm+5daVPF3iXNVLh8AOGX5xj6h75jqy0ChFZZ/eGq7J2dXFvpdbDdZd4V3d zf8bRsi9tRsTu9VAjdDkoOk8gspUpotiVYAa4dEjX6C1waH+r8iz8GmCwbAZn7yP4Phk juAqcL7bc8/BP2Bf+MUFoUN3brInz0KLfTtXDEdvhLy3xrLv/usLe/84SinK1hYi5BB3 cAYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:in-reply-to:message-id :references:subject:from:to:cc; bh=D75bzu57Vb+Gc0Gy/OAz1HCmAwb32W6lqiuANod/EaU=; b=VLZG7yU+y4/TvTtg5qHbCJnOXUcy9mmq7QXaJqOCW3D2niqORODHbBjVNu4ITWOelF bXa7qCotwCGgtx0tI3V9uln33OBMfq91A6i8N+3Yr+WdX90xwmgJEGhwHjX7ARL+YfQp F6ZdVwE+uzAjXEbyuLu2+7LuIH7k+HS9xADxGwr0jEaJ36leF3w7sLP/rGviSYFuOGP1 jjg9XiDd+XUZghersdfcylDvYvgLqDUFQB/yXDE55DTHy4X8s8FZ/29oGVX+LBVEqiC7 KS2xZuhxLMK1iifXTPmXGbi6tHoK7EYiS0rRh21zrxHMLlfPg4IUaAkFol96rZwfd30g PdAQ== X-Gm-Message-State: APt69E0FJJC5bU6InbvQNwvqX+v6gCiZudDc7bItz6ANS+J/woiBx7sx xvhH2arIIeocM03KlywWaNdidFbAXFELFXQ7IyS0J5dC1ibC7R80s8KLy1BNVjOpVTSHhLybomE tOOHYCIDMDtMRYS8JzvdzMWxLYXew7hwdAkdsWGxUEMgL0AfY+6r5MDMiZi257Qd055ph7qM3qt FOT1R0RZRU X-Google-Smtp-Source: AAOMgpcQTfcZ30Vu91D/khdpDSy9W6riHjZbVBKvf9oIAD/DCju8oxcERdHxXZ8e7WSsxzij1P7EXWbc5txrIQ== MIME-Version: 1.0 X-Received: by 2002:a9d:4c13:: with SMTP id l19-v6mr6998073otf.68.1529966479864; Mon, 25 Jun 2018 15:41:19 -0700 (PDT) Date: Mon, 25 Jun 2018 15:38:56 -0700 In-Reply-To: <20180625224014.134829-1-thgarnie@google.com> Message-Id: <20180625224014.134829-9-thgarnie@google.com> References: <20180625224014.134829-1-thgarnie@google.com> X-Mailer: git-send-email 2.18.0.rc2.346.g013aa6912e-goog Subject: [PATCH v5 08/27] x86/CPU: Adapt assembly for PIE support From: Thomas Garnier To: kernel-hardening@lists.openwall.com Cc: Thomas Garnier , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Borislav Petkov , Andy Lutomirski , linux-kernel@vger.kernel.org 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 extend the KASLR randomization range 0xffffffff80000000. 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 cfd29ee8c3da..25b5842a4646 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; } @@ -711,6 +711,7 @@ static inline void sync_core(void) : ASM_CALL_CONSTRAINT : : "memory"); #else unsigned int tmp; + unsigned long tmp2; asm volatile ( UNWIND_HINT_SAVE @@ -721,11 +722,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 }