0122-x86-Make-X86_BUG_FXSAVE_LEAK-detectable-in-CPUID-on-.patch 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. From 5280fab9bb19e94b1ea5046dc1360f121ec64c0f Mon Sep 17 00:00:00 2001
  2. From: Rudolf Marek <[email protected]>
  3. Date: Tue, 28 Nov 2017 22:01:06 +0100
  4. Subject: [PATCH 122/232] x86: Make X86_BUG_FXSAVE_LEAK detectable in CPUID on
  5. AMD
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. CVE-2017-5754
  10. [ Note, this is a Git cherry-pick of the following commit:
  11. 2b67799bdf25 ("x86: Make X86_BUG_FXSAVE_LEAK detectable in CPUID on AMD")
  12. ... for easier x86 PTI code testing and back-porting. ]
  13. The latest AMD AMD64 Architecture Programmer's Manual
  14. adds a CPUID feature XSaveErPtr (CPUID_Fn80000008_EBX[2]).
  15. If this feature is set, the FXSAVE, XSAVE, FXSAVEOPT, XSAVEC, XSAVES
  16. / FXRSTOR, XRSTOR, XRSTORS always save/restore error pointers,
  17. thus making the X86_BUG_FXSAVE_LEAK workaround obsolete on such CPUs.
  18. Signed-Off-By: Rudolf Marek <[email protected]>
  19. Signed-off-by: Thomas Gleixner <[email protected]>
  20. Reviewed-by: Borislav Petkov <[email protected]>
  21. Tested-by: Borislav Petkov <[email protected]>
  22. Cc: Andy Lutomirski <[email protected]>
  23. Link: https://lkml.kernel.org/r/[email protected]
  24. Signed-off-by: Ingo Molnar <[email protected]>
  25. (cherry picked from commit f2dbad36c55e5d3a91dccbde6e8cae345fe5632f)
  26. Signed-off-by: Andy Whitcroft <[email protected]>
  27. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  28. (cherry picked from commit 281b622113c66ba2de9b7725e1d232ea3c282114)
  29. Signed-off-by: Fabian Grünbichler <[email protected]>
  30. ---
  31. arch/x86/include/asm/cpufeatures.h | 1 +
  32. arch/x86/kernel/cpu/amd.c | 7 +++++--
  33. 2 files changed, 6 insertions(+), 2 deletions(-)
  34. diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
  35. index 0ea630bb3e74..d57a174ec97c 100644
  36. --- a/arch/x86/include/asm/cpufeatures.h
  37. +++ b/arch/x86/include/asm/cpufeatures.h
  38. @@ -265,6 +265,7 @@
  39. /* AMD-defined CPU features, CPUID level 0x80000008 (EBX), word 13 */
  40. #define X86_FEATURE_CLZERO (13*32+ 0) /* CLZERO instruction */
  41. #define X86_FEATURE_IRPERF (13*32+ 1) /* Instructions Retired Count */
  42. +#define X86_FEATURE_XSAVEERPTR (13*32+ 2) /* Always save/restore FP error pointers */
  43. /* Thermal and Power Management Leaf, CPUID level 0x00000006 (EAX), word 14 */
  44. #define X86_FEATURE_DTHERM (14*32+ 0) /* Digital Thermal Sensor */
  45. diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
  46. index 3b9e220621f8..2a5328cc03a6 100644
  47. --- a/arch/x86/kernel/cpu/amd.c
  48. +++ b/arch/x86/kernel/cpu/amd.c
  49. @@ -760,8 +760,11 @@ static void init_amd(struct cpuinfo_x86 *c)
  50. case 0x15: init_amd_bd(c); break;
  51. }
  52. - /* Enable workaround for FXSAVE leak */
  53. - if (c->x86 >= 6)
  54. + /*
  55. + * Enable workaround for FXSAVE leak on CPUs
  56. + * without a XSaveErPtr feature
  57. + */
  58. + if ((c->x86 >= 6) && (!cpu_has(c, X86_FEATURE_XSAVEERPTR)))
  59. set_cpu_bug(c, X86_BUG_FXSAVE_LEAK);
  60. cpu_detect_cache_sizes(c);
  61. --
  62. 2.14.2