History

Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 fixes from Ingo Molnar: "The biggest diffstat comes from self-test updates, plus there's entry code fixes, 5-level paging related fixes, console debug output fixes, and misc fixes" * 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/mm: Clean up the printk()s in show_fault_oops() x86/mm: Drop unneeded __always_inline for p4d page table helpers x86/efi: Fix efi_call_phys_epilog() with CONFIG_X86_5LEVEL=y selftests/x86/sigreturn: Do minor cleanups selftests/x86/sigreturn/64: Fix spurious failures on AMD CPUs x86/entry/64/compat: Fix "x86/entry/64/compat: Preserve r8-r11 in int $0x80" x86/mm: Don't free P4D table when it is folded at runtime x86/entry/32: Add explicit 'l' instruction suffix x86/mm: Get rid of KERN_CONT in show_fault_oops()

Linus Torvalds committed 8 years ago

Commit 0fbc4ae2 parents d7d5388 d79d0d88 files · +60 −51Browse files

Unified · Split

8 files
  1. arch/x86/entry/entry_32.S +1 −1
  2. arch/x86/entry/entry_64_compat.S +8 −8
  3. arch/x86/include/asm/pgalloc.h +3 −0
  4. arch/x86/include/asm/pgtable.h +1 −1
  5. arch/x86/include/asm/pgtable_64.h +2 −2
  6. arch/x86/mm/fault.c +7 −14
  7. arch/x86/platform/efi/efi_64.c +2 −2
  8. tools/testing/selftests/x86/sigreturn.c +36 −23
