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 28D6C762C1; Wed, 21 Feb 2024 14:00:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708524038; cv=none; b=FYJvJL+Pwp5rPF/OGmNm/TwvjeSmFVbfTBie3MTYkZrYIzRM/xQADutn1APAxNknnJdf9DgcVT2NfW/yeDw8L17RQCWQdYhN6w1y3ElbLa2LvyKx3ueyvFl1jZZlECTZYgeDL/Z3/+CXCBmFfkqgy9vZUBbJ9Q38cqEjS69895g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708524038; c=relaxed/simple; bh=Ypyt+AZVuORb5Dv64ibK8iZJSECYHOyiSxK00lAXoVs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TZO2saWq1RpmE4W77RhlF8owP6wBr59zoFwo0DrQxYsGdss6xpn2MWfSY3KHsp2WAxcixSX5YEufeoKNAiErMSVLByODlF7EvQp9CbpfAn3Ui+vlons4g8LO7EY4HpAtX7l1Dl408wU/Zqup7mToshg7rRKvITAtYnN445kH7fs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Pnu3QDNW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Pnu3QDNW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98BCBC433C7; Wed, 21 Feb 2024 14:00:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708524038; bh=Ypyt+AZVuORb5Dv64ibK8iZJSECYHOyiSxK00lAXoVs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pnu3QDNWMflvsuUC/Z13PFwJFGI4vbbA84eP6j0RJwXMYWGBzX4Z9wM051Q3kxIki fN3tmmCJigDMEj8mn2cll04oU7SpYkTN91e/YTOukv3Cw+z8/h3Xm18pKfJAuYIdft UjaXal3kpiOeU2PlVY5yEss9lYQoTpAxpngdKZdk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Xi Ruoyao , Thomas Bogendoerfer Subject: [PATCH 5.10 098/379] mips: Call lose_fpu(0) before initializing fcr31 in mips_set_personality_nan Date: Wed, 21 Feb 2024 14:04:37 +0100 Message-ID: <20240221125957.822079162@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221125954.917878865@linuxfoundation.org> References: <20240221125954.917878865@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Xi Ruoyao commit 59be5c35850171e307ca5d3d703ee9ff4096b948 upstream. If we still own the FPU after initializing fcr31, when we are preempted the dirty value in the FPU will be read out and stored into fcr31, clobbering our setting. This can cause an improper floating-point environment after execve(). For example: zsh% cat measure.c #include int main() { return fetestexcept(FE_INEXACT); } zsh% cc measure.c -o measure -lm zsh% echo $((1.0/3)) # raising FE_INEXACT 0.33333333333333331 zsh% while ./measure; do ; done (stopped in seconds) Call lose_fpu(0) before setting fcr31 to prevent this. Closes: https://lore.kernel.org/linux-mips/7a6aa1bbdbbe2e63ae96ff163fab0349f58f1b9e.camel@xry111.site/ Fixes: 9b26616c8d9d ("MIPS: Respect the ISA level in FCSR handling") Cc: stable@vger.kernel.org Signed-off-by: Xi Ruoyao Signed-off-by: Thomas Bogendoerfer Signed-off-by: Greg Kroah-Hartman --- arch/mips/kernel/elf.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/arch/mips/kernel/elf.c +++ b/arch/mips/kernel/elf.c @@ -11,6 +11,7 @@ #include #include +#include #ifdef CONFIG_MIPS_FP_SUPPORT @@ -309,6 +310,11 @@ void mips_set_personality_nan(struct arc struct cpuinfo_mips *c = &boot_cpu_data; struct task_struct *t = current; + /* Do this early so t->thread.fpu.fcr31 won't be clobbered in case + * we are preempted before the lose_fpu(0) in start_thread. + */ + lose_fpu(0); + t->thread.fpu.fcr31 = c->fpu_csr31; switch (state->nan_2008) { case 0: