Skip to content

Commit

Permalink
Merge tag 'x86-urgent-2021-09-26' of git://git.kernel.org/pub/scm/lin…
Browse files Browse the repository at this point in the history
…ux/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
  • Loading branch information
torvalds committed Sep 26, 2021
2 parents 3a398ac + 5ba1071 commit 5bb7b21
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 27 deletions.
2 changes: 0 additions & 2 deletions arch/x86/include/asm/pkeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#ifndef _ASM_X86_PKEYS_H
#define _ASM_X86_PKEYS_H

#define ARCH_DEFAULT_PKEY 0

/*
* If more than 16 keys are ever supported, a thorough audit
* will be necessary to ensure that the types that store key
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/asm/special_insns.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ static inline int enqcmds(void __iomem *dst, const void *src)
{
const struct { char _[64]; } *__src = src;
struct { char _[64]; } __iomem *__dst = dst;
int zf;
bool zf;

/*
* ENQCMDS %(rdx), rax
Expand Down
26 changes: 14 additions & 12 deletions arch/x86/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,20 @@ void __init setup_arch(char **cmdline_p)

x86_init.oem.arch_setup();

/*
* Do some memory reservations *before* memory is added to memblock, so
* memblock allocations won't overwrite it.
*
* After this point, everything still needed from the boot loader or
* firmware or kernel text should be early reserved or marked not RAM in
* e820. All other memory is free game.
*
* This call needs to happen before e820__memory_setup() which calls the
* xen_memory_setup() on Xen dom0 which relies on the fact that those
* early reservations have happened already.
*/
early_reserve_memory();

iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
e820__memory_setup();
parse_setup_data();
Expand Down Expand Up @@ -876,18 +890,6 @@ void __init setup_arch(char **cmdline_p)

parse_early_param();

/*
* Do some memory reservations *before* memory is added to
* memblock, so memblock allocations won't overwrite it.
* Do it after early param, so we could get (unlikely) panic from
* serial.
*
* After this point everything still needed from the boot loader or
* firmware or kernel text should be early reserved or marked not
* RAM in e820. All other memory is free game.
*/
early_reserve_memory();

#ifdef CONFIG_MEMORY_HOTPLUG
/*
* Memory used by the kernel cannot be hot-removed because Linux
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/lib/insn.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)

#define __get_next(t, insn) \
({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); leXX_to_cpu(t, r); })
({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); })

#define __peek_nbyte_next(t, insn, n) \
({ t r = *(t*)((insn)->next_byte + n); leXX_to_cpu(t, r); })
({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); })

#define get_next(t, insn) \
({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })
Expand Down
26 changes: 18 additions & 8 deletions arch/x86/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,8 @@ page_fault_oops(struct pt_regs *regs, unsigned long error_code,

static noinline void
kernelmode_fixup_or_oops(struct pt_regs *regs, unsigned long error_code,
unsigned long address, int signal, int si_code)
unsigned long address, int signal, int si_code,
u32 pkey)
{
WARN_ON_ONCE(user_mode(regs));

Expand All @@ -735,8 +736,12 @@ kernelmode_fixup_or_oops(struct pt_regs *regs, unsigned long error_code,

set_signal_archinfo(address, error_code);

/* XXX: hwpoison faults will set the wrong code. */
force_sig_fault(signal, si_code, (void __user *)address);
if (si_code == SEGV_PKUERR) {
force_sig_pkuerr((void __user *)address, pkey);
} else {
/* XXX: hwpoison faults will set the wrong code. */
force_sig_fault(signal, si_code, (void __user *)address);
}
}

/*
Expand Down Expand Up @@ -798,7 +803,8 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
struct task_struct *tsk = current;

if (!user_mode(regs)) {
kernelmode_fixup_or_oops(regs, error_code, address, pkey, si_code);
kernelmode_fixup_or_oops(regs, error_code, address,
SIGSEGV, si_code, pkey);
return;
}

Expand Down Expand Up @@ -930,7 +936,8 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
{
/* Kernel mode? Handle exceptions or die: */
if (!user_mode(regs)) {
kernelmode_fixup_or_oops(regs, error_code, address, SIGBUS, BUS_ADRERR);
kernelmode_fixup_or_oops(regs, error_code, address,
SIGBUS, BUS_ADRERR, ARCH_DEFAULT_PKEY);
return;
}

Expand Down Expand Up @@ -1396,7 +1403,8 @@ void do_user_addr_fault(struct pt_regs *regs,
*/
if (!user_mode(regs))
kernelmode_fixup_or_oops(regs, error_code, address,
SIGBUS, BUS_ADRERR);
SIGBUS, BUS_ADRERR,
ARCH_DEFAULT_PKEY);
return;
}

Expand All @@ -1416,15 +1424,17 @@ void do_user_addr_fault(struct pt_regs *regs,
return;

if (fatal_signal_pending(current) && !user_mode(regs)) {
kernelmode_fixup_or_oops(regs, error_code, address, 0, 0);
kernelmode_fixup_or_oops(regs, error_code, address,
0, 0, ARCH_DEFAULT_PKEY);
return;
}

if (fault & VM_FAULT_OOM) {
/* Kernel mode? Handle exceptions or die: */
if (!user_mode(regs)) {
kernelmode_fixup_or_oops(regs, error_code, address,
SIGSEGV, SEGV_MAPERR);
SIGSEGV, SEGV_MAPERR,
ARCH_DEFAULT_PKEY);
return;
}

Expand Down
2 changes: 2 additions & 0 deletions include/linux/pkeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <linux/mm.h>

#define ARCH_DEFAULT_PKEY 0

#ifdef CONFIG_ARCH_HAS_PKEYS
#include <asm/pkeys.h>
#else /* ! CONFIG_ARCH_HAS_PKEYS */
Expand Down
4 changes: 2 additions & 2 deletions tools/arch/x86/lib/insn.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)

#define __get_next(t, insn) \
({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); leXX_to_cpu(t, r); })
({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); })

#define __peek_nbyte_next(t, insn, n) \
({ t r = *(t*)((insn)->next_byte + n); leXX_to_cpu(t, r); })
({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); })

#define get_next(t, insn) \
({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })
Expand Down

0 comments on commit 5bb7b21

Please sign in to comment.