Received: by 10.223.185.116 with SMTP id b49csp730056wrg; Fri, 16 Feb 2018 06:20:28 -0800 (PST) X-Google-Smtp-Source: AH8x224K07mNvj9yK9IjC6w7bQxpvGnJQh7pkjaw43sDav0qhcUwnojtz8BEixu0NcFE6A0KPOOL X-Received: by 10.167.130.193 with SMTP id f1mr6169231pfn.241.1518790827952; Fri, 16 Feb 2018 06:20:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518790827; cv=none; d=google.com; s=arc-20160816; b=NJVl+rD7L6ognUdYW+Zav9DYfMhdlKPkiYWGQkmLTX+PUxscCicLDX3iU0T97bSoww LaXIA6PqaJqkdLpcdpPQl+puniQ4LGDm0qc7mBFxgjQ4npbfO0zIhbceH4o5KnT6AaW+ zPztIaNaz0Sf3rGRNq+OIYxljDRW6MYX6NJbXYE9Ek7BymG3/w+Zz9WSVI6MkGu5s3gU zXU+5b37WODWke9nsyLdLtdcdyrqY3YjvJAwkE9kFstVbhuoMEIAzVoa6DU3vs39iLr9 D7SEIQT1H0KhFG37/IeUJNFZz+9LziUbQIXrMU2ei88d4WigShqHwBaxl+7AqszNnO6Q 94SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=yNf7Ki32lEcpo5VD6jK36y7l8ydi+53aJrNAzF/+yRU=; b=wOWKgSZpeQcGC6PWDDUy8scU84zeD2Y3X78IFVwqHoChqttSE3RNZnGZdMvnH4x8IO WLVkEs9HQ/3lgUBBD1JdmGmQNBNQC1RVNPKp67qJtqgJDSLfRKEJNOCQZcPwIX3hlafD y/HUzWjxF60CmyQ1J9GJi9s23BPbxZ1i507CsDwxReEwjsTWR3xCD09Fmwxu56hXo4C6 lv939jewwVFI9X/roliHHYQv0E0JVVTpeBeIS+QDD+AffgagPxHu1ZPZJaNzqtLq0Hvn tHAHRkrOIQCx6okCswlLzlsB/Cr3pWXYfuZsUOl1hXefd4ZbPX0EEWwPJ6boi/gbu9X1 BrgQ== 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 y10si1170568pgp.405.2018.02.16.06.20.13; Fri, 16 Feb 2018 06:20:27 -0800 (PST) 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 S1167033AbeBOS6P (ORCPT + 99 others); Thu, 15 Feb 2018 13:58:15 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:48028 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033864AbeBOPTq (ORCPT ); Thu, 15 Feb 2018 10:19:46 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id ED3301098; Thu, 15 Feb 2018 15:19:45 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ard Biesheuvel , Marc Zyngier , Catalin Marinas Subject: [PATCH 3.18 34/45] arm: KVM: Fix SMCCC handling of unimplemented SMC/HVC calls Date: Thu, 15 Feb 2018 16:17:25 +0100 Message-Id: <20180215144123.189399417@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215144115.863307741@linuxfoundation.org> References: <20180215144115.863307741@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 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 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Marc Zyngier commit 20e8175d246e9f9deb377f2784b3e7dfb2ad3e86 upstream. KVM doesn't follow the SMCCC when it comes to unimplemented calls, and inject an UNDEF instead of returning an error. Since firmware calls are now used for security mitigation, they are becoming more common, and the undef is counter productive. Instead, let's follow the SMCCC which states that -1 must be returned to the caller when getting an unknown function number. Tested-by: Ard Biesheuvel Signed-off-by: Marc Zyngier Signed-off-by: Catalin Marinas Signed-off-by: Greg Kroah-Hartman --- arch/arm/kvm/handle_exit.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) --- a/arch/arm/kvm/handle_exit.c +++ b/arch/arm/kvm/handle_exit.c @@ -45,7 +45,7 @@ static int handle_hvc(struct kvm_vcpu *v ret = kvm_psci_call(vcpu); if (ret < 0) { - kvm_inject_undefined(vcpu); + vcpu_set_reg(vcpu, 0, ~0UL); return 1; } @@ -54,7 +54,16 @@ static int handle_hvc(struct kvm_vcpu *v static int handle_smc(struct kvm_vcpu *vcpu, struct kvm_run *run) { - kvm_inject_undefined(vcpu); + /* + * "If an SMC instruction executed at Non-secure EL1 is + * trapped to EL2 because HCR_EL2.TSC is 1, the exception is a + * Trap exception, not a Secure Monitor Call exception [...]" + * + * We need to advance the PC after the trap, as it would + * otherwise return to the same address... + */ + vcpu_set_reg(vcpu, 0, ~0UL); + kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); return 1; }