From patchwork Tue May 29 22:15:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 10437323 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 2FDB0601E9 for ; Tue, 29 May 2018 22:22:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17ED9287D2 for ; Tue, 29 May 2018 22:22:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B46528900; Tue, 29 May 2018 22:22:00 +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 2331528927 for ; Tue, 29 May 2018 22:21:58 +0000 (UTC) Received: (qmail 19691 invoked by uid 550); 29 May 2018 22:17:58 -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 19575 invoked from network); 29 May 2018 22:17:52 -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=Nt2TYn1OyKFDLBMvCqCNyG8g5aCL0Kpp90dxSyap9CA=; b=irlsadiihNmbrpogQFpsGMI8Ra9YnuIuEwD/Y3XAyGiv/bmi51KGGaPSc18sKEO0Ww uRbGyLMBY32gZW/7z2NdrRmYb5yz+uzx2XTWdRD5ek3U9S8J5xml0JKBW72Jp7HrHkPF 0st1aJMeHbCwQCAW57vxgorUycbWtY7c0NtDecU4fYHhHJMZiKu85C79Oo2GSVMBxlXx eMHZ3YzJnXRPY1Zr20aKKyk4Qb8rWTjeUmogt1dc1hSz3NFcgJLMMx20ucOIeiV74c05 kCO84zzal3eFwD9LetQhjrgb7st4G5Z816ANOxsCxuH1QDdb0ILXkeU1Boi6pPVR2iJN gpvA== 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=Nt2TYn1OyKFDLBMvCqCNyG8g5aCL0Kpp90dxSyap9CA=; b=aRSmFv4+0sHYxlnHn7oRAY5AXHHjCC1g3N1Os4UgiP6erqms+TatV7gjlW+og0PHEy /jSQi485atjoGkVOun6rDMSrk1/4V4K3V5RCdL7zS/Fm+3dGSgW/rxpxgB/nLHMYpRlJ cRZe2DT8gwL8gfn7tNhn9CmmXjr9/qtKNo6qQiAQOwpXjByH8Uowe/cXtK7ehPvTZUl6 VUULaSixxnJGaj3F/8SQ4Grn76tv6j0JeQrKBXf/AVW1Euk3kLBbqxEhdKPOiKfPBtet NcI3gnnkdjsyxkuEcMkImB+kULwzJxpOlo2wXTKjptVYGdqa+ewFDUzaVBVrZo7djfJk ulNQ== X-Gm-Message-State: ALKqPwc6c9wnevq4Cvmqxu6XvNpsv2FrmgEVDDFl2DEiDyBv0ouH7H/4 8TN8pOnl3XaROgZxs8250ossnybIeUU= X-Google-Smtp-Source: ADUXVKIoSh1i1WIZkORRpN/RzayD9GIHV8SOmq7PkftI6+8lNqi0/8DIwNL9GZ/Tem8b8CtkhIVpXg== X-Received: by 2002:a62:e710:: with SMTP id s16-v6mr185584pfh.227.1527632259427; Tue, 29 May 2018 15:17:39 -0700 (PDT) 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 Subject: [PATCH v4 19/27] kvm: Adapt assembly for PIE support Date: Tue, 29 May 2018 15:15:20 -0700 Message-Id: <20180529221625.33541-20-thgarnie@google.com> X-Mailer: git-send-email 2.17.0.921.gf22659ad46-goog In-Reply-To: <20180529221625.33541-1-thgarnie@google.com> References: <20180529221625.33541-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. 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 130874077c93..6afb2161263d 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1389,9 +1389,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 5b2300b818af..38716c409a98 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 b2e7140f23ea..bf09d1993d8d 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)