Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp179955imm; Fri, 5 Oct 2018 01:50:46 -0700 (PDT) X-Google-Smtp-Source: ACcGV62EdFa7lPyCIOVXyCJVNEI5VWn8h9PcNFpJLnBMrCSUm++42YSq/a71K1w399SNmmjfs4X2 X-Received: by 2002:a63:4384:: with SMTP id q126-v6mr9299057pga.142.1538729446164; Fri, 05 Oct 2018 01:50:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538729446; cv=none; d=google.com; s=arc-20160816; b=tmX1PcG/4I7zLUBeO6L2ZNcLsZKJ6nfdUDf61aERfv8B05yRRvndGeoeGeVsJ0wALR GA7BudE29spyEcsaRhIhUYLuzga9NtmduP6mbGSV+o4cq8oOGB9mklAHgka1kYVFheqe hoCrE3aqzQN8NaZCCvZpbRkEeexS3NaQq6b5zHRTJas9jdfHo8oNbyqb4GZySZvTjq8i TsiUb/4xXKTihwxKKNRo8V2cZKy8B0YslMZRyRHuAaPNlhhPSHEqpI0TNreSgo++vZHo flg7c+ovCzO61uhayOG3DrZgjcetu0vPYbeuhsVX1qnI8gXa91lY0UqSq5NiEO0a+Rim qMKg== 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; bh=oNQtS8+KLFtk1Pmuh9ViExtIRHM/mn8hhkAacpYibjg=; b=M+2/0lnnwhGdjmU9DScmSJuIXVFNwQ6y2YJj71Csshq+rTApLAJZyjY9BJZIU25/Lb c6mLDJqdYEvJPNjjYESyFIMTzkuoHrpFRICrr2faixKt5Hm2bgvdlOYmaLEYgAsmXmAb 2bqIIgokgVDoJFVzqE8RehyvkAxTyNLJhvfww6AfJKEzMxHdAzXLmcu83QlMEvR2LEqd R6bZOZGDOWdcAxt/GIxW+D9N+gNpkmPB4MJ2QCI1mhGUO0ysyuBi7dWLgL2o1WbDv6Xn 0/q2nA2I865Ty6llAkKoB2LwlNI8P0+r3UFo/7RDbdznKjUN+O+6UOmE6g/27qMwezOH atXw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 129-v6si7505242pgj.283.2018.10.05.01.50.30; Fri, 05 Oct 2018 01:50:46 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728755AbeJEPrj (ORCPT + 99 others); Fri, 5 Oct 2018 11:47:39 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:47782 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728743AbeJEPri (ORCPT ); Fri, 5 Oct 2018 11:47:38 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 44E7615AD; Fri, 5 Oct 2018 01:49:54 -0700 (PDT) Received: from moonbear.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1051B3F5B3; Fri, 5 Oct 2018 01:49:50 -0700 (PDT) From: Kristina Martsenko To: linux-arm-kernel@lists.infradead.org Cc: Adam Wallis , Amit Kachhap , Andrew Jones , Ard Biesheuvel , Arnd Bergmann , Catalin Marinas , Christoffer Dall , Dave P Martin , Jacob Bramley , Kees Cook , Marc Zyngier , Mark Rutland , Ramana Radhakrishnan , "Suzuki K . Poulose" , Will Deacon , kvmarm@lists.cs.columbia.edu, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 03/17] arm64/kvm: hide ptrauth from guests Date: Fri, 5 Oct 2018 09:47:40 +0100 Message-Id: <20181005084754.20950-4-kristina.martsenko@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181005084754.20950-1-kristina.martsenko@arm.com> References: <20181005084754.20950-1-kristina.martsenko@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Rutland In subsequent patches we're going to expose ptrauth to the host kernel and userspace, but things are a bit trickier for guest kernels. For the time being, let's hide ptrauth from KVM guests. Regardless of how well-behaved the guest kernel is, guest userspace could attempt to use ptrauth instructions, triggering a trap to EL2, resulting in noise from kvm_handle_unknown_ec(). So let's write up a handler for the PAC trap, which silently injects an UNDEF into the guest, as if the feature were really missing. Signed-off-by: Mark Rutland [kristina: fix comment] Signed-off-by: Kristina Martsenko Reviewed-by: Andrew Jones Reviewed-by: Christoffer Dall Cc: Marc Zyngier Cc: kvmarm@lists.cs.columbia.edu --- arch/arm64/kvm/handle_exit.c | 18 ++++++++++++++++++ arch/arm64/kvm/sys_regs.c | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index e5e741bfffe1..53759b3c165d 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -173,6 +173,23 @@ static int handle_sve(struct kvm_vcpu *vcpu, struct kvm_run *run) return 1; } +/* + * Guest usage of a ptrauth instruction (which the guest EL1 did not turn into + * a NOP). + */ +static int kvm_handle_ptrauth(struct kvm_vcpu *vcpu, struct kvm_run *run) +{ + /* + * We don't currently support ptrauth in a guest, and we mask the ID + * registers to prevent well-behaved guests from trying to make use of + * it. + * + * Inject an UNDEF, as if the feature really isn't present. + */ + kvm_inject_undefined(vcpu); + return 1; +} + static exit_handle_fn arm_exit_handlers[] = { [0 ... ESR_ELx_EC_MAX] = kvm_handle_unknown_ec, [ESR_ELx_EC_WFx] = kvm_handle_wfx, @@ -195,6 +212,7 @@ static exit_handle_fn arm_exit_handlers[] = { [ESR_ELx_EC_BKPT32] = kvm_handle_guest_debug, [ESR_ELx_EC_BRK64] = kvm_handle_guest_debug, [ESR_ELx_EC_FP_ASIMD] = handle_no_fpsimd, + [ESR_ELx_EC_PAC] = kvm_handle_ptrauth, }; static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 22fbbdbece3c..1ca592d38c3c 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1040,6 +1040,14 @@ static u64 read_id_reg(struct sys_reg_desc const *r, bool raz) kvm_debug("SVE unsupported for guests, suppressing\n"); val &= ~(0xfUL << ID_AA64PFR0_SVE_SHIFT); + } else if (id == SYS_ID_AA64ISAR1_EL1) { + const u64 ptrauth_mask = (0xfUL << ID_AA64ISAR1_APA_SHIFT) | + (0xfUL << ID_AA64ISAR1_API_SHIFT) | + (0xfUL << ID_AA64ISAR1_GPA_SHIFT) | + (0xfUL << ID_AA64ISAR1_GPI_SHIFT); + if (val & ptrauth_mask) + kvm_debug("ptrauth unsupported for guests, suppressing\n"); + val &= ~ptrauth_mask; } else if (id == SYS_ID_AA64MMFR1_EL1) { if (val & (0xfUL << ID_AA64MMFR1_LOR_SHIFT)) kvm_debug("LORegions unsupported for guests, suppressing\n"); -- 2.11.0