0186-x86-cpu_entry_area-Prevent-wraparound-in-setup_cpu_e.patch 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. From 23aa91651cbaf32f10ff75f02c281493ee677dcb Mon Sep 17 00:00:00 2001
  2. From: Thomas Gleixner <[email protected]>
  3. Date: Sat, 23 Dec 2017 19:45:11 +0100
  4. Subject: [PATCH 186/231] x86/cpu_entry_area: Prevent wraparound in
  5. setup_cpu_entry_area_ptes() on 32bit
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. CVE-2017-5754
  10. The loop which populates the CPU entry area PMDs can wrap around on 32bit
  11. machines when the number of CPUs is small.
  12. It worked wonderful for NR_CPUS=64 for whatever reason and the moron who
  13. wrote that code did not bother to test it with !SMP.
  14. Check for the wraparound to fix it.
  15. Fixes: 92a0f81d8957 ("x86/cpu_entry_area: Move it out of the fixmap")
  16. Reported-by: kernel test robot <[email protected]>
  17. Signed-off-by: Thomas "Feels stupid" Gleixner <[email protected]>
  18. Tested-by: Borislav Petkov <[email protected]>
  19. (cherry picked from commit f6c4fd506cb626e4346aa81688f255e593a7c5a0)
  20. Signed-off-by: Andy Whitcroft <[email protected]>
  21. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  22. (cherry picked from commit 8a21158932b93ed7e72d16683085d55a3a06125e)
  23. Signed-off-by: Fabian Grünbichler <[email protected]>
  24. ---
  25. arch/x86/mm/cpu_entry_area.c | 3 ++-
  26. 1 file changed, 2 insertions(+), 1 deletion(-)
  27. diff --git a/arch/x86/mm/cpu_entry_area.c b/arch/x86/mm/cpu_entry_area.c
  28. index 21e8b595cbb1..fe814fd5e014 100644
  29. --- a/arch/x86/mm/cpu_entry_area.c
  30. +++ b/arch/x86/mm/cpu_entry_area.c
  31. @@ -122,7 +122,8 @@ static __init void setup_cpu_entry_area_ptes(void)
  32. start = CPU_ENTRY_AREA_BASE;
  33. end = start + CPU_ENTRY_AREA_MAP_SIZE;
  34. - for (; start < end; start += PMD_SIZE)
  35. + /* Careful here: start + PMD_SIZE might wrap around */
  36. + for (; start < end && start >= CPU_ENTRY_AREA_BASE; start += PMD_SIZE)
  37. populate_extra_pte(start);
  38. #endif
  39. }
  40. --
  41. 2.14.2