arch/x86/entry/entry_32.S+1−1
@@ -477,7 +477,7 @@ ENTRY(entry_SYSENTER_32) · 476 unmodified lines
477477 * whereas POPF does not.)
478478 */
479479 addl $PT_EFLAGS-PT_DS, %esp /* point esp at pt_regs->flags */
480− btr $X86_EFLAGS_IF_BIT, (%esp)
480+ btrl $X86_EFLAGS_IF_BIT, (%esp)
481481 popfl
482482
483483 /*
arch/x86/entry/entry_64_compat.S+8−8
@@ -84,13 +84,13 @@ ENTRY(entry_SYSENTER_compat) · 83 unmodified lines
8484 pushq %rdx /* pt_regs->dx */
8585 pushq %rcx /* pt_regs->cx */
8686 pushq $-ENOSYS /* pt_regs->ax */
87− pushq %r8 /* pt_regs->r8 */
87+ pushq $0 /* pt_regs->r8 = 0 */
8888 xorl %r8d, %r8d /* nospec r8 */
89− pushq %r9 /* pt_regs->r9 */
89+ pushq $0 /* pt_regs->r9 = 0 */
9090 xorl %r9d, %r9d /* nospec r9 */
91− pushq %r10 /* pt_regs->r10 */
91+ pushq $0 /* pt_regs->r10 = 0 */
9292 xorl %r10d, %r10d /* nospec r10 */
93− pushq %r11 /* pt_regs->r11 */
93+ pushq $0 /* pt_regs->r11 = 0 */
9494 xorl %r11d, %r11d /* nospec r11 */
9595 pushq %rbx /* pt_regs->rbx */
9696 xorl %ebx, %ebx /* nospec rbx */
@@ -374,13 +374,13 @@ ENTRY(entry_INT80_compat) · 277 unmodified lines
374374 pushq %rcx /* pt_regs->cx */
375375 xorl %ecx, %ecx /* nospec cx */
376376 pushq $-ENOSYS /* pt_regs->ax */
377− pushq $0 /* pt_regs->r8 = 0 */
377+ pushq %r8 /* pt_regs->r8 */
378378 xorl %r8d, %r8d /* nospec r8 */
379− pushq $0 /* pt_regs->r9 = 0 */
379+ pushq %r9 /* pt_regs->r9 */
380380 xorl %r9d, %r9d /* nospec r9 */
381− pushq $0 /* pt_regs->r10 = 0 */
381+ pushq %r10 /* pt_regs->r10*/
382382 xorl %r10d, %r10d /* nospec r10 */
383− pushq $0 /* pt_regs->r11 = 0 */
383+ pushq %r11 /* pt_regs->r11 */
384384 xorl %r11d, %r11d /* nospec r11 */
385385 pushq %rbx /* pt_regs->rbx */
386386 xorl %ebx, %ebx /* nospec rbx */
arch/x86/include/asm/pgalloc.h+3−0
@@ -184,6 +184,9 @@ static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr) · 183 unmodified lines
184184
185185 static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d)
186186 {
187+ if (!pgtable_l5_enabled())
188+ return;
189+
187190 BUG_ON((unsigned long)p4d & (PAGE_SIZE-1));
188191 free_page((unsigned long)p4d);
189192 }
arch/x86/include/asm/pgtable.h+1−1
@@ -898,7 +898,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd) · 897 unmodified lines
898898 #define pgd_page(pgd) pfn_to_page(pgd_pfn(pgd))
899899
900900 /* to find an entry in a page-table-directory. */
901−static __always_inline p4d_t *p4d_offset(pgd_t *pgd, unsigned long address)
901+static inline p4d_t *p4d_offset(pgd_t *pgd, unsigned long address)
902902 {
903903 if (!pgtable_l5_enabled())
904904 return (p4d_t *)pgd;
arch/x86/include/asm/pgtable_64.h+2−2
@@ -216,7 +216,7 @@ static inline pgd_t pti_set_user_pgd(pgd_t *pgdp, pgd_t pgd) · 215 unmodified lines
216216 }
217217 #endif
218218
219−static __always_inline void native_set_p4d(p4d_t *p4dp, p4d_t p4d)
219+static inline void native_set_p4d(p4d_t *p4dp, p4d_t p4d)
220220 {
221221 pgd_t pgd;
222222
@@ -230,7 +230,7 @@ static __always_inline void native_set_p4d(p4d_t *p4dp, p4d_t p4d) · 7 unmodified lines
230230 *p4dp = native_make_p4d(native_pgd_val(pgd));
231231 }
232232
233−static __always_inline void native_p4d_clear(p4d_t *p4d)
233+static inline void native_p4d_clear(p4d_t *p4d)
234234 {
235235 native_set_p4d(p4d, native_make_p4d(0));
236236 }
arch/x86/mm/fault.c+7−14
@@ -641,11 +641,6 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address) · 640 unmodified lines
641641 return 0;
642642 }
643643
644−static const char nx_warning[] = KERN_CRIT
645−"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
646−static const char smep_warning[] = KERN_CRIT
647−"unable to execute userspace code (SMEP?) (uid: %d)\n";
648−
649644 static void
650645 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
651646 unsigned long address)
@@ -664,20 +659,18 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code, · 12 unmodified lines
664659 pte = lookup_address_in_pgd(pgd, address, &level);
665660
666661 if (pte && pte_present(*pte) && !pte_exec(*pte))
667− printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
662+ pr_crit("kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n",
663+ from_kuid(&init_user_ns, current_uid()));
668664 if (pte && pte_present(*pte) && pte_exec(*pte) &&
669665 (pgd_flags(*pgd) & _PAGE_USER) &&
670666 (__read_cr4() & X86_CR4_SMEP))
671− printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
667+ pr_crit("unable to execute userspace code (SMEP?) (uid: %d)\n",
668+ from_kuid(&init_user_ns, current_uid()));
672669 }
673670
674− printk(KERN_ALERT "BUG: unable to handle kernel ");
675− if (address < PAGE_SIZE)
676− printk(KERN_CONT "NULL pointer dereference");
677− else
678− printk(KERN_CONT "paging request");
679−
680− printk(KERN_CONT " at %px\n", (void *) address);
671+ pr_alert("BUG: unable to handle kernel %s at %px\n",
672+ address < PAGE_SIZE ? "NULL pointer dereference" : "paging request",
673+ (void *)address);
681674
682675 dump_pagetable(address);
683676 }
arch/x86/platform/efi/efi_64.c+2−2
@@ -166,14 +166,14 @@ void __init efi_call_phys_epilog(pgd_t *save_pgd) · 165 unmodified lines
166166 pgd = pgd_offset_k(pgd_idx * PGDIR_SIZE);
167167 set_pgd(pgd_offset_k(pgd_idx * PGDIR_SIZE), save_pgd[pgd_idx]);
168168
169− if (!(pgd_val(*pgd) & _PAGE_PRESENT))
169+ if (!pgd_present(*pgd))
170170 continue;
171171
172172 for (i = 0; i < PTRS_PER_P4D; i++) {
173173 p4d = p4d_offset(pgd,
174174 pgd_idx * PGDIR_SIZE + i * P4D_SIZE);
175175
176− if (!(p4d_val(*p4d) & _PAGE_PRESENT))
176+ if (!p4d_present(*p4d))
177177 continue;
178178
179179 pud = (pud_t *)p4d_page_vaddr(*p4d);
tools/testing/selftests/x86/sigreturn.c+36−23
@@ -610,21 +610,41 @@ static int test_valid_sigreturn(int cs_bits, bool use_16bit_ss, int force_ss) · 609 unmodified lines
610610 */
611611 for (int i = 0; i < NGREG; i++) {
612612 greg_t req = requested_regs[i], res = resulting_regs[i];
613+
613614 if (i == REG_TRAPNO || i == REG_IP)
614615 continue; /* don't care */
615− if (i == REG_SP) {
616− printf("\tSP: %llx -> %llx\n", (unsigned long long)req,
617− (unsigned long long)res);
618616
617+ if (i == REG_SP) {
619618 /*
620− * In many circumstances, the high 32 bits of rsp
621− * are zeroed. For example, we could be a real
622− * 32-bit program, or we could hit any of a number
623− * of poorly-documented IRET or segmented ESP
624− * oddities. If this happens, it's okay.
619+ * If we were using a 16-bit stack segment, then
620+ * the kernel is a bit stuck: IRET only restores
621+ * the low 16 bits of ESP/RSP if SS is 16-bit.
622+ * The kernel uses a hack to restore bits 31:16,
623+ * but that hack doesn't help with bits 63:32.
624+ * On Intel CPUs, bits 63:32 end up zeroed, and, on
625+ * AMD CPUs, they leak the high bits of the kernel
626+ * espfix64 stack pointer. There's very little that
627+ * the kernel can do about it.
628+ *
629+ * Similarly, if we are returning to a 32-bit context,
630+ * the CPU will often lose the high 32 bits of RSP.
625631 */
626− if (res == (req & 0xFFFFFFFF))
627− continue; /* OK; not expected to work */
632+
633+ if (res == req)
634+ continue;
635+
636+ if (cs_bits != 64 && ((res ^ req) & 0xFFFFFFFF) == 0) {
637+ printf("[NOTE]\tSP: %llx -> %llx\n",
638+ (unsigned long long)req,
639+ (unsigned long long)res);
640+ continue;
641+ }
642+
643+ printf("[FAIL]\tSP mismatch: requested 0x%llx; got 0x%llx\n",
644+ (unsigned long long)requested_regs[i],
645+ (unsigned long long)resulting_regs[i]);
646+ nerrs++;
647+ continue;
628648 }
629649
630650 bool ignore_reg = false;
@@ -654,25 +674,18 @@ static int test_valid_sigreturn(int cs_bits, bool use_16bit_ss, int force_ss) · 23 unmodified lines
654674 #endif
655675
656676 /* Sanity check on the kernel */
657− if (i == REG_CX && requested_regs[i] != resulting_regs[i]) {
677+ if (i == REG_CX && req != res) {
658678 printf("[FAIL]\tCX (saved SP) mismatch: requested 0x%llx; got 0x%llx\n",
659− (unsigned long long)requested_regs[i],
660− (unsigned long long)resulting_regs[i]);
679+ (unsigned long long)req,
680+ (unsigned long long)res);
661681 nerrs++;
662682 continue;
663683 }
664684
665− if (requested_regs[i] != resulting_regs[i] && !ignore_reg) {
666− /*
667− * SP is particularly interesting here. The
668− * usual cause of failures is that we hit the
669− * nasty IRET case of returning to a 16-bit SS,
670− * in which case bits 16:31 of the *kernel*
671− * stack pointer persist in ESP.
672− */
685+ if (req != res && !ignore_reg) {
673686 printf("[FAIL]\tReg %d mismatch: requested 0x%llx; got 0x%llx\n",
674− i, (unsigned long long)requested_regs[i],
675− (unsigned long long)resulting_regs[i]);
687+ i, (unsigned long long)req,
688+ (unsigned long long)res);
676689 nerrs++;
677690 }
678691 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t