0028-x86-asm-Replace-access-to-desc_struct-a-b-fields.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. From a0b37d5a5f250199b6df4e9404d2071802591de6 Mon Sep 17 00:00:00 2001
  2. From: Thomas Gleixner <[email protected]>
  3. Date: Mon, 28 Aug 2017 08:47:40 +0200
  4. Subject: [PATCH 028/242] x86/asm: Replace access to desc_struct:a/b fields
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. The union inside of desc_struct which allows access to the raw u32 parts of
  10. the descriptors. This raw access part is about to go away.
  11. Replace the few code parts which access those fields.
  12. Signed-off-by: Thomas Gleixner <[email protected]>
  13. Reviewed-by: Boris Ostrovsky <[email protected]>
  14. Cc: Andy Lutomirski <[email protected]>
  15. Cc: Borislav Petkov <[email protected]>
  16. Cc: Brian Gerst <[email protected]>
  17. Cc: Denys Vlasenko <[email protected]>
  18. Cc: H. Peter Anvin <[email protected]>
  19. Cc: Josh Poimboeuf <[email protected]>
  20. Cc: Juergen Gross <[email protected]>
  21. Cc: Linus Torvalds <[email protected]>
  22. Cc: Peter Zijlstra <[email protected]>
  23. Cc: Steven Rostedt <[email protected]>
  24. Link: http://lkml.kernel.org/r/[email protected]
  25. Signed-off-by: Ingo Molnar <[email protected]>
  26. (cherry picked from commit 9a98e7780022aa7cd201eb8a88a4f1d607b73cde)
  27. Signed-off-by: Andy Whitcroft <[email protected]>
  28. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  29. (cherry picked from commit 8469c76c61ea9c3b86b596352d1148bace5ea706)
  30. Signed-off-by: Fabian Grünbichler <[email protected]>
  31. ---
  32. arch/x86/include/asm/xen/hypercall.h | 6 ++++--
  33. arch/x86/kernel/tls.c | 2 +-
  34. arch/x86/xen/enlighten_pv.c | 2 +-
  35. 3 files changed, 6 insertions(+), 4 deletions(-)
  36. diff --git a/arch/x86/include/asm/xen/hypercall.h b/arch/x86/include/asm/xen/hypercall.h
  37. index 11071fcd630e..9606688caa4b 100644
  38. --- a/arch/x86/include/asm/xen/hypercall.h
  39. +++ b/arch/x86/include/asm/xen/hypercall.h
  40. @@ -552,6 +552,8 @@ static inline void
  41. MULTI_update_descriptor(struct multicall_entry *mcl, u64 maddr,
  42. struct desc_struct desc)
  43. {
  44. + u32 *p = (u32 *) &desc;
  45. +
  46. mcl->op = __HYPERVISOR_update_descriptor;
  47. if (sizeof(maddr) == sizeof(long)) {
  48. mcl->args[0] = maddr;
  49. @@ -559,8 +561,8 @@ MULTI_update_descriptor(struct multicall_entry *mcl, u64 maddr,
  50. } else {
  51. mcl->args[0] = maddr;
  52. mcl->args[1] = maddr >> 32;
  53. - mcl->args[2] = desc.a;
  54. - mcl->args[3] = desc.b;
  55. + mcl->args[2] = *p++;
  56. + mcl->args[3] = *p;
  57. }
  58. trace_xen_mc_entry(mcl, sizeof(maddr) == sizeof(long) ? 2 : 4);
  59. diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
  60. index dcd699baea1b..a106b9719c58 100644
  61. --- a/arch/x86/kernel/tls.c
  62. +++ b/arch/x86/kernel/tls.c
  63. @@ -93,7 +93,7 @@ static void set_tls_desc(struct task_struct *p, int idx,
  64. while (n-- > 0) {
  65. if (LDT_empty(info) || LDT_zero(info)) {
  66. - desc->a = desc->b = 0;
  67. + memset(desc, 0, sizeof(*desc));
  68. } else {
  69. fill_ldt(desc, info);
  70. diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
  71. index 49ee3315b9f7..c76f5ff4d0d7 100644
  72. --- a/arch/x86/xen/enlighten_pv.c
  73. +++ b/arch/x86/xen/enlighten_pv.c
  74. @@ -501,7 +501,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
  75. static inline bool desc_equal(const struct desc_struct *d1,
  76. const struct desc_struct *d2)
  77. {
  78. - return d1->a == d2->a && d1->b == d2->b;
  79. + return !memcmp(d1, d2, sizeof(*d1));
  80. }
  81. static void load_TLS_descriptor(struct thread_struct *t,
  82. --
  83. 2.14.2