0180-x86-mm-Remove-hard-coded-ASID-limit-checks.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. From f847420cd768a0b95c3159ab822c30c909f0e5ee Mon Sep 17 00:00:00 2001
  2. From: Dave Hansen <[email protected]>
  3. Date: Mon, 4 Dec 2017 15:07:55 +0100
  4. Subject: [PATCH 180/242] x86/mm: Remove hard-coded ASID limit checks
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. First, it's nice to remove the magic numbers.
  10. Second, PAGE_TABLE_ISOLATION is going to consume half of the available ASID
  11. space. The space is currently unused, but add a comment to spell out this
  12. new restriction.
  13. Signed-off-by: Dave Hansen <[email protected]>
  14. Signed-off-by: Thomas Gleixner <[email protected]>
  15. Cc: Andy Lutomirski <[email protected]>
  16. Cc: Boris Ostrovsky <[email protected]>
  17. Cc: Borislav Petkov <[email protected]>
  18. Cc: Brian Gerst <[email protected]>
  19. Cc: Dave Hansen <[email protected]>
  20. Cc: David Laight <[email protected]>
  21. Cc: Denys Vlasenko <[email protected]>
  22. Cc: Eduardo Valentin <[email protected]>
  23. Cc: Greg KH <[email protected]>
  24. Cc: H. Peter Anvin <[email protected]>
  25. Cc: Josh Poimboeuf <[email protected]>
  26. Cc: Juergen Gross <[email protected]>
  27. Cc: Linus Torvalds <[email protected]>
  28. Cc: Peter Zijlstra <[email protected]>
  29. Cc: Will Deacon <[email protected]>
  30. Cc: [email protected]
  31. Cc: [email protected]
  32. Cc: [email protected]
  33. Cc: [email protected]
  34. Cc: [email protected]
  35. Signed-off-by: Ingo Molnar <[email protected]>
  36. (cherry picked from commit cb0a9144a744e55207e24dcef812f05cd15a499a)
  37. Signed-off-by: Andy Whitcroft <[email protected]>
  38. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  39. (cherry picked from commit fd5d001ae73ccd382d4270f53e27dcf61c4e4749)
  40. Signed-off-by: Fabian Grünbichler <[email protected]>
  41. ---
  42. arch/x86/include/asm/tlbflush.h | 20 ++++++++++++++++++--
  43. 1 file changed, 18 insertions(+), 2 deletions(-)
  44. diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
  45. index 3a421b164868..c1c10db4156c 100644
  46. --- a/arch/x86/include/asm/tlbflush.h
  47. +++ b/arch/x86/include/asm/tlbflush.h
  48. @@ -68,6 +68,22 @@ static inline u64 inc_mm_tlb_gen(struct mm_struct *mm)
  49. return atomic64_inc_return(&mm->context.tlb_gen);
  50. }
  51. +/* There are 12 bits of space for ASIDS in CR3 */
  52. +#define CR3_HW_ASID_BITS 12
  53. +/*
  54. + * When enabled, PAGE_TABLE_ISOLATION consumes a single bit for
  55. + * user/kernel switches
  56. + */
  57. +#define PTI_CONSUMED_ASID_BITS 0
  58. +
  59. +#define CR3_AVAIL_ASID_BITS (CR3_HW_ASID_BITS - PTI_CONSUMED_ASID_BITS)
  60. +/*
  61. + * ASIDs are zero-based: 0->MAX_AVAIL_ASID are valid. -1 below to account
  62. + * for them being zero-based. Another -1 is because ASID 0 is reserved for
  63. + * use by non-PCID-aware users.
  64. + */
  65. +#define MAX_ASID_AVAILABLE ((1 << CR3_AVAIL_ASID_BITS) - 2)
  66. +
  67. /*
  68. * If PCID is on, ASID-aware code paths put the ASID+1 into the PCID bits.
  69. * This serves two purposes. It prevents a nasty situation in which
  70. @@ -80,7 +96,7 @@ struct pgd_t;
  71. static inline unsigned long build_cr3(pgd_t *pgd, u16 asid)
  72. {
  73. if (static_cpu_has(X86_FEATURE_PCID)) {
  74. - VM_WARN_ON_ONCE(asid > 4094);
  75. + VM_WARN_ON_ONCE(asid > MAX_ASID_AVAILABLE);
  76. return __sme_pa(pgd) | (asid + 1);
  77. } else {
  78. VM_WARN_ON_ONCE(asid != 0);
  79. @@ -90,7 +106,7 @@ static inline unsigned long build_cr3(pgd_t *pgd, u16 asid)
  80. static inline unsigned long build_cr3_noflush(pgd_t *pgd, u16 asid)
  81. {
  82. - VM_WARN_ON_ONCE(asid > 4094);
  83. + VM_WARN_ON_ONCE(asid > MAX_ASID_AVAILABLE);
  84. return __sme_pa(pgd) | (asid + 1) | CR3_NOFLUSH;
  85. }
  86. --
  87. 2.14.2