0100-x86-xen-64-x86-entry-64-Clean-up-SP-code-in-cpu_init.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Andy Lutomirski <[email protected]>
  3. Date: Thu, 2 Nov 2017 00:59:12 -0700
  4. Subject: [PATCH] x86/xen/64, x86/entry/64: Clean up SP code in
  5. cpu_initialize_context()
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. CVE-2017-5754
  10. I'm removing thread_struct::sp0, and Xen's usage of it is slightly
  11. dubious and unnecessary. Use appropriate helpers instead.
  12. While we're at at, reorder the code slightly to make it more obvious
  13. what's going on.
  14. Signed-off-by: Andy Lutomirski <[email protected]>
  15. Reviewed-by: Juergen Gross <[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: Juergen Gross <[email protected]>
  21. Cc: Linus Torvalds <[email protected]>
  22. Cc: Peter Zijlstra <[email protected]>
  23. Cc: Thomas Gleixner <[email protected]>
  24. Link: http://lkml.kernel.org/r/d5b9a3da2b47c68325bd2bbe8f82d9554dee0d0f.1509609304.git.luto@kernel.org
  25. Signed-off-by: Ingo Molnar <[email protected]>
  26. (cherry picked from commit f16b3da1dc936c0f8121741d0a1731bf242f2f56)
  27. Signed-off-by: Andy Whitcroft <[email protected]>
  28. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  29. (cherry picked from commit 27c60a1f6c49062151f67042458a523386cc3dc5)
  30. Signed-off-by: Fabian Grünbichler <[email protected]>
  31. ---
  32. arch/x86/xen/smp_pv.c | 17 ++++++++++++++---
  33. 1 file changed, 14 insertions(+), 3 deletions(-)
  34. diff --git a/arch/x86/xen/smp_pv.c b/arch/x86/xen/smp_pv.c
  35. index 51471408fdd1..8c0e047d0b80 100644
  36. --- a/arch/x86/xen/smp_pv.c
  37. +++ b/arch/x86/xen/smp_pv.c
  38. @@ -13,6 +13,7 @@
  39. * single-threaded.
  40. */
  41. #include <linux/sched.h>
  42. +#include <linux/sched/task_stack.h>
  43. #include <linux/err.h>
  44. #include <linux/slab.h>
  45. #include <linux/smp.h>
  46. @@ -293,12 +294,19 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
  47. #endif
  48. memset(&ctxt->fpu_ctxt, 0, sizeof(ctxt->fpu_ctxt));
  49. + /*
  50. + * Bring up the CPU in cpu_bringup_and_idle() with the stack
  51. + * pointing just below where pt_regs would be if it were a normal
  52. + * kernel entry.
  53. + */
  54. ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
  55. ctxt->flags = VGCF_IN_KERNEL;
  56. ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
  57. ctxt->user_regs.ds = __USER_DS;
  58. ctxt->user_regs.es = __USER_DS;
  59. ctxt->user_regs.ss = __KERNEL_DS;
  60. + ctxt->user_regs.cs = __KERNEL_CS;
  61. + ctxt->user_regs.esp = (unsigned long)task_pt_regs(idle);
  62. xen_copy_trap_info(ctxt->trap_ctxt);
  63. @@ -313,8 +321,13 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
  64. ctxt->gdt_frames[0] = gdt_mfn;
  65. ctxt->gdt_ents = GDT_ENTRIES;
  66. + /*
  67. + * Set SS:SP that Xen will use when entering guest kernel mode
  68. + * from guest user mode. Subsequent calls to load_sp0() can
  69. + * change this value.
  70. + */
  71. ctxt->kernel_ss = __KERNEL_DS;
  72. - ctxt->kernel_sp = idle->thread.sp0;
  73. + ctxt->kernel_sp = task_top_of_stack(idle);
  74. #ifdef CONFIG_X86_32
  75. ctxt->event_callback_cs = __KERNEL_CS;
  76. @@ -326,10 +339,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
  77. (unsigned long)xen_hypervisor_callback;
  78. ctxt->failsafe_callback_eip =
  79. (unsigned long)xen_failsafe_callback;
  80. - ctxt->user_regs.cs = __KERNEL_CS;
  81. per_cpu(xen_cr3, cpu) = __pa(swapper_pg_dir);
  82. - ctxt->user_regs.esp = idle->thread.sp0 - sizeof(struct pt_regs);
  83. ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_gfn(swapper_pg_dir));
  84. if (HYPERVISOR_vcpu_op(VCPUOP_initialise, xen_vcpu_nr(cpu), ctxt))
  85. BUG();
  86. --
  87. 2.14.2