Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3855641imm; Tue, 29 May 2018 15:21:20 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLyAuhXZu15n58rIdcopL/eURp4R5eUOTA757W/ztS7t7Z24nZuZcld++sIcn4nQARnr8j9 X-Received: by 2002:a62:c11:: with SMTP id u17-v6mr235383pfi.60.1527632480624; Tue, 29 May 2018 15:21:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527632480; cv=none; d=google.com; s=arc-20160816; b=noY2dVrHjwDzatELNGlDkofu0FdaLjfjMIVpvdRifpxkj2Eo9BMjJY0mkKmEtgStk/ xRWpgxWnEZuNkLaYGXL3NjHdyvw8bfopTbydx0BOijdeu/jrVgM2Xw9A5QVkdeDdNDmp xoTIcNR7/wSS5HGTfFhH/CvWCcfKPhKrv6SkORZ31nut0f1KclSCsKAfkKYSUM1ng/ex pYzLl+J+w5YfxMbMn8+XVTzkUESfD70NiwhtnAvv0tMh39KLmafWn4iBM8T1+9uGJqXU HDUjn8IXzdezeP4qYVkYw11Cim8Jf9nhJqwCe29rYlihp5+RpJtgHcVAbKgX5bO8hn64 FFmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Nt2TYn1OyKFDLBMvCqCNyG8g5aCL0Kpp90dxSyap9CA=; b=DZJNKM1gO2QWuyfVX8XDb8E20zZRWt+1IcD5eXV+s5j3MypGH+KaFMSl0q4gyIPNwg iBwlLxNZ+Et9T1hciC5UM81yAzv/9WNxjI8OJKia9JVVkrc57MaxAWypKhnBumeSFaX5 R+Tu0LAp285bOfvSMo0OS55tlBWVp3FNOjVZ+wCGAs0OVCPwk2bcSKWGtWHdvUbS7X72 lg9SCQECdKJbchOoOerPragxMvER9zWecWPCayxtNMZSk2ez4lHeZDgK39Sa2GLV9AII Pa11SVbW4XcmdEH6W3rsG1xmda8fHrRTfg5upaRG84JIB6rpsQiN2h+43S9P0IwZC/ye Da7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=irlsadii; 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 k134-v6si4777920pga.149.2018.05.29.15.21.06; Tue, 29 May 2018 15:21:20 -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=irlsadii; 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 S968172AbeE2WSI (ORCPT + 99 others); Tue, 29 May 2018 18:18:08 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:35036 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968083AbeE2WRk (ORCPT ); Tue, 29 May 2018 18:17:40 -0400 Received: by mail-pf0-f194.google.com with SMTP id x9-v6so7949555pfm.2 for ; Tue, 29 May 2018 15:17:40 -0700 (PDT) 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=uk5xPQSZO8yY6SbV238l/uvwvsJn/rktNfljQT7Hxulo2Gyf0t8e2PjIQHqAplJ15p WoND4uqf5V0jpcPRpwuo1PbUR25qv/8OfDGBJ15TEQEmPbT3X6AcEzD18Nw1HvgVB9g/ L6CRUXWYxTgwFIgjo0Sa5hFgfvdS20CWuYMrf4S/cMH0GGab0lq9Jfpy/JpSgRC1AzuP DsR1foptbeask+EZW22f8pQ+Kh5lpGoOepLfVQ4RG3DH0OLsHS7U4LAOr2RgIJXpUHZR jro5TQG9Pm0InbcCTLV3FlE10SZdHzJpQ9M8QKFjorQp6QMfxeLucJJPXTR5S/y/Zd5k gsqA== X-Gm-Message-State: ALKqPwe/7iQ4zwhF+jCksZ5Id4SHAWPpzznC+lcioufmqjQfpUGqrM4K 9U3pR/G3USRdRn5CgcA0vWfL7g== X-Received: by 2002:a62:e710:: with SMTP id s16-v6mr185584pfh.227.1527632259427; Tue, 29 May 2018 15:17:39 -0700 (PDT) Received: from skynet.sea.corp.google.com ([2620:15c:17:4:29de:3bb1:1270:e679]) by smtp.gmail.com with ESMTPSA id o84-v6sm78767935pfi.27.2018.05.29.15.17.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 May 2018 15:17:38 -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> 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 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) -- 2.17.0.921.gf22659ad46-goog