0017-x86-mm-Document-how-CR4.PCIDE-restore-works.patch 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. From 20e07f035810f1b2bb3d816e49f48f6b6a37bf64 Mon Sep 17 00:00:00 2001
  2. From: Andy Lutomirski <[email protected]>
  3. Date: Wed, 6 Sep 2017 19:54:54 -0700
  4. Subject: [PATCH 017/232] x86/mm: Document how CR4.PCIDE restore works
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. While debugging a problem, I thought that using
  10. cr4_set_bits_and_update_boot() to restore CR4.PCIDE would be
  11. helpful. It turns out to be counterproductive.
  12. Add a comment documenting how this works.
  13. Signed-off-by: Andy Lutomirski <[email protected]>
  14. Signed-off-by: Linus Torvalds <[email protected]>
  15. (cherry picked from commit 1c9fe4409ce3e9c78b1ed96ee8ed699d4f03bf33)
  16. Signed-off-by: Andy Whitcroft <[email protected]>
  17. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  18. (cherry picked from commit 0d69e4c4a2db42a9bac6609a3df15bd91163f8b9)
  19. Signed-off-by: Fabian Grünbichler <[email protected]>
  20. ---
  21. arch/x86/kernel/cpu/common.c | 13 +++++++++++++
  22. 1 file changed, 13 insertions(+)
  23. diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
  24. index b95cd94ca97b..0b80ed14ff52 100644
  25. --- a/arch/x86/kernel/cpu/common.c
  26. +++ b/arch/x86/kernel/cpu/common.c
  27. @@ -333,6 +333,19 @@ static void setup_pcid(struct cpuinfo_x86 *c)
  28. {
  29. if (cpu_has(c, X86_FEATURE_PCID)) {
  30. if (cpu_has(c, X86_FEATURE_PGE)) {
  31. + /*
  32. + * We'd like to use cr4_set_bits_and_update_boot(),
  33. + * but we can't. CR4.PCIDE is special and can only
  34. + * be set in long mode, and the early CPU init code
  35. + * doesn't know this and would try to restore CR4.PCIDE
  36. + * prior to entering long mode.
  37. + *
  38. + * Instead, we rely on the fact that hotplug, resume,
  39. + * etc all fully restore CR4 before they write anything
  40. + * that could have nonzero PCID bits to CR3. CR4.PCIDE
  41. + * has no effect on the page tables themselves, so we
  42. + * don't need it to be restored early.
  43. + */
  44. cr4_set_bits(X86_CR4_PCIDE);
  45. } else {
  46. /*
  47. --
  48. 2.14.2