mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 1/2] x86/fpu: Fix NULL dereference in avx512_status()
@ 2025-07-21 21:53 Sohil Mehta
  2025-07-21 21:53 ` [PATCH v2 2/2] x86/fpu: Update the debug flow for x86_task_fpu() Sohil Mehta
  2025-07-21 22:33 ` [PATCH v2 1/2] x86/fpu: Fix NULL dereference in avx512_status() Dave Hansen
  0 siblings, 2 replies; 6+ messages in thread
From: Sohil Mehta @ 2025-07-21 21:53 UTC (permalink / raw)
  To: Dave Hansen, x86
  Cc: Borislav Petkov, H . Peter Anvin, Thomas Gleixner, Ingo Molnar,
	Sohil Mehta, Sean Christopherson, Peter Zijlstra,
	Vignesh Balasubramanian, Rick Edgecombe, Oleg Nesterov,
	Chang S . Bae, Brian Gerst, Eric Biggers, Kees Cook, Chao Gao,
	Fushuai Wang, linux-kernel

From: Fushuai Wang <wangfushuai@baidu.com>

When CONFIG_X86_DEBUG_FPU is set, reading /proc/[kthread]/arch_status
causes a NULL pointer dereference.

For Kthreads tasks:
  proc_pid_arch_status()
    avx512_status()
      x86_task_fpu() => returns NULL when CONFIG_X86_DEBUG_FPU=y
      x86_task_fpu()->avx512_timestamp => NULL dereference

Kernel threads aren't expected to access FPU state directly. However,
avx512_timestamp resides within struct fpu which lead to this unique
situation.

It is uncertain whether kernel threads use AVX-512 in a meaningful way
that needs userspace reporting. For now, avoid reporting AVX-512 usage
for kernel threads.

Fixes: 22aafe3bcb67 ("x86/fpu: Remove init_task FPU state dependencies, add debugging warning for PF_KTHREAD tasks")
Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
Co-developed-by: Sohil Mehta <sohil.mehta@intel.com>
Signed-off-by: Sohil Mehta <sohil.mehta@intel.com>
---
v2:
 - Avoid making the fix dependent on CONFIG_X86_DEBUG_FPU.
 - Include PF_USER_WORKER in the kernel thread check.
 - Update commit message for clarity.

v1: https://lore.kernel.org/lkml/20250717094308.94450-1-wangfushuai@baidu.com/
---
 arch/x86/kernel/fpu/xstate.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 9aa9ac8399ae..a75077c645b6 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -1855,19 +1855,18 @@ long fpu_xstate_prctl(int option, unsigned long arg2)
 #ifdef CONFIG_PROC_PID_ARCH_STATUS
 /*
  * Report the amount of time elapsed in millisecond since last AVX512
- * use in the task.
+ * use in the task. Report -1 if no AVX-512 usage.
  */
 static void avx512_status(struct seq_file *m, struct task_struct *task)
 {
-	unsigned long timestamp = READ_ONCE(x86_task_fpu(task)->avx512_timestamp);
-	long delta;
+	unsigned long timestamp = 0;
+	long delta = -1;
 
-	if (!timestamp) {
-		/*
-		 * Report -1 if no AVX512 usage
-		 */
-		delta = -1;
-	} else {
+	/* Do not report AVX-512 usage for kernel threads */
+	if (!(task->flags & (PF_KTHREAD | PF_USER_WORKER)))
+		timestamp = READ_ONCE(x86_task_fpu(task)->avx512_timestamp);
+
+	if (timestamp) {
 		delta = (long)(jiffies - timestamp);
 		/*
 		 * Cap to LONG_MAX if time difference > LONG_MAX
-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-07-22  1:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-21 21:53 [PATCH v2 1/2] x86/fpu: Fix NULL dereference in avx512_status() Sohil Mehta
2025-07-21 21:53 ` [PATCH v2 2/2] x86/fpu: Update the debug flow for x86_task_fpu() Sohil Mehta
2025-07-21 22:34   ` Dave Hansen
2025-07-22  1:40     ` Sohil Mehta
2025-07-21 22:33 ` [PATCH v2 1/2] x86/fpu: Fix NULL dereference in avx512_status() Dave Hansen
2025-07-22  1:11   ` Sohil Mehta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome