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 906F62D79D; Tue, 16 Jan 2024 01:08:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gA0/vKOT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61649C43399; Tue, 16 Jan 2024 01:08:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705367282; bh=z9Z/P6e9Nj9RPAHquzp+XmH8ajhDID8q4WfNGUpN+n0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gA0/vKOTZSDrv1JgDa/b9MsMbl8kYPJTpC1o0DQ7Nej4p0o7a06vD40OoBo5OwpoL VKyh69jDadXXB7bflpbg4PshPSISKF5laHjpMbPiODo7Epj6RfpGypkmzSO/NPEGP2 DJUK7u2f8veV5daR+3f3fYsIkMQXJu0BC56p7DBcNW0XalSRFSXdY0mgn7p1fQOf24 AvByWfumqsk1qe5udY609GluUCHwrPIu+00TDmeh9KYpNzioaCTUZjbl5Z/1P3ZdWG nRjNKkdJSd/WfEBS2+XtsLJSFadS+ELAtMR/Q9UUM5cJvR7GfkxdniYswlWmdVobz1 1r2kDXCHPJZVQ== 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 5.10 2/9] s390/ptrace: handle setting of fpc register correctly Date: Mon, 15 Jan 2024 20:07:46 -0500 Message-ID: <20240116010757.219495-2-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240116010757.219495-1-sashal@kernel.org> References: <20240116010757.219495-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 5.10.208 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 3009bb527252..f381caddd905 100644 --- a/arch/s390/kernel/ptrace.c +++ b/arch/s390/kernel/ptrace.c @@ -411,6 +411,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; @@ -771,6 +772,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; @@ -1010,9 +1012,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