s390: add no-execute support
Bit 0x100 of a page table, segment table of region table entry can be used to disallow code execution for the virtual addresses associated with the entry. There is one tricky bit, the system call to return from a signal is part of the signal frame written to the user stack. With a non-executable stack this would stop working. To avoid breaking things the protection fault handler checks the opcode that caused the fault for 0x0a77 (sys_sigreturn) and 0x0aad (sys_rt_sigreturn) and injects a system call. This is preferable to the alternative solution with a stub function in the vdso because it works for vdso=off and statically linked binaries as well. Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
This commit is contained in:
@@ -59,6 +59,8 @@ static inline unsigned long __pte_to_rste(pte_t pte)
|
||||
rste |= move_set_bit(pte_val(pte), _PAGE_SOFT_DIRTY,
|
||||
_SEGMENT_ENTRY_SOFT_DIRTY);
|
||||
#endif
|
||||
rste |= move_set_bit(pte_val(pte), _PAGE_NOEXEC,
|
||||
_SEGMENT_ENTRY_NOEXEC);
|
||||
} else
|
||||
rste = _SEGMENT_ENTRY_INVALID;
|
||||
return rste;
|
||||
@@ -113,6 +115,8 @@ static inline pte_t __rste_to_pte(unsigned long rste)
|
||||
pte_val(pte) |= move_set_bit(rste, _SEGMENT_ENTRY_SOFT_DIRTY,
|
||||
_PAGE_DIRTY);
|
||||
#endif
|
||||
pte_val(pte) |= move_set_bit(rste, _SEGMENT_ENTRY_NOEXEC,
|
||||
_PAGE_NOEXEC);
|
||||
} else
|
||||
pte_val(pte) = _PAGE_INVALID;
|
||||
return pte;
|
||||
@@ -121,7 +125,11 @@ static inline pte_t __rste_to_pte(unsigned long rste)
|
||||
void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
|
||||
pte_t *ptep, pte_t pte)
|
||||
{
|
||||
unsigned long rste = __pte_to_rste(pte);
|
||||
unsigned long rste;
|
||||
|
||||
rste = __pte_to_rste(pte);
|
||||
if (!MACHINE_HAS_NX)
|
||||
rste &= ~_SEGMENT_ENTRY_NOEXEC;
|
||||
|
||||
/* Set correct table type for 2G hugepages */
|
||||
if ((pte_val(*ptep) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3)
|
||||
|
Reference in New Issue
Block a user