Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp859858rdb; Fri, 26 Jan 2024 13:02:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEGS+BLPC25WXLJrangqGvOHMIvkklVeq/OudGQosUhXGSaAnIqnm/ghMKyxeSGY+4w05EH X-Received: by 2002:a05:6122:2a4f:b0:4bd:707b:9cfc with SMTP id fx15-20020a0561222a4f00b004bd707b9cfcmr339324vkb.10.1706302935407; Fri, 26 Jan 2024 13:02:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706302935; cv=pass; d=google.com; s=arc-20160816; b=hKLWxAUYZj1J3N1uC7UdR+e67Ya+SrFhE58HIa/QM/8TOhvf9WaLaNOYCCHe6DJyMP zrjsHpWxl7K9qjENKvKo4gfLHEF2tpbwQaexKi43ZzS802ZGsFOXk6hskbx1CKEBG9GI jtZAheZzNnDZVEcsVLUAFCooFtlcTfPygH0UrFZLiLhLdpPMKE1dP1adeX2MSj/z0Kfn EJG9TsuIoHauDkFYf8iRKdL8lrWxQ7a3wxZQNXNRqoS1ItW2wNjBXuZM2qYfb7LVuRvT 8+qTwwF1s/CqU+CerGbF7abnq9C1ciWEQsppAqYzSULPg3JGmuQZ6xm/UbuQPF0winLZ odbg== 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=YXo4rNx0jEt6yUQfKDOtegAhnXJBbbsAktS5vUIdul8=; fh=o3CYwh1t/ir/PwNAX4EA9A7OTDL9GyL2lTV9HBEFNKs=; b=HxD+etrCfP+WRiGjq7ZI/WBH/U2Kfy+eW8rBgiHhLxJyb07xQbFCc4NTP1/+y/Ykbj p+rKLZpJSjpK3fOlDJt1hbNVM1O26BWU5CEAm6/gPqSsYe7wa3K2fIVcGahhtnx+a4a3 12kpwID/ZSPgeGEYF3yDH+zlxWm5KVqwriyH/D9DtJ6CFrcuafzKon3kzBL/+rkm/1hp mrPM3wBLi6CMpBLU6dhMcrbKFWhFpoD6KcXueRdT8RfBXB8EExy3KaSR953F5ICwcVCm Z6TE8JeD6GQN+loKGtz8qk6KfMogGTPeP1aiTxCFSy5si7LFPPCyy+lhOHvNi80+axIz qmcw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=U3CR9W38; 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-40644-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40644-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ec9-20020a056122368900b004bd7d89ac4fsi369399vkb.306.2024.01.26.13.02.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 13:02:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40644-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=U3CR9W38; 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-40644-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40644-linux.lists.archive=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 24ACE1C248DD for ; Fri, 26 Jan 2024 21:02:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9BCC72421E; Fri, 26 Jan 2024 21:02:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xry111.site header.i=@xry111.site header.b="U3CR9W38" 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 9583D2374C; Fri, 26 Jan 2024 21:02:07 +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=1706302929; cv=none; b=XpKs77LKRxwlK+9RGtnfxjHp+m+/iBSfKl86ywM4Qw6qEaGDDP3JERmO1TKBAOHbsxh9J0aYHptcSwH7BFRKNoh7f4el1ti9IytmMUcNNdPohk9pRAB4ZO77F1LjzSTOhaV/AARsFZb+QsOAkLjFPewU3HSCKslvGHCHsGMJ5/g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706302929; c=relaxed/simple; bh=mn39oHpKfrn31dhBf6OIk09Xa6Qf/ZTs2k7yrfk5adA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=A60iBnePNS86HPL3VdGrKJ7MubGXYqvSgcV0z/H/Y0/W6HfgzCAi9hHkUDoPE+jW7FL/JfEmrHMMOHNTUB0KkcN+A9O5ec9sApAKdU+xcOg5G3x9dJzVvzvf2u6HZK5tIEwtfOqrqv+QPkV60/ytK1b6iV+gPwZsvJTRAyoRFNw= 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=U3CR9W38; 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=1706302923; bh=mn39oHpKfrn31dhBf6OIk09Xa6Qf/ZTs2k7yrfk5adA=; h=From:To:Cc:Subject:Date:From; b=U3CR9W38GcKEHTnb5MkhwcafV1zLklKgHN8srBonMiiLOgJBLd43aKdrY8oYvZ4nj 5RSct1lbhRLPK69gRBaey0Zl9kJNiPMXfP2vJxkiEJfp7CDxyHVfE4WYGDwXtqY6CB 70FVtUnT7uAopEpSWiOQm07xsbjC6ekCHIGhlNOo= 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 BFBFD66A22; Fri, 26 Jan 2024 16:01:58 -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.linux.org Subject: [PATCH] mips: Call lose_fpu(0) before initializing fcr31 in mips_set_personality_nan Date: Sat, 27 Jan 2024 04:59:22 +0800 Message-ID: <20240126205920.11487-3-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 Content-Transfer-Encoding: 8bit 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.linux.org Signed-off-by: Xi Ruoyao --- 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: -- 2.43.0