From patchwork Mon Aug 7 19:03:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shanker Donthineni X-Patchwork-Id: 9886031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6808760364 for ; Mon, 7 Aug 2017 19:05:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57659286B6 for ; Mon, 7 Aug 2017 19:05:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C147286C4; Mon, 7 Aug 2017 19:05:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CD7FD286B6 for ; Mon, 7 Aug 2017 19:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=uaT52RduVpXWzgRp5S8u4a3Ljhcye/oVIH70fC+XA4w=; b=uij 8TecowW46foIiQ1mKmhilX/dvusiC9DjxQdhNWItsq/CpTVdPlBU3x0v+Bh7DKspYTeiSZeBEgWqh y2fHrE53/Fx6jTwFV7M2stGalScIaaeDtd/6ty9pxmqU+g7UM7xNl5vEgu3+56R4pwI7capeJGQih Y1bL3oIbP4+GwhrI+QEN4MK4xLTV25mfaOR59hKV/SXzYnK1jiiJ+yPqUlx7Dvn4D70Awnt1qovG/ CIQUpbNN4P6/Ixjs3qDN4SeGGWEa7LyWpIID6jcz4m20/etLViuibycSOHVx+ecyWhjbWDXr2PQvb wHknoCjaN+m60ETsnclYCEGrz8W8KNg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1denK1-0005Dm-BI; Mon, 07 Aug 2017 19:04:13 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1denJx-0005Br-Va for linux-arm-kernel@lists.infradead.org; Mon, 07 Aug 2017 19:04:11 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 56DAE601D7; Mon, 7 Aug 2017 19:03:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1502132629; bh=3Jc8qQYnOZEipAlSKShaCmshaL50mhHsd447xVIvpko=; h=From:To:Cc:Subject:Date:From; b=l4ul4wQsB4LvtvWMBr+03SZ2gJGm1y7JQcyff0T1Jz8dMcHK1KCy9LJPSs6oOs2xK nuCOImiiOYCwuE8gEzOoQ9LkNt8xpDl3XGBuJl1sAJ5hKz23zyTzjk2MDLySrZyMFH tsovOBjxnByOCZiTPC4xWrRAQPfT/mX0mR4yHBLQ= Received: from shankerd-ubuntu.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: shankerd@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id D559F600EC; Mon, 7 Aug 2017 19:03:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1502132628; bh=3Jc8qQYnOZEipAlSKShaCmshaL50mhHsd447xVIvpko=; h=From:To:Cc:Subject:Date:From; b=FOwGX8jPHMZdE/EwtWhFya3rAXwcvolhN9urs/qiUDbj/mYQjzMvsTOcmNrK2J7e7 gwg4pL1ZcTIiBWBiz7SJbWDE/qbGH3tZurDJRIhLo/b6pGL2/ac5jLeEywtCR1/pzJ +GNralvoHek2pgHY+Y6TIHEx0k3n6JbgH6ixyYrU= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org D559F600EC Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=shankerd@codeaurora.org From: Shanker Donthineni To: Marc Zyngier , Christoffer Dall Subject: [PATCH] arm64: KVM: Reject non-compliant HVC calls from guest kernel Date: Mon, 7 Aug 2017 14:03:28 -0500 Message-Id: <1502132608-26077-1-git-send-email-shankerd@codeaurora.org> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170807_120410_070015_BC491432 X-CRM114-Status: GOOD ( 12.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm , Shanker Donthineni , linux-kernel , linux-arm-kernel , kvmarm MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The SMC/HVC instructions with an immediate value non-zero are not compliant according to 'SMC calling convention system software document'. Add a validation check in handle_hvc() to avoid malicious HVC calls from VM, and inject an undefined instruction for those calls. http://infocenter.arm.com/help/topic/com.arm.doc.den0028b/ARM_DEN0028B_SMC_Calling_Convention.pdf Signed-off-by: Shanker Donthineni --- arch/arm64/include/asm/esr.h | 4 ++++ arch/arm64/kvm/handle_exit.c | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/esr.h b/arch/arm64/include/asm/esr.h index 8cabd57..fa988e5 100644 --- a/arch/arm64/include/asm/esr.h +++ b/arch/arm64/include/asm/esr.h @@ -107,6 +107,9 @@ #define ESR_ELx_AR (UL(1) << 14) #define ESR_ELx_CM (UL(1) << 8) +/* ISS field definitions for HVC/SVC instruction execution traps */ +#define ESR_HVC_IMMEDIATE(esr) ((esr) & 0xFFFF) + /* ISS field definitions for exceptions taken in to Hyp */ #define ESR_ELx_CV (UL(1) << 24) #define ESR_ELx_COND_SHIFT (20) @@ -114,6 +117,7 @@ #define ESR_ELx_WFx_ISS_WFE (UL(1) << 0) #define ESR_ELx_xVC_IMM_MASK ((1UL << 16) - 1) + /* ESR value templates for specific events */ /* BRK instruction trap from AArch64 state */ diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index 17d8a16..a900dcd 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -42,13 +42,15 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run) kvm_vcpu_hvc_get_imm(vcpu)); vcpu->stat.hvc_exit_stat++; - ret = kvm_psci_call(vcpu); - if (ret < 0) { - kvm_inject_undefined(vcpu); - return 1; + /* HVC immediate value must be zero for all compliant calls */ + if (!ESR_HVC_IMMEDIATE(kvm_vcpu_get_hsr(vcpu))) { + ret = kvm_psci_call(vcpu); + if (ret >= 0) + return ret; } - return ret; + kvm_inject_undefined(vcpu); + return 1; } static int handle_smc(struct kvm_vcpu *vcpu, struct kvm_run *run)