add manpages for Memory Protection Keys
RFC PATCH v2 1/1 add manpages for Memory Protection Keys
From: Dave Hansen <dave.hansen-VuQAYsv1563Yd54FQh9/[email protected]>
Memory Protection Keys for User pages is an Intel CPU feature which will first appear on Skylake Servers, but will also be supported on future non-server parts (there is also a QEMU implementation). It provides a mechanism for enforcing page-based protections, but without requiring modification of the page tables when an application wishes to change permissions.
I have propsed adding five new system calls to support this feature. The five calls are distributed across three man-pages (one existing and 2 new), plus a new pkey(7) page which serves as a general overview of the feature.
The system calls for this feature are not currently upstream but can be found here:
http://git.kernel.org/cgit/linux/kernel/git/daveh/x86-pkeys.git/
--- man2/mprotect.2 | 45 ++++++++++++- man2/pkey_alloc.2 | 103 +++++++++++++++++++++++++++++ man2/pkey_get.2 | 110 +++++++++++++++++++++++++++++++ man2/sigaction.2 | 9 +++ man5/proc.5 | 8 +++ man7/pkey.7 | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 464 insertions(+), 3 deletions(-) create mode 100644 man2/pkey_alloc.2 create mode 100644 man2/pkey_get.2 create mode 100644 man7/pkey.7
man2/mprotect.2 +42 -3
@@ -29,6 +29,7 @@ .\" Modified 2004-08-16 by Andi Kleen <[email protected]> .\" 2007-06-02, mtk: Fairly substantial rewrites and additions, and .\" a much improved example program. +.\" 2016-03-03, added pkey_mprotect, Dave Hansen <[email protected]> .\" .\" FIXME The following protection flags need documenting: .\" PROT_SEM
@@ -38,16 +39,19 @@ .\" .TH MPROTECT 2 2015-07-23 "Linux" "Linux Programmer's Manual" .SH NAME -mprotect \- set protection on a region of memory +mprotect, pkey_mprotect \- set protection on a region of memory .SH SYNOPSIS .nf .B #include <sys/mman.h> .sp .BI "int mprotect(void *" addr ", size_t " len ", int " prot ); +.BI "int pkey_mprotect(void *" addr ", size_t " len ", int " prot ", int " pkey "); .fi .SH DESCRIPTION .BR mprotect () -changes protection for the calling process's memory page(s) +and +.BR pkey_mprotect () +change protection for the calling process's memory page(s) containing any part of the address range in the interval [\fIaddr\fP,\ \fIaddr\fP+\fIlen\fP\-1]. .I addr
@@ -74,10 +78,19 @@ The memory can be modified. .TP .B PROT_EXEC The memory can be executed. +.PP +.I pkey +is the protection key to assign to the memory. +A pkey must be allocated with +.BR pkey_alloc (2) +before it is passed to +.BR pkey_mprotect (). .SH RETURN VALUE On success, .BR mprotect () -returns zero. +and +.BR pkey_mprotect () +return zero. On error, \-1 is returned, and .I errno is set appropriately.
@@ -95,6 +108,8 @@ to mark it .B EINVAL \fIaddr\fP is not a valid pointer, or not a multiple of the system page size. +Or: \fIpkey\fP has not been allocated with +.BR pkey_alloc (2) .\" Or: both PROT_GROWSUP and PROT_GROWSDOWN were specified in 'prot'. .TP .B ENOMEM
@@ -165,6 +180,29 @@ but at a minimum can allow write access only if has been set, and must not allow any access if .B PROT_NONE has been set. + +Applications should be careful when mixing use of +.BR mprotect () +and +.BR pkey_mprotect () . +On x86, when +.BR mprotect () +is used with +.IR prot +set to +.B PROT_EXEC +a pkey is may be allocated and set on the memory implicitly +by the kernel, but only when the pkey was 0 previously. + +On systems that do not support protection keys in hardware, +.BR pkey_mprotect () +may still be used, but +.IR pkey +must be set to 0. When called this way, the operation of +.BR pkey_mprotect () +is equivalent to +.BR mprotect (). + .SH EXAMPLE .\" sigaction.2 refers to this example .PP
@@ -246,3 +284,4 @@ main(int argc, char *argv[]) .SH SEE ALSO .BR mmap (2), .BR sysconf (3) +.BR pkey (7)
man2/pkey_alloc.2 new file +103 -0
103 lines not on this page · raw message
man2/pkey_get.2 new file +110 -0
110 lines not on this page · raw message
man2/sigaction.2 +9 -0
@@ -45,6 +45,7 @@ .\" 2010-06-11 mtk, improvements to discussion of various siginfo_t fields. .\" 2015-01-17, Kees Cook <[email protected]> .\" Added notes on ptrace SIGTRAP and SYS_SECCOMP. +.\" 2016-03-10, Dave Hansen, add si_pkey .\" .TH SIGACTION 2 2015-08-08 "Linux" "Linux Programmer's Manual" .SH NAME
@@ -305,6 +306,8 @@ siginfo_t { (since Linux 3.5) */ unsigned int si_arch; /* Architecture of attempted system call (since Linux 3.5) */ + unsigned int si_pkey; /* Protection key set on si_addr + (since Linux <FIXME>) */ } .fi .in
@@ -620,6 +623,12 @@ Address not mapped to object. .TP .B SEGV_ACCERR Invalid permissions for mapped object. +.TP +.B SEGV_PKUERR +Access was denied by memory protection keys. See: +.BR pkeys (7). +The protection key which applied to this access is available via +.I si_pkey .RE .PP The following values can be placed in
man5/proc.5 +8 -0
@@ -47,6 +47,7 @@ .\" and /proc/[pid]/fdinfo/*. .\" 2008-06-19, mtk, Documented /proc/[pid]/status. .\" 2008-07-15, mtk, added /proc/config.gz +.\" 2016-03-10, Dave Hansen, added ProtectionKey to /proc/[pid]/smaps .\" .\" FIXME . cross check against Documentation/filesystems/proc.txt .\" to see what information could be imported from that file
@@ -1471,6 +1472,13 @@ The codes are the following: nh - no-huge page advise flag mg - mergeable advise flag +"ProtectionKey" field contains the memory protection key (see +.BR pkeys (5)) +associated with the virtual memory area. Only present if the +kernel was built with the +.B CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS +configuration option. (since Linux 4.6) + The .IR /proc/[pid]/smaps file is present only if the
man7/pkey.7 new file +192 -0
192 lines not on this page · raw message
Signature · 1 line
1.9.1