Received: by 10.223.185.116 with SMTP id b49csp2163665wrg; Thu, 15 Feb 2018 07:29:38 -0800 (PST) X-Google-Smtp-Source: AH8x2246dXtaYoSV3oFOpAU/vHXgzXc/mSndZTwoFF0ALESKi0zUxItik4+Un+1kfyiXmycqKH0O X-Received: by 10.99.173.73 with SMTP id y9mr2486032pgo.432.1518708578346; Thu, 15 Feb 2018 07:29:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518708578; cv=none; d=google.com; s=arc-20160816; b=b/f0pmnPm1mPRB6Lbgw5WkDwq2juA3i3NsDtjpN37lkH9007+o6myV9KEwFxvpBjAA FoBpd8TpbGjCBu+Uy3h2M7lAhzLqI6I0bnMKbNUSzADIgaA1yDTvkBk2i/eWG/GX5v83 JzcNdpi+5xGZ/3/pqItGaM4LQiZS40x/VUCLFHknaE9qdjIgrWaCqwFV5FYyOY0lJIXV VQAXjKuiuT1HBoUwsd2WQzxi1UqZZezuyi1kWja5L7ygVOygQYkGE4B1/l5iCWgLHfUk NFDsSHkhXM/AQ0JmBSIcMKYock1VGDozuD7ZFTtcrLYaX+SMlLNwZA5xMdUi8x8vgapK xFGg== 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=s6beJ4xeh2iBsQ1xvKqFoFPZa2CqKJWu6YiWF/gecUU=; b=hGpvz9cXokqroOJbGQzXu07hfO45+w4qxW9yTafGMptjdSVzthYVPgurGouJV2Ae0T OCKGIEo4inqRL8DcRdcibqxmz8sKD2n7Jq9wguzQPaSNfTBr/5vqnkKGrinlY+hsofG0 Q7V+ApS0g2c3R19UJaTyYtuoRgyXy7rdf595DzxI7RUOdQdNNV4GZgon6iVTcFHjvr9q E0OIfRw/NeP6uRmWaNN1G2Oz/IG07+gx7CAIgO3+34pGCrIeN25k9R95mdPZ76lZK27l lTkujKkfuy6noOFY+uYEFFUDPOCF+95ML/TDI/M1D9YPKTfve8Z2VLiNG252e9GJAfo5 dCYQ== 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 d8-v6si1700176pls.25.2018.02.15.07.29.24; Thu, 15 Feb 2018 07:29:38 -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 S1163686AbeBOP1y (ORCPT + 99 others); Thu, 15 Feb 2018 10:27:54 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:53610 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1163671AbeBOP1s (ORCPT ); Thu, 15 Feb 2018 10:27:48 -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 5C5931036; Thu, 15 Feb 2018 15:27:47 +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 4.9 52/88] arm: KVM: Fix SMCCC handling of unimplemented SMC/HVC calls Date: Thu, 15 Feb 2018 16:17:19 +0100 Message-Id: <20180215151229.925317169@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151222.437136975@linuxfoundation.org> References: <20180215151222.437136975@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 4.9-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 @@ -38,7 +38,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; } @@ -47,7 +47,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; }