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: 10488303 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 019CD602B3 for ; Tue, 26 Jun 2018 08:44:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E315D287E2 for ; Tue, 26 Jun 2018 08:44:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7C63287E7; Tue, 26 Jun 2018 08:44:03 +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 0CE0B287E2 for ; Tue, 26 Jun 2018 08:44:02 +0000 (UTC) Received: (qmail 28392 invoked by uid 550); 26 Jun 2018 08:39:55 -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 11992 invoked from network); 25 Jun 2018 22:42:19 -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=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=RV6nYFM86oIgW4xACdgdBtWKPu8WBA6OJYgneYVayE5F59iln7Oe9zVsQfZhVmlp7g ZdBkR432L7ihXoINPDHhLhICvyeB8EFAy+N6WX4183ur0F4MmJZcynNT/ef5Byx8C81t FxfMKzAaSOFu5qGsheVXlXL4Egs+MKvleUN1pnVdMcOsYiweMC4JE/4Y0cqecwwjCTGB 0KPaMEEo9oBJZ9/AYRijHCeaMf4wfEetQeoNWdMJZRQVJr2YeGiMUJ9Se0f42za+FzDS 1xnS7PfnWtGwGtdwe/M65KNiLmZRiTfqUhg8qXfDxR+sqzQYsC+GvtuB4kZFXDMUcFzZ swQA== X-Gm-Message-State: APt69E0qf/tnEP+h5a68WDePB8pVnTiowcjyCljS+D5nTjCjWC7k7Pc2 Fc5ZWEEr/1NztcMiNuhHAbbdiPMUHII8iwGY6a07NEXVtGzPpPI9Ob2H4ysNkhWq/5aPyfH8BNV uSCqNs1uR/BsJXNWgTkVZlfarM1BfNs+PzsJpXQXYVxg6DmqVuuj0BS7+q/T1ElYmkQdBC4jt9D tau1uZOVnx 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 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)