Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp4423534imm; Mon, 25 Jun 2018 15:43:34 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLJj9H40D4DYm+rCgFa3meIH36m2781RE5mF9FGBJD8f1n58qJKd3Rg+uKV5R9IS1G5iHNc X-Received: by 2002:a62:c20e:: with SMTP id l14-v6mr14878833pfg.185.1529966614679; Mon, 25 Jun 2018 15:43:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529966614; cv=none; d=google.com; s=arc-20160816; b=aDLj8EIX8tZRu0cxKTsNqlJmbsw4Ixbu7e7h8VPoJw993OSr3tbORqrlIkwHOmae8o 7lCB2NPwT16yr1olkCQ4mNLLWAQBwf9QaUJgJ7Msvhx7iw1dhLuZV35SExaKKqG5I/mX qswuXddpNGt09di3xsnGc0Fs133LcRleFl/eFyY7ATG3o3ih1qyMFqp2war9AzRTP+dj +1O6OEQW1GxfG+dBIWM3nNFkImVpd0W3qSLo340GSVS6474BvhEmSWx5KT7HPB8tsD2w CIr1DltRnUrcjzERoCcsTl3tJHfr6RJLhS3Tn7Xilu6Wl1hhiRE1A19wlkfmKF3A7UPg AN5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references:message-id :in-reply-to:date:mime-version:dkim-signature :arc-authentication-results; bh=di1a+2IpeHvGipVB0LNFKlY88ZP9mtPFk4hb1bdjJ3g=; b=QBqaOGn1LYSQPXjiZkM4s6PCtGo8NO4E2cTIvB6J+PjYP2zZ6GLPw5aaQLoUYJFjMq VSi3+/0bdWXnMygUb/w5cSzwGvUQEefSvGSCXwqyvVlgL9YYgcqTP6Q5XIQ5siVhgOFm RPUglGcK/SkXS+tkm5cgr2EFz5MxrAXyIOQjTBr91cex6AecC2sYKjoU9cDpj/2JRiY1 3vCDTUlc3lmuBvGomhiNQ0jiHLvaT1wWmHza2HPQTNfeHO4uEiwJxia8P4wV91YVwvI2 sPvfbjBBfR66P+T6+fgxuvX1431Tykpcq64CYDtL9XOuWfw6JFqJFyTAmDcPVr2Of726 icuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XFEwAkvd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z1-v6si52318plo.516.2018.06.25.15.43.20; Mon, 25 Jun 2018 15:43:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XFEwAkvd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934603AbeFYWmN (ORCPT + 99 others); Mon, 25 Jun 2018 18:42:13 -0400 Received: from mail-yb0-f201.google.com ([209.85.213.201]:55457 "EHLO mail-yb0-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934572AbeFYWmJ (ORCPT ); Mon, 25 Jun 2018 18:42:09 -0400 Received: by mail-yb0-f201.google.com with SMTP id y16-v6so2009482ybk.22 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=JguCdVr95Nk+1e2oI1y5if/mE0MJ973xrxe6Y9Hk+jXL9vwJ/SBZqnzSeipl+sArUj ZcPLJEQbiXDEXIn7QbGX8BjRbfLTUSSN65TKA1OccJ3BSVD4DgpoJpgFP/jPFwwNeITH CwR9t41TT3RDYWtljlon44o0q9DyNDp438gINqkuLT5KcZ41YvzAZiTfmWPemuYawYMI mbESYkNvWKQj/wm6B3mldq9KOtbuvqCXkNyn9LjIxJJ+IjcS2Hz/+pqBRY4MXb+6865U Yh6amv+V9F0TWntE15SA9A64x5ApEmQXwcjzpWANmrS4016y088RWNQ48ELRYEUntKvh 5uWw== X-Gm-Message-State: APt69E0sln2SnGK4WpztDJ19l4RDUYI2v7UxR7XyyhLRC3saxNd3r2nE HCd0xmL+KQD3Qf/MS5kdGuxVurLYJX1Eiw== 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) -- 2.18.0.rc2.346.g013aa6912e-goog