From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3DB212B9B; Tue, 16 Jan 2024 01:04:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Pz7mz58h" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56284C433F1; Tue, 16 Jan 2024 01:04:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705367089; bh=hW/eSg5d7K6pgLZdwzqIpEwWIhjaeTGSAuuOR+FBth8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pz7mz58h0xInZCd6y964PjDHWUml1tVAlnbBHKmCEk7i2tpHev3vFUyP+fL65TkjD vt9TTVZ+AxTnE7OK5EKScIADblwJcT7L8CbVi/IJTvGnmH05FneL/uNiiEhS/Yr0FG PRJJi4mshRkrYBMe+dMaWahvU7E9+SgFW20wfGUAAsNI+HECoIGX+E7At3f21nwUUP y5i2nTxNw4lNHXd23lJJQXU1+IWMxmCcV3jEUiX1GxMbMJIB9FTPCpzonNIefZXQnm MB2F/lZtZDusEz3VX0WhUhnlsjvX11dG1weLkYY8ukymfX4xpPOCR5XsoVBGfEg2CN 6x3Fjx93hfgEw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Heiko Carstens , Christian Borntraeger , Claudio Imbrenda , Alexander Gordeev , Sasha Levin , frankja@linux.ibm.com, gor@linux.ibm.com, kvm@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH AUTOSEL 6.7 07/21] KVM: s390: fix setting of fpc register Date: Mon, 15 Jan 2024 20:03:44 -0500 Message-ID: <20240116010422.217925-7-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240116010422.217925-1-sashal@kernel.org> References: <20240116010422.217925-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.7 Content-Transfer-Encoding: 8bit From: Heiko Carstens [ Upstream commit b988b1bb0053c0dcd26187d29ef07566a565cf55 ] kvm_arch_vcpu_ioctl_set_fpu() allows to set the floating point control (fpc) register of a guest cpu. The new value is tested for validity by temporarily loading it into the fpc register. This may lead to corruption of the fpc register of the host process: if an interrupt happens while the value is temporarily loaded into the fpc register, and within interrupt context floating point or vector registers are used, the current fp/vx registers are saved with save_fpu_regs() assuming they belong to user space and will be loaded into fp/vx registers when returning to user space. test_fp_ctl() restores the original user space / host process fpc register value, however it will be discarded, when returning to user space. In result the host process will incorrectly continue to run with the value that was supposed to be used for a guest cpu. Fix this by simply removing the test. There is another test right before the SIE context is entered which will handles invalid values. This results in a change of behaviour: invalid values will now be accepted instead of that the ioctl fails with -EINVAL. This seems to be acceptable, given that this interface is most likely not used anymore, and this is in addition the same behaviour implemented with the memory mapped interface (replace invalid values with zero) - see sync_regs() in kvm-s390.c. Reviewed-by: Christian Borntraeger Reviewed-by: Claudio Imbrenda Signed-off-by: Heiko Carstens Signed-off-by: Alexander Gordeev Signed-off-by: Sasha Levin --- arch/s390/kvm/kvm-s390.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 7aa0e668488f..16e32174807f 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -4316,10 +4316,6 @@ int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) vcpu_load(vcpu); - if (test_fp_ctl(fpu->fpc)) { - ret = -EINVAL; - goto out; - } vcpu->run->s.regs.fpc = fpu->fpc; if (MACHINE_HAS_VX) convert_fp_to_vx((__vector128 *) vcpu->run->s.regs.vrs, @@ -4327,7 +4323,6 @@ int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) else memcpy(vcpu->run->s.regs.fprs, &fpu->fprs, sizeof(fpu->fprs)); -out: vcpu_put(vcpu); return ret; } -- 2.43.0