Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'x86/espfix' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip into next

Pull x86-64 espfix changes from Peter Anvin:
"This is the espfix64 code, which fixes the IRET information leak as
well as the associated functionality problem. With this code applied,
16-bit stack segments finally work as intended even on a 64-bit
kernel.

Consequently, this patchset also removes the runtime option that we
added as an interim measure.

To help the people working on Linux kernels for very small systems,
this patchset also makes these compile-time configurable features"

* 'x86/espfix' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
Revert "x86-64, modify_ldt: Make support for 16-bit segments a runtime option"
x86, espfix: Make it possible to disable 16-bit support
x86, espfix: Make espfix64 a Kconfig option, fix UML
x86, espfix: Fix broken header guard
x86, espfix: Move espfix definitions into a separate header file
x86-32, espfix: Remove filter for espfix32 due to race
x86-64, espfix: Don't leak bits 31:16 of %esp returning to 16-bit stack

+386 -40
+2
Documentation/x86/x86_64/mm.txt
··· 12 12 ffffe90000000000 - ffffe9ffffffffff (=40 bits) hole 13 13 ffffea0000000000 - ffffeaffffffffff (=40 bits) virtual memory map (1TB) 14 14 ... unused hole ... 15 + ffffff0000000000 - ffffff7fffffffff (=39 bits) %esp fixup stacks 16 + ... unused hole ... 15 17 ffffffff80000000 - ffffffffa0000000 (=512 MB) kernel text mapping, from phys 0 16 18 ffffffffa0000000 - ffffffffff5fffff (=1525 MB) module mapping space 17 19 ffffffffff600000 - ffffffffffdfffff (=8 MB) vsyscalls
+21 -4
arch/x86/Kconfig
··· 912 912 default y 913 913 depends on X86_32 914 914 ---help--- 915 - This option is required by programs like DOSEMU to run 16-bit legacy 916 - code on X86 processors. It also may be needed by software like 917 - XFree86 to initialize some video cards via BIOS. Disabling this 918 - option saves about 6k. 915 + This option is required by programs like DOSEMU to run 916 + 16-bit real mode legacy code on x86 processors. It also may 917 + be needed by software like XFree86 to initialize some video 918 + cards via BIOS. Disabling this option saves about 6K. 919 + 920 + config X86_16BIT 921 + bool "Enable support for 16-bit segments" if EXPERT 922 + default y 923 + ---help--- 924 + This option is required by programs like Wine to run 16-bit 925 + protected mode legacy code on x86 processors. Disabling 926 + this option saves about 300 bytes on i386, or around 6K text 927 + plus 16K runtime memory on x86-64, 928 + 929 + config X86_ESPFIX32 930 + def_bool y 931 + depends on X86_16BIT && X86_32 932 + 933 + config X86_ESPFIX64 934 + def_bool y 935 + depends on X86_16BIT && X86_64 919 936 920 937 config TOSHIBA 921 938 tristate "Toshiba Laptop support"
+16
arch/x86/include/asm/espfix.h
··· 1 + #ifndef _ASM_X86_ESPFIX_H 2 + #define _ASM_X86_ESPFIX_H 3 + 4 + #ifdef CONFIG_X86_64 5 + 6 + #include <asm/percpu.h> 7 + 8 + DECLARE_PER_CPU_READ_MOSTLY(unsigned long, espfix_stack); 9 + DECLARE_PER_CPU_READ_MOSTLY(unsigned long, espfix_waddr); 10 + 11 + extern void init_espfix_bsp(void); 12 + extern void init_espfix_ap(void); 13 + 14 + #endif /* CONFIG_X86_64 */ 15 + 16 + #endif /* _ASM_X86_ESPFIX_H */
+2
arch/x86/include/asm/pgtable_64_types.h
··· 61 61 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE) 62 62 #define MODULES_END _AC(0xffffffffff000000, UL) 63 63 #define MODULES_LEN (MODULES_END - MODULES_VADDR) 64 + #define ESPFIX_PGD_ENTRY _AC(-2, UL) 65 + #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT) 64 66 65 67 #define EARLY_DYNAMIC_PAGE_TABLES 64 66 68
+2
arch/x86/include/asm/setup.h
··· 59 59 60 60 #ifndef _SETUP 61 61 62 + #include <asm/espfix.h> 63 + 62 64 /* 63 65 * This is set up by the setup-routine at boot-time 64 66 */
+1
arch/x86/kernel/Makefile
··· 29 29 obj-y += syscall_$(BITS).o vsyscall_gtod.o 30 30 obj-$(CONFIG_X86_64) += vsyscall_64.o 31 31 obj-$(CONFIG_X86_64) += vsyscall_emu_64.o 32 + obj-$(CONFIG_X86_ESPFIX64) += espfix_64.o 32 33 obj-$(CONFIG_SYSFS) += ksysfs.o 33 34 obj-y += bootflag.o e820.o 34 35 obj-y += pci-dma.o quirks.o topology.o kdebugfs.o
+12 -5
arch/x86/kernel/entry_32.S
··· 527 527 restore_all: 528 528 TRACE_IRQS_IRET 529 529 restore_all_notrace: 530 + #ifdef CONFIG_X86_ESPFIX32 530 531 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS 531 532 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we 532 533 # are returning to the kernel. ··· 538 537 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax 539 538 CFI_REMEMBER_STATE 540 539 je ldt_ss # returning to user-space with LDT SS 540 + #endif 541 541 restore_nocheck: 542 542 RESTORE_REGS 4 # skip orig_eax/error_code 543 543 irq_return: ··· 551 549 .previous 552 550 _ASM_EXTABLE(irq_return,iret_exc) 553 551 552 + #ifdef CONFIG_X86_ESPFIX32 554 553 CFI_RESTORE_STATE 555 554 ldt_ss: 556 - larl PT_OLDSS(%esp), %eax 557 - jnz restore_nocheck 558 - testl $0x00400000, %eax # returning to 32bit stack? 559 - jnz restore_nocheck # allright, normal return 560 - 561 555 #ifdef CONFIG_PARAVIRT 562 556 /* 563 557 * The kernel can't run on a non-flat stack if paravirt mode ··· 595 597 lss (%esp), %esp /* switch to espfix segment */ 596 598 CFI_ADJUST_CFA_OFFSET -8 597 599 jmp restore_nocheck 600 + #endif 598 601 CFI_ENDPROC 599 602 ENDPROC(system_call) 600 603 ··· 703 704 * the high word of the segment base from the GDT and swiches to the 704 705 * normal stack and adjusts ESP with the matching offset. 705 706 */ 707 + #ifdef CONFIG_X86_ESPFIX32 706 708 /* fixup the stack */ 707 709 mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */ 708 710 mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */ ··· 713 713 pushl_cfi %eax 714 714 lss (%esp), %esp /* switch to the normal stack segment */ 715 715 CFI_ADJUST_CFA_OFFSET -8 716 + #endif 716 717 .endm 717 718 .macro UNWIND_ESPFIX_STACK 719 + #ifdef CONFIG_X86_ESPFIX32 718 720 movl %ss, %eax 719 721 /* see if on espfix stack */ 720 722 cmpw $__ESPFIX_SS, %ax ··· 727 725 /* switch to normal stack */ 728 726 FIXUP_ESPFIX_STACK 729 727 27: 728 + #endif 730 729 .endm 731 730 732 731 /* ··· 1358 1355 ENTRY(nmi) 1359 1356 RING0_INT_FRAME 1360 1357 ASM_CLAC 1358 + #ifdef CONFIG_X86_ESPFIX32 1361 1359 pushl_cfi %eax 1362 1360 movl %ss, %eax 1363 1361 cmpw $__ESPFIX_SS, %ax 1364 1362 popl_cfi %eax 1365 1363 je nmi_espfix_stack 1364 + #endif 1366 1365 cmpl $ia32_sysenter_target,(%esp) 1367 1366 je nmi_stack_fixup 1368 1367 pushl_cfi %eax ··· 1404 1399 FIX_STACK 24, nmi_stack_correct, 1 1405 1400 jmp nmi_stack_correct 1406 1401 1402 + #ifdef CONFIG_X86_ESPFIX32 1407 1403 nmi_espfix_stack: 1408 1404 /* We have a RING0_INT_FRAME here. 1409 1405 * ··· 1426 1420 lss 12+4(%esp), %esp # back to espfix stack 1427 1421 CFI_ADJUST_CFA_OFFSET -24 1428 1422 jmp irq_return 1423 + #endif 1429 1424 CFI_ENDPROC 1430 1425 END(nmi) 1431 1426
+77 -4
arch/x86/kernel/entry_64.S
··· 58 58 #include <asm/asm.h> 59 59 #include <asm/context_tracking.h> 60 60 #include <asm/smap.h> 61 + #include <asm/pgtable_types.h> 61 62 #include <linux/err.h> 62 63 63 64 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */ ··· 1041 1040 RESTORE_ARGS 1,8,1 1042 1041 1043 1042 irq_return: 1043 + /* 1044 + * Are we returning to a stack segment from the LDT? Note: in 1045 + * 64-bit mode SS:RSP on the exception stack is always valid. 1046 + */ 1047 + #ifdef CONFIG_X86_ESPFIX64 1048 + testb $4,(SS-RIP)(%rsp) 1049 + jnz irq_return_ldt 1050 + #endif 1051 + 1052 + irq_return_iret: 1044 1053 INTERRUPT_RETURN 1045 - _ASM_EXTABLE(irq_return, bad_iret) 1054 + _ASM_EXTABLE(irq_return_iret, bad_iret) 1046 1055 1047 1056 #ifdef CONFIG_PARAVIRT 1048 1057 ENTRY(native_iret) 1049 1058 iretq 1050 1059 _ASM_EXTABLE(native_iret, bad_iret) 1060 + #endif 1061 + 1062 + #ifdef CONFIG_X86_ESPFIX64 1063 + irq_return_ldt: 1064 + pushq_cfi %rax 1065 + pushq_cfi %rdi 1066 + SWAPGS 1067 + movq PER_CPU_VAR(espfix_waddr),%rdi 1068 + movq %rax,(0*8)(%rdi) /* RAX */ 1069 + movq (2*8)(%rsp),%rax /* RIP */ 1070 + movq %rax,(1*8)(%rdi) 1071 + movq (3*8)(%rsp),%rax /* CS */ 1072 + movq %rax,(2*8)(%rdi) 1073 + movq (4*8)(%rsp),%rax /* RFLAGS */ 1074 + movq %rax,(3*8)(%rdi) 1075 + movq (6*8)(%rsp),%rax /* SS */ 1076 + movq %rax,(5*8)(%rdi) 1077 + movq (5*8)(%rsp),%rax /* RSP */ 1078 + movq %rax,(4*8)(%rdi) 1079 + andl $0xffff0000,%eax 1080 + popq_cfi %rdi 1081 + orq PER_CPU_VAR(espfix_stack),%rax 1082 + SWAPGS 1083 + movq %rax,%rsp 1084 + popq_cfi %rax 1085 + jmp irq_return_iret 1051 1086 #endif 1052 1087 1053 1088 .section .fixup,"ax" ··· 1147 1110 call preempt_schedule_irq 1148 1111 jmp exit_intr 1149 1112 #endif 1150 - 1151 1113 CFI_ENDPROC 1152 1114 END(common_interrupt) 1115 + 1116 + /* 1117 + * If IRET takes a fault on the espfix stack, then we 1118 + * end up promoting it to a doublefault. In that case, 1119 + * modify the stack to make it look like we just entered 1120 + * the #GP handler from user space, similar to bad_iret. 1121 + */ 1122 + #ifdef CONFIG_X86_ESPFIX64 1123 + ALIGN 1124 + __do_double_fault: 1125 + XCPT_FRAME 1 RDI+8 1126 + movq RSP(%rdi),%rax /* Trap on the espfix stack? */ 1127 + sarq $PGDIR_SHIFT,%rax 1128 + cmpl $ESPFIX_PGD_ENTRY,%eax 1129 + jne do_double_fault /* No, just deliver the fault */ 1130 + cmpl $__KERNEL_CS,CS(%rdi) 1131 + jne do_double_fault 1132 + movq RIP(%rdi),%rax 1133 + cmpq $irq_return_iret,%rax 1134 + #ifdef CONFIG_PARAVIRT 1135 + je 1f 1136 + cmpq $native_iret,%rax 1137 + #endif 1138 + jne do_double_fault /* This shouldn't happen... */ 1139 + 1: 1140 + movq PER_CPU_VAR(kernel_stack),%rax 1141 + subq $(6*8-KERNEL_STACK_OFFSET),%rax /* Reset to original stack */ 1142 + movq %rax,RSP(%rdi) 1143 + movq $0,(%rax) /* Missing (lost) #GP error code */ 1144 + movq $general_protection,RIP(%rdi) 1145 + retq 1146 + CFI_ENDPROC 1147 + END(__do_double_fault) 1148 + #else 1149 + # define __do_double_fault do_double_fault 1150 + #endif 1151 + 1153 1152 /* 1154 1153 * End of kprobes section 1155 1154 */ ··· 1362 1289 idtentry bounds do_bounds has_error_code=0 1363 1290 idtentry invalid_op do_invalid_op has_error_code=0 1364 1291 idtentry device_not_available do_device_not_available has_error_code=0 1365 - idtentry double_fault do_double_fault has_error_code=1 paranoid=1 1292 + idtentry double_fault __do_double_fault has_error_code=1 paranoid=1 1366 1293 idtentry coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0 1367 1294 idtentry invalid_TSS do_invalid_TSS has_error_code=1 1368 1295 idtentry segment_not_present do_segment_not_present has_error_code=1 ··· 1649 1576 */ 1650 1577 error_kernelspace: 1651 1578 incl %ebx 1652 - leaq irq_return(%rip),%rcx 1579 + leaq irq_return_iret(%rip),%rcx 1653 1580 cmpq %rcx,RIP+8(%rsp) 1654 1581 je error_swapgs 1655 1582 movl %ecx,%eax /* zero extend */
+209
arch/x86/kernel/espfix_64.c
··· 1 + /* ----------------------------------------------------------------------- * 2 + * 3 + * Copyright 2014 Intel Corporation; author: H. Peter Anvin 4 + * 5 + * This program is free software; you can redistribute it and/or modify it 6 + * under the terms and conditions of the GNU General Public License, 7 + * version 2, as published by the Free Software Foundation. 8 + * 9 + * This program is distributed in the hope it will be useful, but WITHOUT 10 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 + * more details. 13 + * 14 + * ----------------------------------------------------------------------- */ 15 + 16 + /* 17 + * The IRET instruction, when returning to a 16-bit segment, only 18 + * restores the bottom 16 bits of the user space stack pointer. This 19 + * causes some 16-bit software to break, but it also leaks kernel state 20 + * to user space. 21 + * 22 + * This works around this by creating percpu "ministacks", each of which 23 + * is mapped 2^16 times 64K apart. When we detect that the return SS is 24 + * on the LDT, we copy the IRET frame to the ministack and use the 25 + * relevant alias to return to userspace. The ministacks are mapped 26 + * readonly, so if the IRET fault we promote #GP to #DF which is an IST 27 + * vector and thus has its own stack; we then do the fixup in the #DF 28 + * handler. 29 + * 30 + * This file sets up the ministacks and the related page tables. The 31 + * actual ministack invocation is in entry_64.S. 32 + */ 33 + 34 + #include <linux/init.h> 35 + #include <linux/init_task.h> 36 + #include <linux/kernel.h> 37 + #include <linux/percpu.h> 38 + #include <linux/gfp.h> 39 + #include <linux/random.h> 40 + #include <asm/pgtable.h> 41 + #include <asm/pgalloc.h> 42 + #include <asm/setup.h> 43 + #include <asm/espfix.h> 44 + 45 + /* 46 + * Note: we only need 6*8 = 48 bytes for the espfix stack, but round 47 + * it up to a cache line to avoid unnecessary sharing. 48 + */ 49 + #define ESPFIX_STACK_SIZE (8*8UL) 50 + #define ESPFIX_STACKS_PER_PAGE (PAGE_SIZE/ESPFIX_STACK_SIZE) 51 + 52 + /* There is address space for how many espfix pages? */ 53 + #define ESPFIX_PAGE_SPACE (1UL << (PGDIR_SHIFT-PAGE_SHIFT-16)) 54 + 55 + #define ESPFIX_MAX_CPUS (ESPFIX_STACKS_PER_PAGE * ESPFIX_PAGE_SPACE) 56 + #if CONFIG_NR_CPUS > ESPFIX_MAX_CPUS 57 + # error "Need more than one PGD for the ESPFIX hack" 58 + #endif 59 + 60 + #define PGALLOC_GFP (GFP_KERNEL | __GFP_NOTRACK | __GFP_REPEAT | __GFP_ZERO) 61 + 62 + /* This contains the *bottom* address of the espfix stack */ 63 + DEFINE_PER_CPU_READ_MOSTLY(unsigned long, espfix_stack); 64 + DEFINE_PER_CPU_READ_MOSTLY(unsigned long, espfix_waddr); 65 + 66 + /* Initialization mutex - should this be a spinlock? */ 67 + static DEFINE_MUTEX(espfix_init_mutex); 68 + 69 + /* Page allocation bitmap - each page serves ESPFIX_STACKS_PER_PAGE CPUs */ 70 + #define ESPFIX_MAX_PAGES DIV_ROUND_UP(CONFIG_NR_CPUS, ESPFIX_STACKS_PER_PAGE) 71 + static void *espfix_pages[ESPFIX_MAX_PAGES]; 72 + 73 + static __page_aligned_bss pud_t espfix_pud_page[PTRS_PER_PUD] 74 + __aligned(PAGE_SIZE); 75 + 76 + static unsigned int page_random, slot_random; 77 + 78 + /* 79 + * This returns the bottom address of the espfix stack for a specific CPU. 80 + * The math allows for a non-power-of-two ESPFIX_STACK_SIZE, in which case 81 + * we have to account for some amount of padding at the end of each page. 82 + */ 83 + static inline unsigned long espfix_base_addr(unsigned int cpu) 84 + { 85 + unsigned long page, slot; 86 + unsigned long addr; 87 + 88 + page = (cpu / ESPFIX_STACKS_PER_PAGE) ^ page_random; 89 + slot = (cpu + slot_random) % ESPFIX_STACKS_PER_PAGE; 90 + addr = (page << PAGE_SHIFT) + (slot * ESPFIX_STACK_SIZE); 91 + addr = (addr & 0xffffUL) | ((addr & ~0xffffUL) << 16); 92 + addr += ESPFIX_BASE_ADDR; 93 + return addr; 94 + } 95 + 96 + #define PTE_STRIDE (65536/PAGE_SIZE) 97 + #define ESPFIX_PTE_CLONES (PTRS_PER_PTE/PTE_STRIDE) 98 + #define ESPFIX_PMD_CLONES PTRS_PER_PMD 99 + #define ESPFIX_PUD_CLONES (65536/(ESPFIX_PTE_CLONES*ESPFIX_PMD_CLONES)) 100 + 101 + #define PGTABLE_PROT ((_KERNPG_TABLE & ~_PAGE_RW) | _PAGE_NX) 102 + 103 + static void init_espfix_random(void) 104 + { 105 + unsigned long rand; 106 + 107 + /* 108 + * This is run before the entropy pools are initialized, 109 + * but this is hopefully better than nothing. 110 + */ 111 + if (!arch_get_random_long(&rand)) { 112 + /* The constant is an arbitrary large prime */ 113 + rdtscll(rand); 114 + rand *= 0xc345c6b72fd16123UL; 115 + } 116 + 117 + slot_random = rand % ESPFIX_STACKS_PER_PAGE; 118 + page_random = (rand / ESPFIX_STACKS_PER_PAGE) 119 + & (ESPFIX_PAGE_SPACE - 1); 120 + } 121 + 122 + void __init init_espfix_bsp(void) 123 + { 124 + pgd_t *pgd_p; 125 + pteval_t ptemask; 126 + 127 + ptemask = __supported_pte_mask; 128 + 129 + /* Install the espfix pud into the kernel page directory */ 130 + pgd_p = &init_level4_pgt[pgd_index(ESPFIX_BASE_ADDR)]; 131 + pgd_populate(&init_mm, pgd_p, (pud_t *)espfix_pud_page); 132 + 133 + /* Randomize the locations */ 134 + init_espfix_random(); 135 + 136 + /* The rest is the same as for any other processor */ 137 + init_espfix_ap(); 138 + } 139 + 140 + void init_espfix_ap(void) 141 + { 142 + unsigned int cpu, page; 143 + unsigned long addr; 144 + pud_t pud, *pud_p; 145 + pmd_t pmd, *pmd_p; 146 + pte_t pte, *pte_p; 147 + int n; 148 + void *stack_page; 149 + pteval_t ptemask; 150 + 151 + /* We only have to do this once... */ 152 + if (likely(this_cpu_read(espfix_stack))) 153 + return; /* Already initialized */ 154 + 155 + cpu = smp_processor_id(); 156 + addr = espfix_base_addr(cpu); 157 + page = cpu/ESPFIX_STACKS_PER_PAGE; 158 + 159 + /* Did another CPU already set this up? */ 160 + stack_page = ACCESS_ONCE(espfix_pages[page]); 161 + if (likely(stack_page)) 162 + goto done; 163 + 164 + mutex_lock(&espfix_init_mutex); 165 + 166 + /* Did we race on the lock? */ 167 + stack_page = ACCESS_ONCE(espfix_pages[page]); 168 + if (stack_page) 169 + goto unlock_done; 170 + 171 + ptemask = __supported_pte_mask; 172 + 173 + pud_p = &espfix_pud_page[pud_index(addr)]; 174 + pud = *pud_p; 175 + if (!pud_present(pud)) { 176 + pmd_p = (pmd_t *)__get_free_page(PGALLOC_GFP); 177 + pud = __pud(__pa(pmd_p) | (PGTABLE_PROT & ptemask)); 178 + paravirt_alloc_pud(&init_mm, __pa(pmd_p) >> PAGE_SHIFT); 179 + for (n = 0; n < ESPFIX_PUD_CLONES; n++) 180 + set_pud(&pud_p[n], pud); 181 + } 182 + 183 + pmd_p = pmd_offset(&pud, addr); 184 + pmd = *pmd_p; 185 + if (!pmd_present(pmd)) { 186 + pte_p = (pte_t *)__get_free_page(PGALLOC_GFP); 187 + pmd = __pmd(__pa(pte_p) | (PGTABLE_PROT & ptemask)); 188 + paravirt_alloc_pmd(&init_mm, __pa(pte_p) >> PAGE_SHIFT); 189 + for (n = 0; n < ESPFIX_PMD_CLONES; n++) 190 + set_pmd(&pmd_p[n], pmd); 191 + } 192 + 193 + pte_p = pte_offset_kernel(&pmd, addr); 194 + stack_page = (void *)__get_free_page(GFP_KERNEL); 195 + pte = __pte(__pa(stack_page) | (__PAGE_KERNEL_RO & ptemask)); 196 + paravirt_alloc_pte(&init_mm, __pa(stack_page) >> PAGE_SHIFT); 197 + for (n = 0; n < ESPFIX_PTE_CLONES; n++) 198 + set_pte(&pte_p[n*PTE_STRIDE], pte); 199 + 200 + /* Job is done for this CPU and any CPU which shares this page */ 201 + ACCESS_ONCE(espfix_pages[page]) = stack_page; 202 + 203 + unlock_done: 204 + mutex_unlock(&espfix_init_mutex); 205 + done: 206 + this_cpu_write(espfix_stack, addr); 207 + this_cpu_write(espfix_waddr, (unsigned long)stack_page 208 + + (addr & ~PAGE_MASK)); 209 + }
+1 -9
arch/x86/kernel/ldt.c
··· 20 20 #include <asm/mmu_context.h> 21 21 #include <asm/syscalls.h> 22 22 23 - int sysctl_ldt16 = 0; 24 - 25 23 #ifdef CONFIG_SMP 26 24 static void flush_ldt(void *current_mm) 27 25 { ··· 229 231 } 230 232 } 231 233 232 - /* 233 - * On x86-64 we do not support 16-bit segments due to 234 - * IRET leaking the high bits of the kernel stack address. 235 - */ 236 - #ifdef CONFIG_X86_64 237 - if (!ldt_info.seg_32bit && !sysctl_ldt16) { 234 + if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) { 238 235 error = -EINVAL; 239 236 goto out_unlock; 240 237 } 241 - #endif 242 238 243 239 fill_ldt(&ldt, &ldt_info); 244 240 if (oldmode)
+7
arch/x86/kernel/smpboot.c
··· 244 244 check_tsc_sync_target(); 245 245 246 246 /* 247 + * Enable the espfix hack for this CPU 248 + */ 249 + #ifdef CONFIG_X86_ESPFIX64 250 + init_espfix_ap(); 251 + #endif 252 + 253 + /* 247 254 * We need to hold vector_lock so there the set of online cpus 248 255 * does not change while we are assigning vectors to cpus. Holding 249 256 * this lock ensures we don't half assign or remove an irq from a cpu.
+32 -10
arch/x86/mm/dump_pagetables.c
··· 30 30 unsigned long start_address; 31 31 unsigned long current_address; 32 32 const struct addr_marker *marker; 33 + unsigned long lines; 33 34 bool to_dmesg; 34 35 }; 35 36 36 37 struct addr_marker { 37 38 unsigned long start_address; 38 39 const char *name; 40 + unsigned long max_lines; 39 41 }; 40 42 41 43 /* indices for address_markers; keep sync'd w/ address_markers below */ ··· 48 46 LOW_KERNEL_NR, 49 47 VMALLOC_START_NR, 50 48 VMEMMAP_START_NR, 49 + ESPFIX_START_NR, 51 50 HIGH_KERNEL_NR, 52 51 MODULES_VADDR_NR, 53 52 MODULES_END_NR, ··· 71 68 { PAGE_OFFSET, "Low Kernel Mapping" }, 72 69 { VMALLOC_START, "vmalloc() Area" }, 73 70 { VMEMMAP_START, "Vmemmap" }, 71 + { ESPFIX_BASE_ADDR, "ESPfix Area", 16 }, 74 72 { __START_KERNEL_map, "High Kernel Mapping" }, 75 73 { MODULES_VADDR, "Modules" }, 76 74 { MODULES_END, "End Modules" }, ··· 186 182 pgprot_t new_prot, int level) 187 183 { 188 184 pgprotval_t prot, cur; 189 - static const char units[] = "KMGTPE"; 185 + static const char units[] = "BKMGTPE"; 190 186 191 187 /* 192 188 * If we have a "break" in the series, we need to flush the state that ··· 201 197 st->current_prot = new_prot; 202 198 st->level = level; 203 199 st->marker = address_markers; 200 + st->lines = 0; 204 201 pt_dump_seq_printf(m, st->to_dmesg, "---[ %s ]---\n", 205 202 st->marker->name); 206 203 } else if (prot != cur || level != st->level || ··· 213 208 /* 214 209 * Now print the actual finished series 215 210 */ 216 - pt_dump_seq_printf(m, st->to_dmesg, "0x%0*lx-0x%0*lx ", 217 - width, st->start_address, 218 - width, st->current_address); 211 + if (!st->marker->max_lines || 212 + st->lines < st->marker->max_lines) { 213 + pt_dump_seq_printf(m, st->to_dmesg, 214 + "0x%0*lx-0x%0*lx ", 215 + width, st->start_address, 216 + width, st->current_address); 219 217 220 - delta = (st->current_address - st->start_address) >> 10; 221 - while (!(delta & 1023) && unit[1]) { 222 - delta >>= 10; 223 - unit++; 218 + delta = st->current_address - st->start_address; 219 + while (!(delta & 1023) && unit[1]) { 220 + delta >>= 10; 221 + unit++; 222 + } 223 + pt_dump_cont_printf(m, st->to_dmesg, "%9lu%c ", 224 + delta, *unit); 225 + printk_prot(m, st->current_prot, st->level, 226 + st->to_dmesg); 224 227 } 225 - pt_dump_cont_printf(m, st->to_dmesg, "%9lu%c ", delta, *unit); 226 - printk_prot(m, st->current_prot, st->level, st->to_dmesg); 228 + st->lines++; 227 229 228 230 /* 229 231 * We print markers for special areas of address space, ··· 238 226 * This helps in the interpretation. 239 227 */ 240 228 if (st->current_address >= st->marker[1].start_address) { 229 + if (st->marker->max_lines && 230 + st->lines > st->marker->max_lines) { 231 + unsigned long nskip = 232 + st->lines - st->marker->max_lines; 233 + pt_dump_seq_printf(m, st->to_dmesg, 234 + "... %lu entr%s skipped ... \n", 235 + nskip, 236 + nskip == 1 ? "y" : "ies"); 237 + } 241 238 st->marker++; 239 + st->lines = 0; 242 240 pt_dump_seq_printf(m, st->to_dmesg, "---[ %s ]---\n", 243 241 st->marker->name); 244 242 }
-8
arch/x86/vdso/vdso32-setup.c
··· 39 39 #ifdef CONFIG_X86_64 40 40 #define vdso_enabled sysctl_vsyscall32 41 41 #define arch_setup_additional_pages syscall32_setup_pages 42 - extern int sysctl_ldt16; 43 42 #endif 44 43 45 44 /* ··· 245 246 { 246 247 .procname = "vsyscall32", 247 248 .data = &sysctl_vsyscall32, 248 - .maxlen = sizeof(int), 249 - .mode = 0644, 250 - .proc_handler = proc_dointvec 251 - }, 252 - { 253 - .procname = "ldt16", 254 - .data = &sysctl_ldt16, 255 249 .maxlen = sizeof(int), 256 250 .mode = 0644, 257 251 .proc_handler = proc_dointvec
+4
init/main.c
··· 617 617 if (efi_enabled(EFI_RUNTIME_SERVICES)) 618 618 efi_enter_virtual_mode(); 619 619 #endif 620 + #ifdef CONFIG_X86_ESPFIX64 621 + /* Should be run before the first non-init thread is created */ 622 + init_espfix_bsp(); 623 + #endif 620 624 thread_info_cache_init(); 621 625 cred_init(); 622 626 fork_init(totalram_pages);