Lines Matching refs:pkey

402 static u32 hw_pkey_get(int pkey, unsigned long flags)  in hw_pkey_get()  argument
410 __func__, pkey, flags, 0, 0); in hw_pkey_get()
413 shifted_pkru = (pkru >> (pkey * PKRU_BITS_PER_PKEY)); in hw_pkey_get()
424 static int hw_pkey_set(int pkey, unsigned long rights, unsigned long flags) in hw_pkey_set() argument
436 new_pkru &= ~(mask << (pkey * PKRU_BITS_PER_PKEY)); in hw_pkey_set()
438 new_pkru |= (rights << (pkey * PKRU_BITS_PER_PKEY)); in hw_pkey_set()
443 __func__, pkey, rights, flags, 0, __rdpkru(), old_pkru); in hw_pkey_set()
447 void pkey_disable_set(int pkey, int flags) in pkey_disable_set() argument
455 pkey, flags); in pkey_disable_set()
458 pkey_rights = hw_pkey_get(pkey, syscall_flags); in pkey_disable_set()
461 pkey, pkey, pkey_rights); in pkey_disable_set()
466 ret = hw_pkey_set(pkey, pkey_rights, syscall_flags); in pkey_disable_set()
469 shadow_pkru |= flags << (pkey * 2); in pkey_disable_set()
470 dprintf1("%s(%d) shadow: 0x%x\n", __func__, pkey, shadow_pkru); in pkey_disable_set()
474 pkey_rights = hw_pkey_get(pkey, syscall_flags); in pkey_disable_set()
476 pkey, pkey, pkey_rights); in pkey_disable_set()
478 dprintf1("%s(%d) pkru: 0x%x\n", __func__, pkey, rdpkru()); in pkey_disable_set()
482 pkey, flags); in pkey_disable_set()
485 void pkey_disable_clear(int pkey, int flags) in pkey_disable_clear() argument
489 int pkey_rights = hw_pkey_get(pkey, syscall_flags); in pkey_disable_clear()
495 pkey, pkey, pkey_rights); in pkey_disable_clear()
500 ret = hw_pkey_set(pkey, pkey_rights, 0); in pkey_disable_clear()
502 shadow_pkru &= ~(flags << (pkey * 2)); in pkey_disable_clear()
505 pkey_rights = hw_pkey_get(pkey, syscall_flags); in pkey_disable_clear()
507 pkey, pkey, pkey_rights); in pkey_disable_clear()
509 dprintf1("%s(%d) pkru: 0x%x\n", __func__, pkey, rdpkru()); in pkey_disable_clear()
514 void pkey_write_allow(int pkey) in pkey_write_allow() argument
516 pkey_disable_clear(pkey, PKEY_DISABLE_WRITE); in pkey_write_allow()
518 void pkey_write_deny(int pkey) in pkey_write_deny() argument
520 pkey_disable_set(pkey, PKEY_DISABLE_WRITE); in pkey_write_deny()
522 void pkey_access_allow(int pkey) in pkey_access_allow() argument
524 pkey_disable_clear(pkey, PKEY_DISABLE_ACCESS); in pkey_access_allow()
526 void pkey_access_deny(int pkey) in pkey_access_deny() argument
528 pkey_disable_set(pkey, PKEY_DISABLE_ACCESS); in pkey_access_deny()
532 unsigned long pkey) in sys_mprotect_pkey() argument
537 ptr, size, orig_prot, pkey); in sys_mprotect_pkey()
540 sret = syscall(SYS_mprotect_key, ptr, size, orig_prot, pkey); in sys_mprotect_pkey()
594 int sys_pkey_free(unsigned long pkey) in sys_pkey_free() argument
596 int ret = syscall(SYS_pkey_free, pkey); in sys_pkey_free()
597 dprintf1("%s(pkey=%ld) syscall ret: %d\n", __func__, pkey, ret); in sys_pkey_free()
647 unsigned long pkey) in mprotect_pkey() argument
654 ret = sys_mprotect_pkey(ptr, size, orig_prot, pkey); in mprotect_pkey()
656 ptr, size, orig_prot, pkey, ret); in mprotect_pkey()
666 pkey_assert(pkey < NR_PKEYS); in mprotect_pkey()
668 ret = sys_mprotect_pkey(ptr, size, orig_prot, pkey); in mprotect_pkey()
670 ptr, size, orig_prot, pkey, ret); in mprotect_pkey()
750 void *malloc_pkey_with_mprotect(long size, int prot, u16 pkey) in malloc_pkey_with_mprotect() argument
757 size, prot, pkey); in malloc_pkey_with_mprotect()
758 pkey_assert(pkey < NR_PKEYS); in malloc_pkey_with_mprotect()
761 ret = mprotect_pkey((void *)ptr, PAGE_SIZE, prot, pkey); in malloc_pkey_with_mprotect()
766 dprintf1("%s() for pkey %d @ %p\n", __func__, pkey, ptr); in malloc_pkey_with_mprotect()
770 void *malloc_pkey_anon_huge(long size, int prot, u16 pkey) in malloc_pkey_anon_huge() argument
776 size, prot, pkey); in malloc_pkey_anon_huge()
785 mprotect_pkey(ptr, size, prot, pkey); in malloc_pkey_anon_huge()
796 dprintf1("mmap()'d thp for pkey %d @ %p\n", pkey, ptr); in malloc_pkey_anon_huge()
842 void *malloc_pkey_hugetlb(long size, int prot, u16 pkey) in malloc_pkey_hugetlb() argument
850 dprintf1("doing %s(%ld, %x, %x)\n", __func__, size, prot, pkey); in malloc_pkey_hugetlb()
852 pkey_assert(pkey < NR_PKEYS); in malloc_pkey_hugetlb()
855 mprotect_pkey(ptr, size, prot, pkey); in malloc_pkey_hugetlb()
859 dprintf1("mmap()'d hugetlbfs for pkey %d @ %p\n", pkey, ptr); in malloc_pkey_hugetlb()
863 void *malloc_pkey_mmap_dax(long size, int prot, u16 pkey) in malloc_pkey_mmap_dax() argument
869 size, prot, pkey); in malloc_pkey_mmap_dax()
870 pkey_assert(pkey < NR_PKEYS); in malloc_pkey_mmap_dax()
877 mprotect_pkey(ptr, size, prot, pkey); in malloc_pkey_mmap_dax()
881 dprintf1("mmap()'d for pkey %d @ %p\n", pkey, ptr); in malloc_pkey_mmap_dax()
886 void *(*pkey_malloc[])(long size, int prot, u16 pkey) = {
897 void *malloc_pkey(long size, int prot, u16 pkey) in malloc_pkey() argument
903 pkey_assert(pkey < NR_PKEYS); in malloc_pkey()
908 ret = pkey_malloc[malloc_type](size, prot, pkey); in malloc_pkey()
923 size, prot, pkey, ret); in malloc_pkey()
929 void expected_pk_fault(int pkey) in expected_pk_fault() argument
933 dprintf2("%s(%d): last_si_pkey: %d\n", __func__, pkey, last_si_pkey); in expected_pk_fault()
940 if (pkey != UNKNOWN_PKEY) in expected_pk_fault()
941 pkey_assert(last_si_pkey == pkey); in expected_pk_fault()
1003 void test_read_of_write_disabled_region(int *ptr, u16 pkey) in test_read_of_write_disabled_region() argument
1008 pkey_write_deny(pkey); in test_read_of_write_disabled_region()
1013 void test_read_of_access_disabled_region(int *ptr, u16 pkey) in test_read_of_access_disabled_region() argument
1017 dprintf1("disabling access to PKEY[%02d], doing read @ %p\n", pkey, ptr); in test_read_of_access_disabled_region()
1019 pkey_access_deny(pkey); in test_read_of_access_disabled_region()
1022 expected_pk_fault(pkey); in test_read_of_access_disabled_region()
1024 void test_write_of_write_disabled_region(int *ptr, u16 pkey) in test_write_of_write_disabled_region() argument
1026 dprintf1("disabling write access to PKEY[%02d], doing write\n", pkey); in test_write_of_write_disabled_region()
1027 pkey_write_deny(pkey); in test_write_of_write_disabled_region()
1029 expected_pk_fault(pkey); in test_write_of_write_disabled_region()
1031 void test_write_of_access_disabled_region(int *ptr, u16 pkey) in test_write_of_access_disabled_region() argument
1033 dprintf1("disabling access to PKEY[%02d], doing write\n", pkey); in test_write_of_access_disabled_region()
1034 pkey_access_deny(pkey); in test_write_of_access_disabled_region()
1036 expected_pk_fault(pkey); in test_write_of_access_disabled_region()
1038 void test_kernel_write_of_access_disabled_region(int *ptr, u16 pkey) in test_kernel_write_of_access_disabled_region() argument
1044 "having kernel read() to buffer\n", pkey); in test_kernel_write_of_access_disabled_region()
1045 pkey_access_deny(pkey); in test_kernel_write_of_access_disabled_region()
1050 void test_kernel_write_of_write_disabled_region(int *ptr, u16 pkey) in test_kernel_write_of_write_disabled_region() argument
1055 pkey_write_deny(pkey); in test_kernel_write_of_write_disabled_region()
1063 void test_kernel_gup_of_access_disabled_region(int *ptr, u16 pkey) in test_kernel_gup_of_access_disabled_region() argument
1073 "having kernel vmsplice from buffer\n", pkey); in test_kernel_gup_of_access_disabled_region()
1074 pkey_access_deny(pkey); in test_kernel_gup_of_access_disabled_region()
1085 void test_kernel_gup_write_to_write_disabled_region(int *ptr, u16 pkey) in test_kernel_gup_write_to_write_disabled_region() argument
1092 "doing futex gunk in buffer\n", pkey); in test_kernel_gup_write_to_write_disabled_region()
1094 pkey_write_deny(pkey); in test_kernel_gup_write_to_write_disabled_region()
1103 void test_pkey_syscalls_on_non_allocated_pkey(int *ptr, u16 pkey) in test_pkey_syscalls_on_non_allocated_pkey() argument
1110 if (pkey == i) in test_pkey_syscalls_on_non_allocated_pkey()
1126 void test_pkey_syscalls_bad_args(int *ptr, u16 pkey) in test_pkey_syscalls_bad_args() argument
1137 void test_pkey_alloc_exhaust(int *ptr, u16 pkey) in test_pkey_alloc_exhaust() argument
1192 void test_mprotect_with_pkey_0(int *ptr, u16 pkey) in test_mprotect_with_pkey_0() argument
1213 mprotect_pkey(ptr, size, prot, pkey); in test_mprotect_with_pkey_0()
1216 void test_ptrace_of_child(int *ptr, u16 pkey) in test_ptrace_of_child() argument
1252 pkey_access_deny(pkey); in test_ptrace_of_child()
1253 pkey_write_deny(pkey); in test_ptrace_of_child()
1269 expected_pk_fault(pkey); in test_ptrace_of_child()
1313 void test_executing_on_unreadable_memory(int *ptr, u16 pkey) in test_executing_on_unreadable_memory() argument
1325 ret = mprotect_pkey(p1, PAGE_SIZE, PROT_EXEC, (u64)pkey); in test_executing_on_unreadable_memory()
1327 pkey_access_deny(pkey); in test_executing_on_unreadable_memory()
1339 expected_pk_fault(pkey); in test_executing_on_unreadable_memory()
1342 void test_implicit_mprotect_exec_only_memory(int *ptr, u16 pkey) in test_implicit_mprotect_exec_only_memory() argument
1385 void test_mprotect_pkey_on_unsupported_cpu(int *ptr, u16 pkey) in test_mprotect_pkey_on_unsupported_cpu() argument
1395 sret = syscall(SYS_mprotect_key, ptr, size, PROT_READ, pkey); in test_mprotect_pkey_on_unsupported_cpu()
1399 void (*pkey_tests[])(int *ptr, u16 pkey) = {
1423 int pkey; in run_tests_once() local
1430 pkey = alloc_random_pkey(); in run_tests_once()
1431 dprintf1("test %d starting with pkey: %d\n", test_nr, pkey); in run_tests_once()
1432 ptr = malloc_pkey(PAGE_SIZE, prot, pkey); in run_tests_once()
1434 pkey_tests[test_nr](ptr, pkey); in run_tests_once()
1437 sys_pkey_free(pkey); in run_tests_once()