{"id":65456,"date":"2025-07-03T14:32:21","date_gmt":"2025-07-03T11:02:21","guid":{"rendered":"https:\/\/afaghhosting.net\/blog\/cve-2025-38170-linux-kernel-arm64-fpsimd-sme-trap-handling-stale-cpu-state-vulnerability\/"},"modified":"2025-07-03T14:32:21","modified_gmt":"2025-07-03T11:02:21","slug":"cve-2025-38170-linux-kernel-arm64-fpsimd-sme-trap-handling-stale-cpu-state-vulnerability","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/cve-2025-38170-linux-kernel-arm64-fpsimd-sme-trap-handling-stale-cpu-state-vulnerability\/","title":{"rendered":"CVE-2025-38170 &#8211; Linux kernel &#8211; arm64 FPSIMD SME Trap Handling Stale CPU State Vulnerability"},"content":{"rendered":"<p><strong>CVE ID : <\/strong>CVE-2025-38170<br \/>\n<br \/>\n<strong>Published : <\/strong> July 3, 2025, 9:15 a.m. | 1\u00a0hour, 40\u00a0minutes ago<br \/>\n<br \/>\n<strong>Description : <\/strong>In the Linux kernel, the following vulnerability has been resolved:<\/p>\n<p>arm64\/fpsimd: Discard stale CPU state when handling SME traps<\/p>\n<p>The logic for handling SME traps manipulates saved FPSIMD\/SVE\/SME state<br \/>\nincorrectly, and a race with preemption can result in a task having<br \/>\nTIF_SME set and TIF_FOREIGN_FPSTATE clear even though the live CPU state<br \/>\nis stale (e.g. with SME traps enabled). This can result in warnings from<br \/>\ndo_sme_acc() where SME traps are not expected while TIF_SME is set:<\/p>\n<p>|        \/* With TIF_SME userspace shouldn&#8217;t generate any traps *\/<br \/>\n|        if (test_and_set_thread_flag(TIF_SME))<br \/>\n|                WARN_ON(1);<\/p>\n<p>This is very similar to the SVE issue we fixed in commit:<\/p>\n<p>  751ecf6afd6568ad (&#8220;arm64\/sve: Discard stale CPU state when handling SVE traps&#8221;)<\/p>\n<p>The race can occur when the SME trap handler is preempted before and<br \/>\nafter manipulating the saved FPSIMD\/SVE\/SME state, starting and ending on<br \/>\nthe same CPU, e.g.<\/p>\n<p>| void do_sme_acc(unsigned long esr, struct pt_regs *regs)<br \/>\n| {<br \/>\n|         \/\/ Trap on CPU 0 with TIF_SME clear, SME traps enabled<br \/>\n|         \/\/ task-&gt;fpsimd_cpu is 0.<br \/>\n|         \/\/ per_cpu_ptr(&amp;fpsimd_last_state, 0) is task.<br \/>\n|<br \/>\n|         &#8230;<br \/>\n|<br \/>\n|         \/\/ Preempted; migrated from CPU 0 to CPU 1.<br \/>\n|         \/\/ TIF_FOREIGN_FPSTATE is set.<br \/>\n|<br \/>\n|         get_cpu_fpsimd_context();<br \/>\n|<br \/>\n|         \/* With TIF_SME userspace shouldn&#8217;t generate any traps *\/<br \/>\n|         if (test_and_set_thread_flag(TIF_SME))<br \/>\n|                 WARN_ON(1);<br \/>\n|<br \/>\n|         if (!test_thread_flag(TIF_FOREIGN_FPSTATE)) {<br \/>\n|                 unsigned long vq_minus_one =<br \/>\n|                         sve_vq_from_vl(task_get_sme_vl(current)) &#8211; 1;<br \/>\n|                 sme_set_vq(vq_minus_one);<br \/>\n|<br \/>\n|                 fpsimd_bind_task_to_cpu();<br \/>\n|         }<br \/>\n|<br \/>\n|         put_cpu_fpsimd_context();<br \/>\n|<br \/>\n|         \/\/ Preempted; migrated from CPU 1 to CPU 0.<br \/>\n|         \/\/ task-&gt;fpsimd_cpu is still 0<br \/>\n|         \/\/ If per_cpu_ptr(&amp;fpsimd_last_state, 0) is still task then:<br \/>\n|         \/\/ &#8211; Stale HW state is reused (with SME traps enabled)<br \/>\n|         \/\/ &#8211; TIF_FOREIGN_FPSTATE is cleared<br \/>\n|         \/\/ &#8211; A return to userspace skips HW state restore<br \/>\n| }<\/p>\n<p>Fix the case where the state is not live and TIF_FOREIGN_FPSTATE is set<br \/>\nby calling fpsimd_flush_task_state() to detach from the saved CPU<br \/>\nstate. This ensures that a subsequent context switch will not reuse the<br \/>\nstale CPU state, and will instead set TIF_FOREIGN_FPSTATE, forcing the<br \/>\nnew state to be reloaded from memory prior to a return to userspace.<\/p>\n<p>Note: this was originallly posted as [1].<\/p>\n[ Rutland: rewrite commit message ]\n<br \/>\n<strong>Severity:<\/strong> 0.0 | NA<br \/>\n<br \/>\nVisit the link for more details, such as CVSS details, affected products, timeline, and more&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CVE ID : CVE-2025-38170 Published : July 3, 2025, 9:15 a.m. | 1\u00a0hour, 40\u00a0minutes ago Description : In the Linux kernel, the following vulnerability has been resolved: arm64\/fpsimd: Discard stale CPU state when handling SME traps The logic for handling SME traps manipulates saved FPSIMD\/SVE\/SME state incorrectly, and a race with preemption can result in &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-65456","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/65456","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=65456"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/65456\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=65456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=65456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=65456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}