Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp181439rdb; Mon, 15 Jan 2024 17:32:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IE2JQTOEjsbRE4+JbkvS2QywO5I4Ypgh7wcQ7mVYfKoOoyZv5CJNOUhiAjGBaOyG816wXLb X-Received: by 2002:a05:6870:56ab:b0:205:c8cd:8902 with SMTP id p43-20020a05687056ab00b00205c8cd8902mr4135961oao.106.1705368726053; Mon, 15 Jan 2024 17:32:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705368726; cv=none; d=google.com; s=arc-20160816; b=hn5DjugScC65UW2HWmpQdCQYI7bs/VQ3A5OP0Qj1ZJqj7NlH6TdpVDeNHYgl2VW9cC cIxsLRBn/07zCUNgC7xHYbQOPuPY1kmyr+426GRQwY+7EpnrmYUdmEfYLQM5VRbwiWs9 mtLcb4gpWcxFKxPn8mqx1HgMCRM8C3rlVyIK7V+yUoUz6i4uSiQCMVISA7wTp6ZyUF62 CapdCSv8nkGcBd3cZ9hWm1mzvoK/ujtBexjKQPMyGcmB77we8NBSb1vwd//YIh9MUBaj 8w+N+TATu3lqjM1pYl8cSHygLErmgbqWmrsKBBZZcfwTrpVsytar2fsV51RE4cps4Lkv pfvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=tFL8EMZbqvETZZ9vjrZV0A75/3wdZp8w85i6HOqqn9w=; fh=1Ocf2NwHWe8RPGaaCLEQTeh/QhYCKlu9Oh6XPewyxUw=; b=Tojzd12HsJmUNgtde/kKJO4byQkCiyxlBYV4r4Z9x43o9tuiTiI2qvdy4eKTNfp9n4 VvB56yF4Pxyh1rbahHsyp0ZXocTYwKYC3nV71mXcb/R5pBexuXK4LpT0V/acEYYxcDpf zjEETWDWFTGqHUgEuhW/njHOcrKfjp2NfPQQiTGmq9a9A2tKQq/aqd/GlvNMjNMtZxB5 zHYDrbuA2dEOo97Z9xmpt7KwLoRE4nNUjlUP/CgFoCJ5v4cUJIeoVw/fPL3ttgD7q0AY ygW5v4TcDd51KfL1seyHR9nehkRtaXJoGPBmwleZjn2F7F7g1pHfns5cyLSjz+ZCAG2p YmWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FOKVHHQm; spf=pass (google.com: domain of linux-kernel+bounces-26854-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26854-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y2-20020a656c02000000b005b8ebaa2937si10953700pgu.47.2024.01.15.17.32.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 17:32:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26854-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FOKVHHQm; spf=pass (google.com: domain of linux-kernel+bounces-26854-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26854-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B1DEA28127B for ; Tue, 16 Jan 2024 01:32:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 443A32375C; Tue, 16 Jan 2024 01:06:54 +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: 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) 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: linux-kernel@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