From patchwork Mon Jun 25 22:39:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 10487433 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 17489603B5 for ; Mon, 25 Jun 2018 22:42:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A9B02869D for ; Mon, 25 Jun 2018 22:42:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3523286B1; Mon, 25 Jun 2018 22:42:23 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97BB12869D for ; Mon, 25 Jun 2018 22:42:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934583AbeFYWmN (ORCPT ); Mon, 25 Jun 2018 18:42:13 -0400 Received: from mail-yb0-f202.google.com ([209.85.213.202]:50234 "EHLO mail-yb0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932351AbeFYWmJ (ORCPT ); Mon, 25 Jun 2018 18:42:09 -0400 Received: by mail-yb0-f202.google.com with SMTP id x13-v6so4190903ybl.17 for ; Mon, 25 Jun 2018 15:42:08 -0700 (PDT) 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=di1a+2IpeHvGipVB0LNFKlY88ZP9mtPFk4hb1bdjJ3g=; b=XFEwAkvdcDd+pTY2WvROAMghiTBxG57BlW5nss82QtKbp7E1LAtNGYODcOl55snyQW USJ95jbU45snVmet677M/BF8OWFmBCHxLwcmBEGrwKvTBp8U+ycdIMwgrZbPjyb5iRnp xDG3SP7aH1umnwtjmFgNCV0mM1AzR4OF5KjEiaBo1qGqlg8K1aA9rjLiAFaa8uguRKN8 QTmiHnV47JU4HRwxc3hjdmWX930eJNIcVge2bRA4KYbHnlEjrZ5HSFxra9eaDyBnaird /mpsKbrF6vJbNAej7N8YV7tTAF2eiLLCoIcmyOlRYSy5Sb4OfqpfGetjqEjOnS8ppV/s g0CQ== 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=di1a+2IpeHvGipVB0LNFKlY88ZP9mtPFk4hb1bdjJ3g=; b=Va5MTARBk0bd5JqIf2wnekAnBKnNubAzK5tAbQk/Rxj3k4ucROfIYyAxZOwPR4eAGu eyPaa+TxEmqJ3OA+2N5gA0ZdSvQnQUo5b9tdvbVP5idToTMhsuGAkw6jlkBRK4J3wJvp TUqYJF2pO/yboe7q9DlcjRinV3cLNsDEBQGg4YJyz1ei4drCz11hMzjedrf+uvETkE8l 13yTo1VbpLBi3vd4fuWBWXZOKJnuTU5sTyvyKv6l/vpId4YyVdhLE126l/P/GKuu/V4C cL7YztoAEYGTLadY3yYKW6Q5hQTBQ3weaQcW9tXizJbvM0zaIbwjuPRjYtVUuBw74jLn +OEA== X-Gm-Message-State: APt69E3x5SSsFC2QClckczZ+MY8Zog+vpVstkFsKD0LkbO7e5o5iJI8m GwIC/FGU1UEKjiNFIfDk2mAVGbkOuyseRA== X-Google-Smtp-Source: ADUXVKLzN1s8fYsNlgRqA0tF1PXlXiR8WocAmAa0gGKaY9LtWGM0+c679ifb6R2DwM8udHVkhXSRbscJM97x7A== MIME-Version: 1.0 X-Received: by 2002:a25:2e0c:: with SMTP id u12-v6mr3925175ybu.27.1529966528225; Mon, 25 Jun 2018 15:42:08 -0700 (PDT) Date: Mon, 25 Jun 2018 15:39:07 -0700 In-Reply-To: <20180625224014.134829-1-thgarnie@google.com> Message-Id: <20180625224014.134829-20-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 19/27] kvm: Adapt assembly for PIE support From: Thomas Garnier To: kernel-hardening@lists.openwall.com Cc: Thomas Garnier , Paolo Bonzini , "=?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?=" , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@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. The new __ASM_MOVABS macro is used to get the address of a symbol on both 32 and 64-bit with PIE support. Position Independent Executable (PIE) support will allow to extend the KASLR randomization range 0xffffffff80000000. Signed-off-by: Thomas Garnier --- arch/x86/include/asm/kvm_host.h | 8 ++++++-- arch/x86/kernel/kvm.c | 6 ++++-- arch/x86/kvm/svm.c | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index c13cd28d9d1b..27370f4917a4 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1390,9 +1390,13 @@ asmlinkage void kvm_spurious_fault(void); ".pushsection .fixup, \"ax\" \n" \ "667: \n\t" \ cleanup_insn "\n\t" \ - "cmpb $0, kvm_rebooting \n\t" \ + "cmpb $0, kvm_rebooting" __ASM_SEL(,(%%rip)) " \n\t" \ "jne 668b \n\t" \ - __ASM_SIZE(push) " $666b \n\t" \ + __ASM_SIZE(push) "$0 \n\t" \ + __ASM_SIZE(push) "%%" _ASM_AX " \n\t" \ + _ASM_MOVABS " $666b, %%" _ASM_AX "\n\t" \ + _ASM_MOV " %%" _ASM_AX ", " __ASM_SEL(4,8) "(%%" _ASM_SP ") \n\t" \ + __ASM_SIZE(pop) "%%" _ASM_AX " \n\t" \ "call kvm_spurious_fault \n\t" \ ".popsection \n\t" \ _ASM_EXTABLE(666b, 667b) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index a37bda38d205..761157c138c9 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -726,8 +726,10 @@ asm( ".global __raw_callee_save___kvm_vcpu_is_preempted;" ".type __raw_callee_save___kvm_vcpu_is_preempted, @function;" "__raw_callee_save___kvm_vcpu_is_preempted:" -"movq __per_cpu_offset(,%rdi,8), %rax;" -"cmpb $0, " __stringify(KVM_STEAL_TIME_preempted) "+steal_time(%rax);" +"leaq __per_cpu_offset(%rip), %rax;" +"movq (%rax,%rdi,8), %rax;" +"addq " __stringify(KVM_STEAL_TIME_preempted) "+steal_time(%rip), %rax;" +"cmpb $0, (%rax);" "setne %al;" "ret;" ".popsection"); diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index f059a73f0fd0..cb78647d6383 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -707,12 +707,12 @@ static u32 svm_msrpm_offset(u32 msr) static inline void clgi(void) { - asm volatile (__ex(SVM_CLGI)); + asm volatile (__ex(SVM_CLGI) : :); } static inline void stgi(void) { - asm volatile (__ex(SVM_STGI)); + asm volatile (__ex(SVM_STGI) : :); } static inline void invlpga(unsigned long addr, u32 asid)