From nobody Mon Oct 6 19:09:59 2025 Received: from baidu.com (mx22.baidu.com [220.181.50.185]) (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 625C228A3FC for ; Thu, 17 Jul 2025 09:44:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.181.50.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752745501; cv=none; b=WfkOY2TKojqYWcMdnJRP04kQwbQYcFbDWzZRdAW0ZbYMcUOdVFRt7qeXgdmP18ol8lIQechjaaFssejdcibWuSCa7oLmV12SbUKK1EGFjBSZVb7L7IDpyKpeJ5Ib5lGoREAj2bhOK6zEs+dbPceNfqIew/FbaRv+UQ+NRVH3Smg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752745501; c=relaxed/simple; bh=CKWUAx3I1kSr/hGyutDFcPettfcApk3ft9EYC5zonDg=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=XRa3d3A5xigm/c32a5V/aqQvNSGZQhAHdHk0g9lQHgvAJvHpKWybaY+w+ZMJSw595OI+I5RIC+HLiIia9IDJOrzPu22XfO6ljwhi8Od6xSwNxi+Lq6bVy+J+BTPn2R+h6jxUjG04x+zLAvRtgxXA2HnZeCRjc52Rm9yHwxPcSHQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com; spf=pass smtp.mailfrom=baidu.com; arc=none smtp.client-ip=220.181.50.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baidu.com From: Fushuai Wang To: , , , , , , , , , , , CC: , Fushuai Wang Subject: [PATCH] x86/fpu: Fix potential NULL dereference in avx512_status() Date: Thu, 17 Jul 2025 17:43:08 +0800 Message-ID: <20250717094308.94450-1-wangfushuai@baidu.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: bjhj-exc7.internal.baidu.com (172.31.3.17) To bjhj-exc17.internal.baidu.com (172.31.4.15) X-FEAS-Client-IP: 172.31.4.15 X-FE-Policy-ID: 52:10:53:SYSTEM Content-Type: text/plain; charset="utf-8" When CONFIG_X86_DEBUG_FPU=3Dy is set, x86_task_fpu() returns NULL for kernel threads. The avx512_status() function would then dereference this NULL pointer via READ_ONCE(x86_task_fpu(task)->avx512_timestamp). when reading /proc/*/arch_status, causing a kernel NULL pointer dereference and system will crash. [ 8215.540977] Oops: general protection fault, probably for non-canonical a= ddress 0xdffffc0000000001: 0000 [#1] SMP KASAN NOPTI [ 8215.542290] CPU: 3 UID: 0 PID: 9285 Comm: cat Kdump: loaded Tainted: G = W 6.16.0-rc1 #4 PREEMPT(full) [ 8215.543000] Tainted: [W]=3DWARN [ 8215.544481] RIP: 0010:proc_pid_arch_status+0x30/0xe0 [ 8215.545408] Code: 1f 44 00 00 55 48 89 fd 48 89 cf 53 48 83 ec 08 e8 e5 = 64 ff ff 48 ba 00 00 00 00 00 fc ff df 48 8d 78 08 48 8 9 f9 48 c1 e9 03 <80> 3c 11 00 75 7d 48 8b 58 08 48 c7 c2 ff ff ff ff 48 85= db 74 3d [ 8215.548456] RSP: 0018:ff11000194107b08 EFLAGS: 00010202 [ 8215.549443] RAX: 0000000000000000 RBX: ff11000211a9c9a0 RCX: 00000000000= 00001 [ 8215.550581] RDX: dffffc0000000000 RSI: ffffffff96d0d020 RDI: 00000000000= 00008 [ 8215.551740] RBP: ff11000111792490 R08: 0000000000000001 R09: ffe21c00211= 7d61d [ 8215.552917] R10: ff11000108beb0eb R11: 0000000000000000 R12: ff11000108a= 80b80 [ 8215.554111] R13: ff11000108beb0e8 R14: ffffffff96d0d020 R15: 00000000000= 00001 [ 8215.555323] FS: 00007f75c18ad740(0000) GS:ff11000e266d1000(0000) knlGS:= 0000000000000000 [ 8215.556629] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 8215.557880] CR2: 00005605184020f8 CR3: 0000000164499005 CR4: 00000000007= 71ef0 [ 8215.559553] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 00000000000= 00000 [ 8215.560882] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 00000000000= 00400 [ 8215.562205] PKRU: 55555554 [ 8215.563277] Call Trace: [ 8215.564338] [ 8215.565383] proc_single_show+0x10c/0x1c0 [ 8215.566568] seq_read_iter+0x3e5/0x1050 [ 8215.567787] seq_read+0x24b/0x3b0 [ 8215.569305] ? __pfx_seq_read+0x10/0x10 [ 8215.570509] ? __pfx_handle_pte_fault+0x10/0x10 [ 8215.571782] ? __pfx_arch_get_unmapped_area_topdown+0x10/0x10 [ 8215.573142] ? __pfx_cp_new_stat+0x10/0x10 [ 8215.574417] vfs_read+0x186/0xad0 [ 8215.575657] ? __pfx_mas_prev+0x10/0x10 [ 8215.576947] ? __pfx_vfs_read+0x10/0x10 [ 8215.578234] ? count_memcg_events+0x1ce/0x410 [ 8215.579523] ? fdget_pos+0x1c9/0x4c0 [ 8215.580737] ksys_read+0xef/0x1c0 [ 8215.581896] ? __pfx_ksys_read+0x10/0x10 [ 8215.583265] ? do_user_addr_fault+0x4c6/0xb50 [ 8215.584633] do_syscall_64+0x73/0x330 [ 8215.585773] ? irqentry_exit_to_user_mode+0x32/0x210 [ 8215.586967] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ 8215.588137] RIP: 0033:0x7f75c17147e2 [ 8215.589209] Code: c0 e9 b2 fe ff ff 50 48 8d 3d 8a b4 0c 00 e8 a5 1d 02 = 00 0f 1f 44 00 00 f3 0f 1e fa 64 8b 04 25 18 00 00 00 8 5 c0 75 10 0f 05 <48> 3d 00 f0 ff ff 77 56 c3 0f 1f 44 00 00 48 83 ec 28 48= 89 54 24 [ 8215.592896] RSP: 002b:00007fffd6935ef8 EFLAGS: 00000246 ORIG_RAX: 000000= 0000000000 [ 8215.594238] RAX: ffffffffffffffda RBX: 0000000000020000 RCX: 00007f75c17= 147e2 [ 8215.595551] RDX: 0000000000020000 RSI: 00005605183e2000 RDI: 00000000000= 00003 [ 8215.596876] RBP: 00005605183e2000 R08: 0000000000000000 R09: 00005605183= e10f0 [ 8215.598187] R10: 00005605183fe000 R11: 0000000000000246 R12: 00000000000= 00000 [ 8215.599494] R13: 0000000000000003 R14: 0000000000020000 R15: 00000000000= 20000 [ 8215.600807] Fixes: 22aafe3bcb67 ("x86/fpu: Remove init_task FPU state dependencies, add= debugging warning for PF_KTHREAD tasks") Signed-off-by: Fushuai Wang --- arch/x86/kernel/fpu/xstate.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index 9aa9ac8399ae..16f813a42f42 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -1859,9 +1859,14 @@ long fpu_xstate_prctl(int option, unsigned long arg2) */ static void avx512_status(struct seq_file *m, struct task_struct *task) { - unsigned long timestamp =3D READ_ONCE(x86_task_fpu(task)->avx512_timestam= p); + unsigned long timestamp =3D 0; long delta; =20 +#ifdef CONFIG_X86_DEBUG_FPU + if (!(task->flags & PF_KTHREAD)) +#endif + timestamp =3D READ_ONCE(x86_task_fpu(task)->avx512_timestamp); + if (!timestamp) { /* * Report -1 if no AVX512 usage --=20 2.36.1