0072-x86-cpuid-Prevent-out-of-bound-access-in-do_clear_cp.patch 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Thomas Gleixner <[email protected]>
  3. Date: Wed, 18 Oct 2017 19:39:35 +0200
  4. Subject: [PATCH] x86/cpuid: Prevent out of bound access in do_clear_cpu_cap()
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. do_clear_cpu_cap() allocates a bitmap to keep track of disabled feature
  10. dependencies. That bitmap is sized NCAPINTS * BITS_PER_INIT. The possible
  11. 'features' which can be handed in are larger than this, because after the
  12. capabilities the bug 'feature' bits occupy another 32bit. Not really
  13. obvious...
  14. So clearing any of the misfeature bits, as 32bit does for the F00F bug,
  15. accesses that bitmap out of bounds thereby corrupting the stack.
  16. Size the bitmap proper and add a sanity check to catch accidental out of
  17. bound access.
  18. Fixes: 0b00de857a64 ("x86/cpuid: Add generic table for CPUID dependencies")
  19. Reported-by: kernel test robot <[email protected]>
  20. Signed-off-by: Thomas Gleixner <[email protected]>
  21. Cc: Andi Kleen <[email protected]>
  22. Cc: Borislav Petkov <[email protected]>
  23. Link: https://lkml.kernel.org/r/20171018022023.GA12058@yexl-desktop
  24. (cherry picked from commit 57b8b1a1856adaa849d02d547411a553a531022b)
  25. Signed-off-by: Andy Whitcroft <[email protected]>
  26. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  27. (cherry picked from commit 4b3a90bd20b35a97fd9ca6f6a71131f4417782e4)
  28. Signed-off-by: Fabian Grünbichler <[email protected]>
  29. ---
  30. arch/x86/kernel/cpu/cpuid-deps.c | 10 ++++++++--
  31. 1 file changed, 8 insertions(+), 2 deletions(-)
  32. diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c
  33. index e48eb7313120..c1d49842a411 100644
  34. --- a/arch/x86/kernel/cpu/cpuid-deps.c
  35. +++ b/arch/x86/kernel/cpu/cpuid-deps.c
  36. @@ -75,11 +75,17 @@ static inline void clear_feature(struct cpuinfo_x86 *c, unsigned int feature)
  37. __clear_cpu_cap(c, feature);
  38. }
  39. +/* Take the capabilities and the BUG bits into account */
  40. +#define MAX_FEATURE_BITS ((NCAPINTS + NBUGINTS) * sizeof(u32) * 8)
  41. +
  42. static void do_clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int feature)
  43. {
  44. - bool changed;
  45. - DECLARE_BITMAP(disable, NCAPINTS * sizeof(u32) * 8);
  46. + DECLARE_BITMAP(disable, MAX_FEATURE_BITS);
  47. const struct cpuid_dep *d;
  48. + bool changed;
  49. +
  50. + if (WARN_ON(feature >= MAX_FEATURE_BITS))
  51. + return;
  52. clear_feature(c, feature);
  53. --
  54. 2.14.2