The attached patch addresses a problem with the current x86 pkey implementation, which makes default-readable pkeys unusable from signal handlers because the default init_pkru value blocks access. With this patch, the following program: #include #include #include #include #include #define PKEY_ALLOC_SETSIGNAL 1 #define PKEY_DISABLE_WRITE 2 static inline unsigned int pkey_read (void) { unsigned int result; __asm__ volatile (".byte 0x0f, 0x01, 0xee" : "=a" (result) : "c" (0) : "rdx"); return result; } static void print_pkru (const char *where) { printf ("PKRU (%s): %08x\n", where, pkey_read ()); } static void sigusr1 (int signo) { print_pkru ("signal handler"); } int main (void) { if (signal (SIGUSR1, sigusr1) == SIG_ERR) err (1, "signal"); print_pkru ("main"); raise (SIGUSR1); puts ("allocating key 1"); int key1 = syscall (SYS_pkey_alloc, 0, 0); if (key1 < 0) err (1, "pkey_alloc"); print_pkru ("main"); raise (SIGUSR1); puts ("allocating key 2"); int key2 = syscall (SYS_pkey_alloc, PKEY_ALLOC_SETSIGNAL, 0); if (key2 < 0) err (1, "pkey_alloc"); print_pkru ("main"); raise (SIGUSR1); puts ("allocating key 3"); int key3 = syscall (SYS_pkey_alloc, PKEY_ALLOC_SETSIGNAL, PKEY_DISABLE_WRITE); if (key3 < 0) err (1, "pkey_alloc"); print_pkru ("main"); raise (SIGUSR1); puts ("freeing key 3"); if (syscall (SYS_pkey_free, key3) < 0) err (1, "pkey_free"); print_pkru ("main"); raise (SIGUSR1); puts ("freeing key 2"); if (syscall (SYS_pkey_free, key2) < 0) err (1, "pkey_free"); print_pkru ("main"); raise (SIGUSR1); return 0; } prints this: PKRU (main): 55555554 PKRU (signal handler): 55555554 allocating key 1 PKRU (main): 55555550 PKRU (signal handler): 55555554 allocating key 2 PKRU (main): 55555540 PKRU (signal handler): 55555544 allocating key 3 PKRU (main): 55555580 PKRU (signal handler): 55555584 freeing key 3 PKRU (main): 55555580 PKRU (signal handler): 55555544 freeing key 2 PKRU (main): 55555580 PKRU (signal handler): 55555554 Something like this is required before we can use memory protection keys in glibc for mostly-read-only data structures which need to be accessible from signal handlers. I'm not sure if I got the locking for mm->context right. Please check carefully. Thanks, Florian