From patchwork Fri Jan 26 21:05:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 192783 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2395:b0:106:343:edcb with SMTP id gw21csp149684dyb; Fri, 26 Jan 2024 13:06:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHIrNsbWZNNUh3v/rUCQJ3yNNbbkxwdoDMcx21X5/U1xB803IzekGE0kvcV/TNUdBr9axYK X-Received: by 2002:a05:6a20:af13:b0:19a:7b36:66a2 with SMTP id dr19-20020a056a20af1300b0019a7b3666a2mr328917pzb.49.1706303196479; Fri, 26 Jan 2024 13:06:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706303196; cv=pass; d=google.com; s=arc-20160816; b=QrsdDKNcNVTd4/a11v6yhldAen4ys+zRHPUiTn9s4kmPdkYieeya+UJ9AxnE2Zt2Me gms9iTuyuJxx98L6iyiIxbhyx8fQD6OsWylYy8Dxr6zIcqBycCGYrkAjs+12tlmjQhWV 62JHTpEwbcDPKqtZ7lHvZh+29lSSGoYpkILZrR4YpmO8n9nxCRHvB/PiAm2uMqzY00XD dJRZXXcH0sNWoE7PUZ0BM0r7DcvnbM7PAShye8MtVjc53q3msuivO9IDm8H1uBGyIl0J oOjJ3PIxn2jqoP1WQeD3woVcwme7NryXABNJvNiJtHXx6fcBE7ImReaswgEYiqbYQuwW Ko1Q== ARC-Message-Signature: i=2; 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:message-id:date:subject:cc:to :from:dkim-signature; bh=EoJemsG7zxUo/FmjwJatg9m7Gv+XGAu+lwvDkceBtrc=; fh=Tx6dpK7U6GtDaFhICg47P4hfe05Mu0pTx93yT0T/fiE=; b=ifqf4BO/exKEmBLW3pdtJOuZKEJ8a+GNmh5aC7GcUSeAQbY+8eD7ELZGgsPVT1ZOYG OXLN1vpYdBMSzKbAv5Q9ucHyVobi1RTpaIfQ0EQUjhTB9gWSZ8GA5DFXh35HRQ4ZZCLA u2nBc5CoD0SOz49GFDS/3cdRjGbmLuK34/sQQBXjtRTfFlzDeK0AR0tOtaeg0RQwLywr z1mBSyLvvYGRsJg2y1gzBHOsAH3C8kLq26q2I7ZK4kX5JzBWnCS1wXv6gDKJUoVjpRX2 NV9+K4mx6MD0Jsjg5TZSSWMQjGrK39C0oOBfe5dC/Mt0Qxy6fvzHzWVkl5JTv4f411Lq 0b1g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b="S/zVRU6E"; arc=pass (i=1 spf=pass spfdomain=xry111.site dkim=pass dkdomain=xry111.site dmarc=pass fromdomain=xry111.site); spf=pass (google.com: domain of linux-kernel+bounces-40648-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40648-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 138-20020a630290000000b005d818072f2esi1282119pgc.874.2024.01.26.13.06.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 13:06:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40648-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b="S/zVRU6E"; arc=pass (i=1 spf=pass spfdomain=xry111.site dkim=pass dkdomain=xry111.site dmarc=pass fromdomain=xry111.site); spf=pass (google.com: domain of linux-kernel+bounces-40648-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40648-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site 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 430222821CA for ; Fri, 26 Jan 2024 21:06:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0781D249FF; Fri, 26 Jan 2024 21:06:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xry111.site header.i=@xry111.site header.b="S/zVRU6E" Received: from xry111.site (xry111.site [89.208.246.23]) (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 04D7B22EF9; Fri, 26 Jan 2024 21:06:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=89.208.246.23 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706303180; cv=none; b=HqCGFdCf0CrGzfTLYyyhr22IQlqwGsENUXLZtei6Ig6xQ2SeYQABZ2V1DDzeGCJpfRw50jRiin5fKwcAcrS0reECcZOMMtB40k4siF0MBnh5OLAGqcBfb1aBIFM3VMikgqC+FwbJGVgzu8z4oTF21LwTW4vBD6Y+OLN419MxNEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706303180; c=relaxed/simple; bh=AV1ZofWLKqVz1PfTeAIMra2ot1/I4iebX4fFRvtm+Uw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=D4FWsLTam7eiOQO5mnfUKqZedITOmy8838uvg7YCWyGUk9Z3ELDTAt6s16n0kLPn3kry6ROHB0yrblwkZYHm5Aj3SddwoZyCOL4iAn4vM6IHHwYM6nDKEK6oWeTr8EGHtua64h4w6F9v5soepWCROFyXJsgEztvBag0fcAhF8tw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=xry111.site; spf=pass smtp.mailfrom=xry111.site; dkim=pass (1024-bit key) header.d=xry111.site header.i=@xry111.site header.b=S/zVRU6E; arc=none smtp.client-ip=89.208.246.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1706303177; bh=AV1ZofWLKqVz1PfTeAIMra2ot1/I4iebX4fFRvtm+Uw=; h=From:To:Cc:Subject:Date:From; b=S/zVRU6E9Q+G3QqJe79cHk0eD7ZSmd0XFyrUlcwTqi3+4Nn4KctzPxOJXVu2Ngdtk sxmANB7LCY3lE8puILgATdGJ9t2ZlQM2o5uV8JpPqAg2XUvm/DlFjYYQhYtsoLgvsO P1Hcspk9qHqUxtAXVx6itlHof7JHxaCKKlB85aJo= Received: from stargazer.. (unknown [IPv6:240e:358:1181:9d00:dc73:854d:832e:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 35E7F66A29; Fri, 26 Jan 2024 16:06:10 -0500 (EST) From: Xi Ruoyao To: Thomas Bogendoerfer , Jiaxun Yang , linux-mips@vger.kernel.org Cc: Ralf Baechle , "Maciej W. Rozycki" , YunQiang Su , Huacai Chen , WANG Xuerui , linux-kernel@vger.kernel.org, Xi Ruoyao , stable@vger.kernel.org Subject: [PATCH v2] mips: Call lose_fpu(0) before initializing fcr31 in mips_set_personality_nan Date: Sat, 27 Jan 2024 05:05:57 +0800 Message-ID: <20240126210557.12442-1-xry111@xry111.site> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789188435298510905 X-GMAIL-MSGID: 1789188580542504937 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 --- v1 -> v2: Fix stable list address in Cc line. arch/mips/kernel/elf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/mips/kernel/elf.c b/arch/mips/kernel/elf.c index 5582a4ca1e9e..7aa2c2360ff6 100644 --- 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 arch_elf_state *state) 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: