0173-x86-entry-Rename-SYSENTER_stack-to-CPU_ENTRY_AREA_en.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. From 3437c6490b62ab15493658a4b9b19786e270bcb2 Mon Sep 17 00:00:00 2001
  2. From: Dave Hansen <[email protected]>
  3. Date: Mon, 4 Dec 2017 17:25:07 -0800
  4. Subject: [PATCH 173/242] x86/entry: Rename SYSENTER_stack to
  5. CPU_ENTRY_AREA_entry_stack
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. CVE-2017-5754
  10. If the kernel oopses while on the trampoline stack, it will print
  11. "<SYSENTER>" even if SYSENTER is not involved. That is rather confusing.
  12. The "SYSENTER" stack is used for a lot more than SYSENTER now. Give it a
  13. better string to display in stack dumps, and rename the kernel code to
  14. match.
  15. Also move the 32-bit code over to the new naming even though it still uses
  16. the entry stack only for SYSENTER.
  17. Signed-off-by: Dave Hansen <[email protected]>
  18. Signed-off-by: Thomas Gleixner <[email protected]>
  19. Cc: Andy Lutomirski <[email protected]>
  20. Cc: Borislav Petkov <[email protected]>
  21. Cc: Borislav Petkov <[email protected]>
  22. Cc: Brian Gerst <[email protected]>
  23. Cc: Denys Vlasenko <[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. Signed-off-by: Ingo Molnar <[email protected]>
  30. (cherry picked from commit 4fe2d8b11a370af286287a2661de9d4e6c9a145a)
  31. Signed-off-by: Andy Whitcroft <[email protected]>
  32. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  33. (cherry picked from commit e0437c473463f208c2b4952f0826e43ce1335a53)
  34. Signed-off-by: Fabian Grünbichler <[email protected]>
  35. ---
  36. arch/x86/include/asm/fixmap.h | 8 ++++----
  37. arch/x86/include/asm/processor.h | 6 +++---
  38. arch/x86/include/asm/stacktrace.h | 4 ++--
  39. arch/x86/kernel/asm-offsets.c | 4 ++--
  40. arch/x86/kernel/asm-offsets_32.c | 2 +-
  41. arch/x86/kernel/cpu/common.c | 14 +++++++-------
  42. arch/x86/kernel/dumpstack.c | 10 +++++-----
  43. arch/x86/kernel/dumpstack_32.c | 6 +++---
  44. arch/x86/kernel/dumpstack_64.c | 12 +++++++++---
  45. arch/x86/entry/entry_32.S | 12 ++++++------
  46. arch/x86/entry/entry_64.S | 4 ++--
  47. 11 files changed, 44 insertions(+), 38 deletions(-)
  48. diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h
  49. index 5dc269ff4085..a7fb137ad964 100644
  50. --- a/arch/x86/include/asm/fixmap.h
  51. +++ b/arch/x86/include/asm/fixmap.h
  52. @@ -56,10 +56,10 @@ struct cpu_entry_area {
  53. char gdt[PAGE_SIZE];
  54. /*
  55. - * The GDT is just below SYSENTER_stack and thus serves (on x86_64) as
  56. + * The GDT is just below entry_stack and thus serves (on x86_64) as
  57. * a a read-only guard page.
  58. */
  59. - struct SYSENTER_stack_page SYSENTER_stack_page;
  60. + struct entry_stack_page entry_stack_page;
  61. /*
  62. * On x86_64, the TSS is mapped RO. On x86_32, it's mapped RW because
  63. @@ -230,9 +230,9 @@ static inline struct cpu_entry_area *get_cpu_entry_area(int cpu)
  64. return (struct cpu_entry_area *)__fix_to_virt(__get_cpu_entry_area_page_index(cpu, 0));
  65. }
  66. -static inline struct SYSENTER_stack *cpu_SYSENTER_stack(int cpu)
  67. +static inline struct entry_stack *cpu_entry_stack(int cpu)
  68. {
  69. - return &get_cpu_entry_area(cpu)->SYSENTER_stack_page.stack;
  70. + return &get_cpu_entry_area(cpu)->entry_stack_page.stack;
  71. }
  72. #endif /* !__ASSEMBLY__ */
  73. diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
  74. index 59a317f8e0ec..935d68609922 100644
  75. --- a/arch/x86/include/asm/processor.h
  76. +++ b/arch/x86/include/asm/processor.h
  77. @@ -330,12 +330,12 @@ struct x86_hw_tss {
  78. #define IO_BITMAP_OFFSET (offsetof(struct tss_struct, io_bitmap) - offsetof(struct tss_struct, x86_tss))
  79. #define INVALID_IO_BITMAP_OFFSET 0x8000
  80. -struct SYSENTER_stack {
  81. +struct entry_stack {
  82. unsigned long words[64];
  83. };
  84. -struct SYSENTER_stack_page {
  85. - struct SYSENTER_stack stack;
  86. +struct entry_stack_page {
  87. + struct entry_stack stack;
  88. } __aligned(PAGE_SIZE);
  89. struct tss_struct {
  90. diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
  91. index 95f999576131..3b3cc5ba579a 100644
  92. --- a/arch/x86/include/asm/stacktrace.h
  93. +++ b/arch/x86/include/asm/stacktrace.h
  94. @@ -15,7 +15,7 @@ enum stack_type {
  95. STACK_TYPE_TASK,
  96. STACK_TYPE_IRQ,
  97. STACK_TYPE_SOFTIRQ,
  98. - STACK_TYPE_SYSENTER,
  99. + STACK_TYPE_ENTRY,
  100. STACK_TYPE_EXCEPTION,
  101. STACK_TYPE_EXCEPTION_LAST = STACK_TYPE_EXCEPTION + N_EXCEPTION_STACKS-1,
  102. };
  103. @@ -28,7 +28,7 @@ struct stack_info {
  104. bool in_task_stack(unsigned long *stack, struct task_struct *task,
  105. struct stack_info *info);
  106. -bool in_sysenter_stack(unsigned long *stack, struct stack_info *info);
  107. +bool in_entry_stack(unsigned long *stack, struct stack_info *info);
  108. int get_stack_info(unsigned long *stack, struct task_struct *task,
  109. struct stack_info *info, unsigned long *visit_mask);
  110. diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
  111. index 40c3fab107ac..25b4832e9c28 100644
  112. --- a/arch/x86/kernel/asm-offsets.c
  113. +++ b/arch/x86/kernel/asm-offsets.c
  114. @@ -96,6 +96,6 @@ void common(void) {
  115. /* Layout info for cpu_entry_area */
  116. OFFSET(CPU_ENTRY_AREA_tss, cpu_entry_area, tss);
  117. OFFSET(CPU_ENTRY_AREA_entry_trampoline, cpu_entry_area, entry_trampoline);
  118. - OFFSET(CPU_ENTRY_AREA_SYSENTER_stack, cpu_entry_area, SYSENTER_stack_page);
  119. - DEFINE(SIZEOF_SYSENTER_stack, sizeof(struct SYSENTER_stack));
  120. + OFFSET(CPU_ENTRY_AREA_entry_stack, cpu_entry_area, entry_stack_page);
  121. + DEFINE(SIZEOF_entry_stack, sizeof(struct entry_stack));
  122. }
  123. diff --git a/arch/x86/kernel/asm-offsets_32.c b/arch/x86/kernel/asm-offsets_32.c
  124. index c4f23da7a0f0..4dba34cb777d 100644
  125. --- a/arch/x86/kernel/asm-offsets_32.c
  126. +++ b/arch/x86/kernel/asm-offsets_32.c
  127. @@ -50,7 +50,7 @@ void foo(void)
  128. /* Offset from the sysenter stack to tss.sp0 */
  129. DEFINE(TSS_sysenter_sp0, offsetof(struct cpu_entry_area, tss.x86_tss.sp0) -
  130. - offsetofend(struct cpu_entry_area, SYSENTER_stack_page.stack));
  131. + offsetofend(struct cpu_entry_area, entry_stack_page.stack));
  132. #ifdef CONFIG_CC_STACKPROTECTOR
  133. BLANK();
  134. diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
  135. index fcdba90e0890..7a8a5d436566 100644
  136. --- a/arch/x86/kernel/cpu/common.c
  137. +++ b/arch/x86/kernel/cpu/common.c
  138. @@ -487,8 +487,8 @@ static DEFINE_PER_CPU_PAGE_ALIGNED(char, exception_stacks
  139. [(N_EXCEPTION_STACKS - 1) * EXCEPTION_STKSZ + DEBUG_STKSZ]);
  140. #endif
  141. -static DEFINE_PER_CPU_PAGE_ALIGNED(struct SYSENTER_stack_page,
  142. - SYSENTER_stack_storage);
  143. +static DEFINE_PER_CPU_PAGE_ALIGNED(struct entry_stack_page,
  144. + entry_stack_storage);
  145. static void __init
  146. set_percpu_fixmap_pages(int idx, void *ptr, int pages, pgprot_t prot)
  147. @@ -523,8 +523,8 @@ static void __init setup_cpu_entry_area(int cpu)
  148. #endif
  149. __set_fixmap(get_cpu_entry_area_index(cpu, gdt), get_cpu_gdt_paddr(cpu), gdt_prot);
  150. - set_percpu_fixmap_pages(get_cpu_entry_area_index(cpu, SYSENTER_stack_page),
  151. - per_cpu_ptr(&SYSENTER_stack_storage, cpu), 1,
  152. + set_percpu_fixmap_pages(get_cpu_entry_area_index(cpu, entry_stack_page),
  153. + per_cpu_ptr(&entry_stack_storage, cpu), 1,
  154. PAGE_KERNEL);
  155. /*
  156. @@ -1315,7 +1315,7 @@ void enable_sep_cpu(void)
  157. tss->x86_tss.ss1 = __KERNEL_CS;
  158. wrmsr(MSR_IA32_SYSENTER_CS, tss->x86_tss.ss1, 0);
  159. - wrmsr(MSR_IA32_SYSENTER_ESP, (unsigned long)(cpu_SYSENTER_stack(cpu) + 1), 0);
  160. + wrmsr(MSR_IA32_SYSENTER_ESP, (unsigned long)(cpu_entry_stack(cpu) + 1), 0);
  161. wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long)entry_SYSENTER_32, 0);
  162. put_cpu();
  163. @@ -1441,7 +1441,7 @@ void syscall_init(void)
  164. * AMD doesn't allow SYSENTER in long mode (either 32- or 64-bit).
  165. */
  166. wrmsrl_safe(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS);
  167. - wrmsrl_safe(MSR_IA32_SYSENTER_ESP, (unsigned long)(cpu_SYSENTER_stack(cpu) + 1));
  168. + wrmsrl_safe(MSR_IA32_SYSENTER_ESP, (unsigned long)(cpu_entry_stack(cpu) + 1));
  169. wrmsrl_safe(MSR_IA32_SYSENTER_EIP, (u64)entry_SYSENTER_compat);
  170. #else
  171. wrmsrl(MSR_CSTAR, (unsigned long)ignore_sysret);
  172. @@ -1655,7 +1655,7 @@ void cpu_init(void)
  173. */
  174. set_tss_desc(cpu, &get_cpu_entry_area(cpu)->tss.x86_tss);
  175. load_TR_desc();
  176. - load_sp0((unsigned long)(cpu_SYSENTER_stack(cpu) + 1));
  177. + load_sp0((unsigned long)(cpu_entry_stack(cpu) + 1));
  178. load_mm_ldt(&init_mm);
  179. diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
  180. index b005e5ef6738..55bf1c3b5319 100644
  181. --- a/arch/x86/kernel/dumpstack.c
  182. +++ b/arch/x86/kernel/dumpstack.c
  183. @@ -43,9 +43,9 @@ bool in_task_stack(unsigned long *stack, struct task_struct *task,
  184. return true;
  185. }
  186. -bool in_sysenter_stack(unsigned long *stack, struct stack_info *info)
  187. +bool in_entry_stack(unsigned long *stack, struct stack_info *info)
  188. {
  189. - struct SYSENTER_stack *ss = cpu_SYSENTER_stack(smp_processor_id());
  190. + struct entry_stack *ss = cpu_entry_stack(smp_processor_id());
  191. void *begin = ss;
  192. void *end = ss + 1;
  193. @@ -53,7 +53,7 @@ bool in_sysenter_stack(unsigned long *stack, struct stack_info *info)
  194. if ((void *)stack < begin || (void *)stack >= end)
  195. return false;
  196. - info->type = STACK_TYPE_SYSENTER;
  197. + info->type = STACK_TYPE_ENTRY;
  198. info->begin = begin;
  199. info->end = end;
  200. info->next_sp = NULL;
  201. @@ -111,13 +111,13 @@ void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
  202. * - task stack
  203. * - interrupt stack
  204. * - HW exception stacks (double fault, nmi, debug, mce)
  205. - * - SYSENTER stack
  206. + * - entry stack
  207. *
  208. * x86-32 can have up to four stacks:
  209. * - task stack
  210. * - softirq stack
  211. * - hardirq stack
  212. - * - SYSENTER stack
  213. + * - entry stack
  214. */
  215. for (regs = NULL; stack; stack = PTR_ALIGN(stack_info.next_sp, sizeof(long))) {
  216. const char *stack_name;
  217. diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
  218. index 3160bf2d100e..4580ba0204f6 100644
  219. --- a/arch/x86/kernel/dumpstack_32.c
  220. +++ b/arch/x86/kernel/dumpstack_32.c
  221. @@ -25,8 +25,8 @@ const char *stack_type_name(enum stack_type type)
  222. if (type == STACK_TYPE_SOFTIRQ)
  223. return "SOFTIRQ";
  224. - if (type == STACK_TYPE_SYSENTER)
  225. - return "SYSENTER";
  226. + if (type == STACK_TYPE_ENTRY)
  227. + return "ENTRY_TRAMPOLINE";
  228. return NULL;
  229. }
  230. @@ -95,7 +95,7 @@ int get_stack_info(unsigned long *stack, struct task_struct *task,
  231. if (task != current)
  232. goto unknown;
  233. - if (in_sysenter_stack(stack, info))
  234. + if (in_entry_stack(stack, info))
  235. goto recursion_check;
  236. if (in_hardirq_stack(stack, info))
  237. diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
  238. index f5107b659f86..7d9c0e06afc2 100644
  239. --- a/arch/x86/kernel/dumpstack_64.c
  240. +++ b/arch/x86/kernel/dumpstack_64.c
  241. @@ -36,8 +36,14 @@ const char *stack_type_name(enum stack_type type)
  242. if (type == STACK_TYPE_IRQ)
  243. return "IRQ";
  244. - if (type == STACK_TYPE_SYSENTER)
  245. - return "SYSENTER";
  246. + if (type == STACK_TYPE_ENTRY) {
  247. + /*
  248. + * On 64-bit, we have a generic entry stack that we
  249. + * use for all the kernel entry points, including
  250. + * SYSENTER.
  251. + */
  252. + return "ENTRY_TRAMPOLINE";
  253. + }
  254. if (type >= STACK_TYPE_EXCEPTION && type <= STACK_TYPE_EXCEPTION_LAST)
  255. return exception_stack_names[type - STACK_TYPE_EXCEPTION];
  256. @@ -117,7 +123,7 @@ int get_stack_info(unsigned long *stack, struct task_struct *task,
  257. if (in_irq_stack(stack, info))
  258. goto recursion_check;
  259. - if (in_sysenter_stack(stack, info))
  260. + if (in_entry_stack(stack, info))
  261. goto recursion_check;
  262. goto unknown;
  263. diff --git a/arch/x86/entry/entry_32.S b/arch/x86/entry/entry_32.S
  264. index 3ef7800007f8..634c6a78885c 100644
  265. --- a/arch/x86/entry/entry_32.S
  266. +++ b/arch/x86/entry/entry_32.S
  267. @@ -949,9 +949,9 @@ ENTRY(debug)
  268. /* Are we currently on the SYSENTER stack? */
  269. movl PER_CPU_VAR(cpu_entry_area), %ecx
  270. - addl $CPU_ENTRY_AREA_SYSENTER_stack + SIZEOF_SYSENTER_stack, %ecx
  271. - subl %eax, %ecx /* ecx = (end of SYSENTER_stack) - esp */
  272. - cmpl $SIZEOF_SYSENTER_stack, %ecx
  273. + addl $CPU_ENTRY_AREA_entry_stack + SIZEOF_entry_stack, %ecx
  274. + subl %eax, %ecx /* ecx = (end of entry_stack) - esp */
  275. + cmpl $SIZEOF_entry_stack, %ecx
  276. jb .Ldebug_from_sysenter_stack
  277. TRACE_IRQS_OFF
  278. @@ -993,9 +993,9 @@ ENTRY(nmi)
  279. /* Are we currently on the SYSENTER stack? */
  280. movl PER_CPU_VAR(cpu_entry_area), %ecx
  281. - addl $CPU_ENTRY_AREA_SYSENTER_stack + SIZEOF_SYSENTER_stack, %ecx
  282. - subl %eax, %ecx /* ecx = (end of SYSENTER_stack) - esp */
  283. - cmpl $SIZEOF_SYSENTER_stack, %ecx
  284. + addl $CPU_ENTRY_AREA_entry_stack + SIZEOF_entry_stack, %ecx
  285. + subl %eax, %ecx /* ecx = (end of entry_stack) - esp */
  286. + cmpl $SIZEOF_entry_stack, %ecx
  287. jb .Lnmi_from_sysenter_stack
  288. /* Not on SYSENTER stack. */
  289. diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
  290. index 157860b3569f..03e052f02176 100644
  291. --- a/arch/x86/entry/entry_64.S
  292. +++ b/arch/x86/entry/entry_64.S
  293. @@ -153,8 +153,8 @@ END(native_usergs_sysret64)
  294. _entry_trampoline - CPU_ENTRY_AREA_entry_trampoline(%rip)
  295. /* The top word of the SYSENTER stack is hot and is usable as scratch space. */
  296. -#define RSP_SCRATCH CPU_ENTRY_AREA_SYSENTER_stack + \
  297. - SIZEOF_SYSENTER_stack - 8 + CPU_ENTRY_AREA
  298. +#define RSP_SCRATCH CPU_ENTRY_AREA_entry_stack + \
  299. + SIZEOF_entry_stack - 8 + CPU_ENTRY_AREA
  300. ENTRY(entry_SYSCALL_64_trampoline)
  301. UNWIND_HINT_EMPTY
  302. --
  303. 2.14.2