Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp394650ybk; Wed, 13 May 2020 03:03:45 -0700 (PDT) X-Google-Smtp-Source: APiQypIK4gac6I2b80zz4xevWb+67MA3dohAC2JKIXo3uTN2wF9cWkgXNKpWxAzQFd/6pTEbi4K4 X-Received: by 2002:a17:906:82d2:: with SMTP id a18mr21071420ejy.373.1589364224673; Wed, 13 May 2020 03:03:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589364224; cv=none; d=google.com; s=arc-20160816; b=gVBnzcg1X71AtT5ic7B9RHtXh/7+OeqLvK1XADCT5V0FpISBbuLC1hhSffYowLWLam pMTXrwgEN2kr7aUv+R0ZEAVA0QxZzIaPtPiAq0zZ+n6NS3iudBC7hM+acntha/AN06/R oDXBz50M6IK4OgTxiHie2AX9bOIOA564WCv6myJmN7J0NPtMnGkGsrjjCiK8vPV00Bsg 1D2zUbcune1xbZwQ0/TB142UA5C5h5tncP6PX6bmjjbmdCKqy9w2gx8HfYSF4VWFVLG9 AsUwjVwnZOIOwlOTICtrrW3VjsajaC3bgzBu73Fz/tYJhMtC9p01lCaFALtNntvEyRCU No6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sK9Mr1iimhSARYT6XkGPrx9Mm6g4pRhrYPpxv0TTdoc=; b=zq8caKDT5AXyBJYbn6V+L940KnLoiXv9IKIY0GeHfIB9wIDVswb6dfl2kxGuJ4VAGY ceZkCpaPScGGo9BXt6/U+5pgxVOTcQ7+WkB4HhrnDvOkLm4CX9BXG3Y0xXoPV851KIG6 JjwNmIwXG8CwBrXUODWUnqzPrTQMfpsRExr+vL4flkxZXlAynyYCAmLEFs79lmFAkNdt lmcMdizqWo4eWivxFzp3nc22VJCOkQTjb6GjALQwz+huc5hjYy/fQ3KN7N0CloFOx4XD 5PH1qMMjD5TH3FVHYrKzlYrcgvs2aAZ/qM1rfL+fyketadaW2IfgQeCCgZ3XPRV1h8J8 icEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bvqN2BQ9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d4si9671529edp.87.2020.05.13.03.03.20; Wed, 13 May 2020 03:03:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bvqN2BQ9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388541AbgEMJ6y (ORCPT + 99 others); Wed, 13 May 2020 05:58:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:56682 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387419AbgEMJyT (ORCPT ); Wed, 13 May 2020 05:54:19 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 143FA20769; Wed, 13 May 2020 09:54:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589363658; bh=WXEx72ox0x9obtGOs2Ak4Pv6rMzqC8WDkMx6ygPsUXk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bvqN2BQ9H7AWRPo1v+ptrkwH8Vxa/hT6hr20ZqZqi7BAKWG8wwAe3lNY0yhPgeFUQ 3Kz+1JrqlBd9kg+dnO9C8GqjrddeoLkbx6TfJv0OL93vQ05dCAghpJKFML5+ME6Mp5 dS5PZoLqwhrar+6bM0duwUk7GUuux1jeZRAsrDvU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Will Deacon , Marc Zyngier Subject: [PATCH 5.6 074/118] KVM: arm64: Fix 32bit PC wrap-around Date: Wed, 13 May 2020 11:44:53 +0200 Message-Id: <20200513094424.154844614@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513094417.618129545@linuxfoundation.org> References: <20200513094417.618129545@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier commit 0225fd5e0a6a32af7af0aefac45c8ebf19dc5183 upstream. In the unlikely event that a 32bit vcpu traps into the hypervisor on an instruction that is located right at the end of the 32bit range, the emulation of that instruction is going to increment PC past the 32bit range. This isn't great, as userspace can then observe this value and get a bit confused. Conversly, userspace can do things like (in the context of a 64bit guest that is capable of 32bit EL0) setting PSTATE to AArch64-EL0, set PC to a 64bit value, change PSTATE to AArch32-USR, and observe that PC hasn't been truncated. More confusion. Fix both by: - truncating PC increments for 32bit guests - sanitizing all 32bit regs every time a core reg is changed by userspace, and that PSTATE indicates a 32bit mode. Cc: stable@vger.kernel.org Acked-by: Will Deacon Signed-off-by: Marc Zyngier Signed-off-by: Greg Kroah-Hartman --- arch/arm64/kvm/guest.c | 7 +++++++ virt/kvm/arm/hyp/aarch32.c | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -201,6 +201,13 @@ static int set_core_reg(struct kvm_vcpu } memcpy((u32 *)regs + off, valp, KVM_REG_SIZE(reg->id)); + + if (*vcpu_cpsr(vcpu) & PSR_MODE32_BIT) { + int i; + + for (i = 0; i < 16; i++) + *vcpu_reg32(vcpu, i) = (u32)*vcpu_reg32(vcpu, i); + } out: return err; } --- a/virt/kvm/arm/hyp/aarch32.c +++ b/virt/kvm/arm/hyp/aarch32.c @@ -125,12 +125,16 @@ static void __hyp_text kvm_adjust_itstat */ void __hyp_text kvm_skip_instr32(struct kvm_vcpu *vcpu, bool is_wide_instr) { + u32 pc = *vcpu_pc(vcpu); bool is_thumb; is_thumb = !!(*vcpu_cpsr(vcpu) & PSR_AA32_T_BIT); if (is_thumb && !is_wide_instr) - *vcpu_pc(vcpu) += 2; + pc += 2; else - *vcpu_pc(vcpu) += 4; + pc += 4; + + *vcpu_pc(vcpu) = pc; + kvm_adjust_itstate(vcpu); }