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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'x86-urgent-2021-09-26' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 fixes from Thomas Gleixner:
"A set of fixes for X86:

- Prevent sending the wrong signal when protection keys are enabled
and the kernel handles a fault in the vsyscall emulation.

- Invoke early_reserve_memory() before invoking e820_memory_setup()
which is required to make the Xen dom0 e820 hooks work correctly.

- Use the correct data type for the SETZ operand in the EMQCMDS
instruction wrapper.

- Prevent undefined behaviour to the potential unaligned accesss in
the instruction decoder library"

* tag 'x86-urgent-2021-09-26' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
x86/insn, tools/x86: Fix undefined behavior due to potential unaligned accesses
x86/asm: Fix SETZ size enqcmds() build failure
x86/setup: Call early_reserve_memory() earlier
x86/fault: Fix wrong signal when vsyscall fails with pkey

+39 -27
-2
arch/x86/include/asm/pkeys.h
··· 2 2 #ifndef _ASM_X86_PKEYS_H 3 3 #define _ASM_X86_PKEYS_H 4 4 5 - #define ARCH_DEFAULT_PKEY 0 6 - 7 5 /* 8 6 * If more than 16 keys are ever supported, a thorough audit 9 7 * will be necessary to ensure that the types that store key
+1 -1
arch/x86/include/asm/special_insns.h
··· 275 275 { 276 276 const struct { char _[64]; } *__src = src; 277 277 struct { char _[64]; } __iomem *__dst = dst; 278 - int zf; 278 + bool zf; 279 279 280 280 /* 281 281 * ENQCMDS %(rdx), rax
+14 -12
arch/x86/kernel/setup.c
··· 830 830 831 831 x86_init.oem.arch_setup(); 832 832 833 + /* 834 + * Do some memory reservations *before* memory is added to memblock, so 835 + * memblock allocations won't overwrite it. 836 + * 837 + * After this point, everything still needed from the boot loader or 838 + * firmware or kernel text should be early reserved or marked not RAM in 839 + * e820. All other memory is free game. 840 + * 841 + * This call needs to happen before e820__memory_setup() which calls the 842 + * xen_memory_setup() on Xen dom0 which relies on the fact that those 843 + * early reservations have happened already. 844 + */ 845 + early_reserve_memory(); 846 + 833 847 iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1; 834 848 e820__memory_setup(); 835 849 parse_setup_data(); ··· 889 875 x86_configure_nx(); 890 876 891 877 parse_early_param(); 892 - 893 - /* 894 - * Do some memory reservations *before* memory is added to 895 - * memblock, so memblock allocations won't overwrite it. 896 - * Do it after early param, so we could get (unlikely) panic from 897 - * serial. 898 - * 899 - * After this point everything still needed from the boot loader or 900 - * firmware or kernel text should be early reserved or marked not 901 - * RAM in e820. All other memory is free game. 902 - */ 903 - early_reserve_memory(); 904 878 905 879 #ifdef CONFIG_MEMORY_HOTPLUG 906 880 /*
+2 -2
arch/x86/lib/insn.c
··· 37 37 ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr) 38 38 39 39 #define __get_next(t, insn) \ 40 - ({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) 40 + ({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) 41 41 42 42 #define __peek_nbyte_next(t, insn, n) \ 43 - ({ t r = *(t*)((insn)->next_byte + n); leXX_to_cpu(t, r); }) 43 + ({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); }) 44 44 45 45 #define get_next(t, insn) \ 46 46 ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })
+18 -8
arch/x86/mm/fault.c
··· 710 710 711 711 static noinline void 712 712 kernelmode_fixup_or_oops(struct pt_regs *regs, unsigned long error_code, 713 - unsigned long address, int signal, int si_code) 713 + unsigned long address, int signal, int si_code, 714 + u32 pkey) 714 715 { 715 716 WARN_ON_ONCE(user_mode(regs)); 716 717 ··· 736 735 737 736 set_signal_archinfo(address, error_code); 738 737 739 - /* XXX: hwpoison faults will set the wrong code. */ 740 - force_sig_fault(signal, si_code, (void __user *)address); 738 + if (si_code == SEGV_PKUERR) { 739 + force_sig_pkuerr((void __user *)address, pkey); 740 + } else { 741 + /* XXX: hwpoison faults will set the wrong code. */ 742 + force_sig_fault(signal, si_code, (void __user *)address); 743 + } 741 744 } 742 745 743 746 /* ··· 803 798 struct task_struct *tsk = current; 804 799 805 800 if (!user_mode(regs)) { 806 - kernelmode_fixup_or_oops(regs, error_code, address, pkey, si_code); 801 + kernelmode_fixup_or_oops(regs, error_code, address, 802 + SIGSEGV, si_code, pkey); 807 803 return; 808 804 } 809 805 ··· 936 930 { 937 931 /* Kernel mode? Handle exceptions or die: */ 938 932 if (!user_mode(regs)) { 939 - kernelmode_fixup_or_oops(regs, error_code, address, SIGBUS, BUS_ADRERR); 933 + kernelmode_fixup_or_oops(regs, error_code, address, 934 + SIGBUS, BUS_ADRERR, ARCH_DEFAULT_PKEY); 940 935 return; 941 936 } 942 937 ··· 1403 1396 */ 1404 1397 if (!user_mode(regs)) 1405 1398 kernelmode_fixup_or_oops(regs, error_code, address, 1406 - SIGBUS, BUS_ADRERR); 1399 + SIGBUS, BUS_ADRERR, 1400 + ARCH_DEFAULT_PKEY); 1407 1401 return; 1408 1402 } 1409 1403 ··· 1424 1416 return; 1425 1417 1426 1418 if (fatal_signal_pending(current) && !user_mode(regs)) { 1427 - kernelmode_fixup_or_oops(regs, error_code, address, 0, 0); 1419 + kernelmode_fixup_or_oops(regs, error_code, address, 1420 + 0, 0, ARCH_DEFAULT_PKEY); 1428 1421 return; 1429 1422 } 1430 1423 ··· 1433 1424 /* Kernel mode? Handle exceptions or die: */ 1434 1425 if (!user_mode(regs)) { 1435 1426 kernelmode_fixup_or_oops(regs, error_code, address, 1436 - SIGSEGV, SEGV_MAPERR); 1427 + SIGSEGV, SEGV_MAPERR, 1428 + ARCH_DEFAULT_PKEY); 1437 1429 return; 1438 1430 } 1439 1431
+2
include/linux/pkeys.h
··· 4 4 5 5 #include <linux/mm.h> 6 6 7 + #define ARCH_DEFAULT_PKEY 0 8 + 7 9 #ifdef CONFIG_ARCH_HAS_PKEYS 8 10 #include <asm/pkeys.h> 9 11 #else /* ! CONFIG_ARCH_HAS_PKEYS */
+2 -2
tools/arch/x86/lib/insn.c
··· 37 37 ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr) 38 38 39 39 #define __get_next(t, insn) \ 40 - ({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) 40 + ({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) 41 41 42 42 #define __peek_nbyte_next(t, insn, n) \ 43 - ({ t r = *(t*)((insn)->next_byte + n); leXX_to_cpu(t, r); }) 43 + ({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); }) 44 44 45 45 #define get_next(t, insn) \ 46 46 ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })