Received: by 10.223.185.116 with SMTP id b49csp2375390wrg; Thu, 15 Feb 2018 10:37:56 -0800 (PST) X-Google-Smtp-Source: AH8x226xbvveqmZuQFrvwTREMXTcVx4SKSLwpQsRUgVOCXBPKlmYc1kjmZDX/N2EaveVRL00801B X-Received: by 2002:a17:902:7681:: with SMTP id m1-v6mr3445243pll.144.1518719876613; Thu, 15 Feb 2018 10:37:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518719876; cv=none; d=google.com; s=arc-20160816; b=bc1uiFuSD0tTOcEkYSQ/zEc4E5qbas+ko5VyTh3QUcnCeH6GX2Eqch9u+Dq5J6FfUZ vuNqzA41BULGKgI5UX2fM2WbuL1vM5//xkbxojtjtsLV6vQgO811m2boduHC810Jz7Gd X4QgX4ySZYOEn4Hd8VhdyI+FVRoHHVQAASD0UrnKAYGXOUq6twbwARNYfNEHc94Mse7I mg7kH5whODoVVYjOkUzIJ40NtURT1EfkhhZqsaAYRvPupJkREu7lnW6lQ97gHxOyBseN IygPgpt8eqxvsPKpSr4wNbYRxTN3GpyFCrWJOgujMb+bC/6w+c2/UqpETekw1UCKKX0H shqQ== 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=THbJBr5MWSwUQPvjKU+nPOOU1LBrAly1FxbTEAbIfcQ=; b=hNUe9nZLZvUyGVJ4eSU3+9a+6lhLtrMzSvLmzW0ztK8yupCO1/t8StihpyPJVBXJaf JIHD9LeGo9/0AolnHMCUFSbBI7g5sff2VnHhlDzdGkvW29wKC9RYdsK8dQXqfbg8x2Nb vFCVh0E/LzTc/N1at4Fw9ibr6EvncKlmIBF3FgfKKthzcSLL8SGcVgbYC7bwk47Rot5k r0sJCelKR/+F4EivoJYgrg+RLxb4/m+5a9mzovXGyXJPAzCxwsuT00hoKfBbzrqH/mfj 6olT++T8SEWJgIP4MJk4WqGtQEck/QPKJ9vp4slUxZ8CPqhdq/uQhKtVrg1pbPfv99Ve jB2Q== 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 y23si2363610pfk.136.2018.02.15.10.37.41; Thu, 15 Feb 2018 10:37:56 -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 S1162867AbeBOPYY (ORCPT + 99 others); Thu, 15 Feb 2018 10:24:24 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:51864 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033898AbeBOPYV (ORCPT ); Thu, 15 Feb 2018 10:24:21 -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 961A1E43; Thu, 15 Feb 2018 15:24:20 +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.4 086/108] arm: KVM: Fix SMCCC handling of unimplemented SMC/HVC calls Date: Thu, 15 Feb 2018 16:17:23 +0100 Message-Id: <20180215151234.348680449@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151222.267507937@linuxfoundation.org> References: <20180215151222.267507937@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.4-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; }