Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions arch/x86/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,13 @@ show_signal_msg(struct pt_regs *regs, unsigned long error_code,
show_opcodes(regs, loglvl);
}

#ifdef CONFIG_OPENPAX_EMUTRAMP
static inline bool openpax_fault_is_trampoline(unsigned long error_code,
struct pt_regs *regs,
unsigned long address);
static inline bool openpax_emulate_trampoline(struct pt_regs *regs);
#endif

static void
__bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
unsigned long address, u32 pkey, int si_code)
Expand All @@ -806,6 +813,19 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
*/
local_irq_enable();

#ifdef CONFIG_OPENPAX_EMUTRAMP
/*
* A trampoline in non-executable memory is an instruction fetch the
* task's mappings do not permit, so it is only here, with the fault
* otherwise about to become SIGSEGV, that one can be emulated. A
* fetch from executable memory that merely needs its page brought
* in is resolved as an ordinary fault above and never reaches this.
*/
if (openpax_fault_is_trampoline(error_code, regs, address) &&
openpax_emulate_trampoline(regs))
return;
#endif

/*
* Valid to do another page fault here because this one came
* from user space:
Expand Down Expand Up @@ -1554,13 +1574,6 @@ void do_user_addr_fault(struct pt_regs *regs,
}
#endif

#ifdef CONFIG_OPENPAX_EMUTRAMP
if (openpax_fault_is_trampoline(error_code, regs, address)) {
if (openpax_emulate_trampoline(regs))
return;
}
#endif

if (!(flags & FAULT_FLAG_USER))
goto lock_mmap;

Expand Down
14 changes: 14 additions & 0 deletions mm/vma.c
Original file line number Diff line number Diff line change
Expand Up @@ -3024,6 +3024,20 @@ int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *vma,
vma_flags_set(&vma_flags, VMA_ACCOUNT_BIT);
vma_flags_set_mask(&vma_flags, mm->def_vma_flags);

#ifdef CONFIG_OPENPAX_MPROTECT
/*
* Under MPROTECT the brk area is never executable. Its only routes
* to VM_EXEC are READ_IMPLIES_EXEC, which personality(2) lets any
* task set for itself, and the ELF loader's vm_brk_flags() for the
* bss of an executable segment. Every other path refuses the
* resulting writable and executable mapping in map_deny_write_exec();
* strip the execute bits here rather than fail, as PaX did, so brk(2)
* keeps working for such tasks.
*/
if (test_bit(PAXF_MPROTECT, &mm->pax_flags))
vma_flags_clear(&vma_flags, VMA_EXEC_BIT, VMA_MAYEXEC_BIT);
#endif

vma_flags = ksm_vma_flags(mm, NULL, vma_flags);
if (!may_expand_vm(mm, &vma_flags, len >> PAGE_SHIFT))
return -ENOMEM;
Expand Down
11 changes: 8 additions & 3 deletions security/Kconfig.openpax
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,20 @@ config OPENPAX_EMUTRAMP
config OPENPAX_EMUTRAMP_DEFAULT
bool "Enable trampoline emulation by default"
depends on OPENPAX_EMUTRAMP
default y
default n
help
Enabling this option allows programs which require
trampolines to be emulated to continue working by default.

Otherwise, the emulation flag must be enabled in a binary's
PaX marking, e.g. with paxmark -E <binary>.

If you do not say 'y' here, you will have to manually mark
all programs which require trampoline emulation.
Trampoline emulation lets a task load fixed values into two
registers and jump to an arbitrary address from any readable
memory, without that memory being executable. Enabling it
for every program weakens PAGEEXEC and MPROTECT for all of
them, so prefer marking only the programs which need it.

If unsure, say 'n'.

endmenu
Loading