Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c1821c2e authored by Gerald Schaefer's avatar Gerald Schaefer Committed by Martin Schwidefsky
Browse files

[S390] noexec protection



This provides a noexec protection on s390 hardware. Our hardware does
not have any bits left in the pte for a hw noexec bit, so this is a
different approach using shadow page tables and a special addressing
mode that allows separate address spaces for code and data.

As a special feature of our "secondary-space" addressing mode, separate
page tables can be specified for the translation of data addresses
(storage operands) and instruction addresses. The shadow page table is
used for the instruction addresses and the standard page table for the
data addresses.
The shadow page table is linked to the standard page table by a pointer
in page->lru.next of the struct page corresponding to the page that
contains the standard page table (since page->private is not really
private with the pte_lock and the page table pages are not in the LRU
list).
Depending on the software bits of a pte, it is either inserted into
both page tables or just into the standard (data) page table. Pages of
a vma that does not have the VM_EXEC bit set get mapped only in the
data address space. Any try to execute code on such a page will cause a
page translation exception. The standard reaction to this is a SIGSEGV
with two exceptions: the two system call opcodes 0x0a77 (sys_sigreturn)
and 0x0aad (sys_rt_sigreturn) are allowed. They are stored by the
kernel to the signal stack frame. Unfortunately, the signal return
mechanism cannot be modified to use an SA_RESTORER because the
exception unwinding code depends on the system call opcode stored
behind the signal stack frame.

This feature requires that user space is executed in secondary-space
mode and the kernel in home-space mode, which means that the addressing
modes need to be switched and that the noexec protection only works
for user space.
After switching the addressing modes, we cannot use the mvcp/mvcs
instructions anymore to copy between kernel and user space. A new
mvcos instruction has been added to the z9 EC/BC hardware which allows
to copy between arbitrary address spaces, but on older hardware the
page tables need to be walked manually.

Signed-off-by: default avatarGerald Schaefer <geraldsc@de.ibm.com>
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
parent 86aa9fc2
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -134,6 +134,31 @@ config AUDIT_ARCH
	bool
	default y

config S390_SWITCH_AMODE
	bool "Switch kernel/user addressing modes"
	help
	  This option allows to switch the addressing modes of kernel and user
	  space. The kernel parameter switch_amode=on will enable this feature,
	  default is disabled. Enabling this (via kernel parameter) on machines
	  earlier than IBM System z9-109 EC/BC will reduce system performance.

	  Note that this option will also be selected by selecting the execute
	  protection option below. Enabling the execute protection via the
	  noexec kernel parameter will also switch the addressing modes,
	  independent of the switch_amode kernel parameter.


config S390_EXEC_PROTECT
	bool "Data execute protection"
	select S390_SWITCH_AMODE
	help
	  This option allows to enable a buffer overflow protection for user
	  space programs and it also selects the addressing mode option above.
	  The kernel parameter noexec=on will enable this feature and also
	  switch the addressing modes, default is disabled. Enabling this (via
	  kernel parameter) on machines earlier than IBM System z9-109 EC/BC
	  will reduce system performance.

comment "Code generation options"

choice
+2 −0
Original line number Diff line number Diff line
@@ -108,6 +108,8 @@ CONFIG_DEFAULT_MIGRATION_COST=1000000
CONFIG_COMPAT=y
CONFIG_SYSVIPC_COMPAT=y
CONFIG_AUDIT_ARCH=y
CONFIG_S390_SWITCH_AMODE=y
CONFIG_S390_EXEC_PROTECT=y

#
# Code generation options
+6 −0
Original line number Diff line number Diff line
@@ -69,6 +69,12 @@

#include "compat_linux.h"

long psw_user32_bits	= (PSW_BASE32_BITS | PSW_MASK_DAT | PSW_ASC_HOME |
			   PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
			   PSW_MASK_PSTATE | PSW_DEFAULT_KEY);
long psw32_user_bits	= (PSW32_BASE_BITS | PSW32_MASK_DAT | PSW32_ASC_HOME |
			   PSW32_MASK_IO | PSW32_MASK_EXT | PSW32_MASK_MCHECK |
			   PSW32_MASK_PSTATE);
 
/* For this source file, we want overflow handling. */

+0 −31
Original line number Diff line number Diff line
@@ -115,37 +115,6 @@ typedef struct
        __u32	addr;
} _psw_t32 __attribute__ ((aligned(8)));

#define PSW32_MASK_PER		0x40000000UL
#define PSW32_MASK_DAT		0x04000000UL
#define PSW32_MASK_IO		0x02000000UL
#define PSW32_MASK_EXT		0x01000000UL
#define PSW32_MASK_KEY		0x00F00000UL
#define PSW32_MASK_MCHECK	0x00040000UL
#define PSW32_MASK_WAIT		0x00020000UL
#define PSW32_MASK_PSTATE	0x00010000UL
#define PSW32_MASK_ASC		0x0000C000UL
#define PSW32_MASK_CC		0x00003000UL
#define PSW32_MASK_PM		0x00000f00UL

#define PSW32_ADDR_AMODE31	0x80000000UL
#define PSW32_ADDR_INSN		0x7FFFFFFFUL

#define PSW32_BASE_BITS		0x00080000UL

#define PSW32_ASC_PRIMARY	0x00000000UL
#define PSW32_ASC_ACCREG	0x00004000UL
#define PSW32_ASC_SECONDARY	0x00008000UL
#define PSW32_ASC_HOME		0x0000C000UL

#define PSW32_USER_BITS	(PSW32_BASE_BITS | PSW32_MASK_DAT | PSW32_ASC_HOME | \
			 PSW32_MASK_IO | PSW32_MASK_EXT | PSW32_MASK_MCHECK | \
			 PSW32_MASK_PSTATE)

#define PSW32_MASK_MERGE(CURRENT,NEW) \
        (((CURRENT) & ~(PSW32_MASK_CC|PSW32_MASK_PM)) | \
         ((NEW) & (PSW32_MASK_CC|PSW32_MASK_PM)))


typedef struct
{
	_psw_t32	psw;
+1 −1
Original line number Diff line number Diff line
@@ -298,7 +298,7 @@ static int save_sigregs32(struct pt_regs *regs, _sigregs32 __user *sregs)
	_s390_regs_common32 regs32;
	int err, i;

	regs32.psw.mask = PSW32_MASK_MERGE(PSW32_USER_BITS,
	regs32.psw.mask = PSW32_MASK_MERGE(psw32_user_bits,
					   (__u32)(regs->psw.mask >> 32));
	regs32.psw.addr = PSW32_ADDR_AMODE31 | (__u32) regs->psw.addr;
	for (i = 0; i < NUM_GPRS; i++)
Loading