0107-x86-cpuid-Replace-set-clear_bit32.patch 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. From 3e535e66c0bd546a1891c3a8ad6bf6aae7a0829e Mon Sep 17 00:00:00 2001
  2. From: Thomas Gleixner <[email protected]>
  3. Date: Thu, 2 Nov 2017 13:22:35 +0100
  4. Subject: [PATCH 107/242] x86/cpuid: Replace set/clear_bit32()
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. Peter pointed out that the set/clear_bit32() variants are broken in various
  10. aspects.
  11. Replace them with open coded set/clear_bit() and type cast
  12. cpu_info::x86_capability as it's done in all other places throughout x86.
  13. Fixes: 0b00de857a64 ("x86/cpuid: Add generic table for CPUID dependencies")
  14. Reported-by: Peter Ziljstra <[email protected]>
  15. Signed-off-by: Thomas Gleixner <[email protected]>
  16. Cc: Andi Kleen <[email protected]>
  17. (cherry picked from commit 06dd688ddda5819025e014b79aea9af6ab475fa2)
  18. Signed-off-by: Andy Whitcroft <[email protected]>
  19. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  20. (cherry picked from commit 3e511952bc3ff9b233d418b0a75a8331deb08171)
  21. Signed-off-by: Fabian Grünbichler <[email protected]>
  22. ---
  23. arch/x86/kernel/cpu/cpuid-deps.c | 26 +++++++++++---------------
  24. 1 file changed, 11 insertions(+), 15 deletions(-)
  25. diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c
  26. index c21f22d836ad..904b0a3c4e53 100644
  27. --- a/arch/x86/kernel/cpu/cpuid-deps.c
  28. +++ b/arch/x86/kernel/cpu/cpuid-deps.c
  29. @@ -62,23 +62,19 @@ const static struct cpuid_dep cpuid_deps[] = {
  30. {}
  31. };
  32. -static inline void __clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit)
  33. -{
  34. - clear_bit32(bit, c->x86_capability);
  35. -}
  36. -
  37. -static inline void __setup_clear_cpu_cap(unsigned int bit)
  38. -{
  39. - clear_cpu_cap(&boot_cpu_data, bit);
  40. - set_bit32(bit, cpu_caps_cleared);
  41. -}
  42. -
  43. static inline void clear_feature(struct cpuinfo_x86 *c, unsigned int feature)
  44. {
  45. - if (!c)
  46. - __setup_clear_cpu_cap(feature);
  47. - else
  48. - __clear_cpu_cap(c, feature);
  49. + /*
  50. + * Note: This could use the non atomic __*_bit() variants, but the
  51. + * rest of the cpufeature code uses atomics as well, so keep it for
  52. + * consistency. Cleanup all of it separately.
  53. + */
  54. + if (!c) {
  55. + clear_cpu_cap(&boot_cpu_data, feature);
  56. + set_bit(feature, (unsigned long *)cpu_caps_cleared);
  57. + } else {
  58. + clear_bit(feature, (unsigned long *)c->x86_capability);
  59. + }
  60. }
  61. /* Take the capabilities and the BUG bits into account */
  62. --
  63. 2.14.2