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 70A5C2374A; Tue, 16 Jan 2024 01:06:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FOKVHHQm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15400C433F1; Tue, 16 Jan 2024 01:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705367213; bh=D7ACoRKf/a7txFuaQtiQt2KHGcw+gZqZLMIp/WJnGxA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FOKVHHQm9PcLioSt9wZ134V7bGzPnWZ57AByC9LfONsVAA/XoJcrFUhq282aJw0eX KmMdUekzpvVjinbkDtfoKIAMlm3PVE5gjRgbu7vdYq0wpQGgxOJaN6f8leIat4F9an BJd+L3tMB9IrEQusb1Q2AByxn0L6R3AoQfPBs0UjhntP2+tiWAtepoecf+XOPUa5+M kJKqXKX9QhSpZsEQSOJh0pb3dn2TOC2TDvnEa1UjUjQDF7zTFYxUHpXRHVx3rF/MCU aZBMDdkF4Hc2+/Rp7s3zQoehexdu0mz3Hig4bbClzYDn0Xx3npZE4cdFpcUYLJ1fwK +0K84+EtlejTA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Heiko Carstens , Claudio Imbrenda , Alexander Gordeev , Sasha Levin , oleg@redhat.com, gor@linux.ibm.com, linux-s390@vger.kernel.org Subject: [PATCH AUTOSEL 6.1 04/14] s390/ptrace: handle setting of fpc register correctly Date: Mon, 15 Jan 2024 20:06:06 -0500 Message-ID: <20240116010642.218876-4-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240116010642.218876-1-sashal@kernel.org> References: <20240116010642.218876-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.1.73 Content-Transfer-Encoding: 8bit From: Heiko Carstens [ Upstream commit 8b13601d19c541158a6e18b278c00ba69ae37829 ] If the content of the floating point control (fpc) register of a traced process is modified with the ptrace interface 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 tracing 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 fpc register value, however it will be discarded, when returning to user space. In result the tracer will incorrectly continue to run with the value that was supposed to be used for the traced process. Fix this by saving fpu register contents with save_fpu_regs() before using test_fp_ctl(). Reviewed-by: Claudio Imbrenda Signed-off-by: Heiko Carstens Signed-off-by: Alexander Gordeev Signed-off-by: Sasha Levin --- arch/s390/kernel/ptrace.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/s390/kernel/ptrace.c b/arch/s390/kernel/ptrace.c index 092b16b4dd4f..6b442edb3857 100644 --- a/arch/s390/kernel/ptrace.c +++ b/arch/s390/kernel/ptrace.c @@ -385,6 +385,7 @@ static int __poke_user(struct task_struct *child, addr_t addr, addr_t data) /* * floating point control reg. is in the thread structure */ + save_fpu_regs(); if ((unsigned int) data != 0 || test_fp_ctl(data >> (BITS_PER_LONG - 32))) return -EINVAL; @@ -741,6 +742,7 @@ static int __poke_user_compat(struct task_struct *child, /* * floating point control reg. is in the thread structure */ + save_fpu_regs(); if (test_fp_ctl(tmp)) return -EINVAL; child->thread.fpu.fpc = data; @@ -904,9 +906,7 @@ static int s390_fpregs_set(struct task_struct *target, int rc = 0; freg_t fprs[__NUM_FPRS]; - if (target == current) - save_fpu_regs(); - + save_fpu_regs(); if (MACHINE_HAS_VX) convert_vx_to_fp(fprs, target->thread.fpu.vxrs); else -- 2.43.0