pkeys(7) Miscellaneous Information Manual pkeys(7) pkeys - (pkeys) . TLB . . pkeys "" pkey. . PROT_READ PROT_WRITE PROT_EXEC mprotect(2) mmap(2) . pkey SIGSEGV. sigaction(2) . pkeys . 2016 Intel x86 16 . pkey 0 15 . pkey pkey_mprotect(2). . . WRPKRU pkeys PKRU . "" . pkey_free(2) pkey. . pkey_free(2) pkey . . /proc/pid/smaps pkey . proc(5). . . pkey_alloc(2) . cpuid. Intel. /proc/cpuinfo "flags". "pku" "ospke" . . clone(2). clone(2) . ( ) . . . x86 PKRU ( ) (XSAVE) . . pkey: pkey_mprotect(2) pkey_alloc(2) pkey_free(2). pkey CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS. . . WRPKRU. . $ ./a.out buffer contains: 73 about to read buffer again... Segmentation fault (core dumped) #define _GNU_SOURCE #include #include #include #include #include int main(void) { int status; int pkey; int *buffer; /* * Allocate one page of memory. */ buffer = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (buffer == MAP_FAILED) err(EXIT_FAILURE, "mmap"); /* * Put some random data into the page (still OK to touch). */ *buffer = __LINE__; printf("buffer contains: %d\n", *buffer); /* * Allocate a protection key: */ pkey = pkey_alloc(0, 0); if (pkey == -1) err(EXIT_FAILURE, "pkey_alloc"); /* * Disable access to any memory with "pkey" set, * even though there is none right now. */ status = pkey_set(pkey, PKEY_DISABLE_ACCESS); if (status) err(EXIT_FAILURE, "pkey_set"); /* * Set the protection key on "buffer". * Note that it is still read/write as far as mprotect() is * concerned and the previous pkey_set() overrides it. */ status = pkey_mprotect(buffer, getpagesize(), PROT_READ | PROT_WRITE, pkey); if (status == -1) err(EXIT_FAILURE, "pkey_mprotect"); printf("about to read buffer again...\n"); /* * This will crash, because we have disallowed access. */ printf("buffer contains: %d\n", *buffer); status = pkey_free(pkey); if (status == -1) err(EXIT_FAILURE, "pkey_free"); exit(EXIT_SUCCESS); } pkey_alloc(2), pkey_free(2), pkey_mprotect(2), sigaction(2) 3 . . : . 6.18 8 2026 pkeys(7)