x86/fpu: Fix AMD X86_BUG_FXSAVE_LEAK fixup
authorUros Bizjak <ubizjak@gmail.com>
Fri, 15 Mar 2024 08:18:23 +0000 (09:18 +0100)
committerIngo Molnar <mingo@kernel.org>
Tue, 19 Mar 2024 13:02:29 +0000 (14:02 +0100)
The assembly snippet in restore_fpregs_from_fpstate() that implements
X86_BUG_FXSAVE_LEAK fixup loads the value from a random variable,
preferably the one that is already in the L1 cache.

However, the access to fpinit_state via *fpstate pointer is not
implemented correctly. The "m" asm constraint requires dereferenced
pointer variable, otherwise the compiler just reloads the value
via temporary stack slot. The current asm code reflects this:

     mov    %rdi,(%rsp)
     ...
     fildl  (%rsp)

With dereferenced pointer variable, the code does what the
comment above the asm snippet says:

     fildl  (%rdi)

Also, remove the pointless %P operand modifier. The modifier is
ineffective on non-symbolic references - it was used to prevent
%rip-relative addresses in .altinstr sections, but FILDL in the
.text section can use %rip-relative addresses without problems.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20240315081849.5187-1-ubizjak@gmail.com
arch/x86/kernel/fpu/core.c

index 520deb411a70255c1d434f4c07767824af54807f..1209c7aebb211f10c5e021724da0414b2f21a27f 100644 (file)
@@ -145,8 +145,8 @@ void restore_fpregs_from_fpstate(struct fpstate *fpstate, u64 mask)
                asm volatile(
                        "fnclex\n\t"
                        "emms\n\t"
-                       "fildl %P[addr]"        /* set F?P to defined value */
-                       : : [addr] "m" (fpstate));
+                       "fildl %[addr]" /* set F?P to defined value */
+                       : : [addr] "m" (*fpstate));
        }
 
        if (use_xsave()) {