Skip to content

Commit cedce05

Browse files
author
Fox Snowpatch
committed
1 parent 1ecdccb commit cedce05

File tree

10 files changed

+18
-16
lines changed

10 files changed

+18
-16
lines changed

include/uapi/asm-generic/mman-common.h

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
/* compatibility flags */
8686
#define MAP_FILE 0
8787

88+
#define PKEY_UNRESTRICTED 0x0
8889
#define PKEY_DISABLE_ACCESS 0x1
8990
#define PKEY_DISABLE_WRITE 0x2
9091
#define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\

tools/testing/selftests/mm/mseal_test.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ bool seal_support(void)
218218
bool pkey_supported(void)
219219
{
220220
#if defined(__i386__) || defined(__x86_64__) /* arch */
221-
int pkey = sys_pkey_alloc(0, 0);
221+
int pkey = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
222222

223223
if (pkey > 0)
224224
return true;
@@ -1671,7 +1671,7 @@ static void test_seal_discard_ro_anon_on_pkey(bool seal)
16711671
setup_single_address_rw(size, &ptr);
16721672
FAIL_TEST_IF_FALSE(ptr != (void *)-1);
16731673

1674-
pkey = sys_pkey_alloc(0, 0);
1674+
pkey = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
16751675
FAIL_TEST_IF_FALSE(pkey > 0);
16761676

16771677
ret = sys_mprotect_pkey((void *)ptr, size, PROT_READ | PROT_WRITE, pkey);
@@ -1683,7 +1683,7 @@ static void test_seal_discard_ro_anon_on_pkey(bool seal)
16831683
}
16841684

16851685
/* sealing doesn't take effect if PKRU allow write. */
1686-
set_pkey(pkey, 0);
1686+
set_pkey(pkey, PKEY_UNRESTRICTED);
16871687
ret = sys_madvise(ptr, size, MADV_DONTNEED);
16881688
FAIL_TEST_IF_FALSE(!ret);
16891689

tools/testing/selftests/mm/pkey-helpers.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <stdlib.h>
1313
#include <ucontext.h>
1414
#include <sys/mman.h>
15+
#include <linux/mman.h>
1516

1617
#include "../kselftest.h"
1718

@@ -224,7 +225,7 @@ static inline u32 *siginfo_get_pkey_ptr(siginfo_t *si)
224225
static inline int kernel_has_pkeys(void)
225226
{
226227
/* try allocating a key and see if it succeeds */
227-
int ret = sys_pkey_alloc(0, 0);
228+
int ret = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
228229
if (ret <= 0) {
229230
return 0;
230231
}

tools/testing/selftests/mm/pkey_sighandler_tests.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ static void test_sigsegv_handler_with_different_pkey_for_stack(void)
314314
__write_pkey_reg(pkey_reg);
315315

316316
/* Protect the new stack with MPK 1 */
317-
pkey = pkey_alloc(0, 0);
317+
pkey = pkey_alloc(0, PKEY_UNRESTRICTED);
318318
pkey_mprotect(stack, STACK_SIZE, PROT_READ | PROT_WRITE, pkey);
319319

320320
/* Set up alternate signal stack that will use the default MPK */
@@ -487,7 +487,7 @@ static void test_pkru_sigreturn(void)
487487
__write_pkey_reg(pkey_reg);
488488

489489
/* Protect the stack with MPK 2 */
490-
pkey = pkey_alloc(0, 0);
490+
pkey = pkey_alloc(0, PKEY_UNRESTRICTED);
491491
pkey_mprotect(stack, STACK_SIZE, PROT_READ | PROT_WRITE, pkey);
492492

493493
/* Set up alternate signal stack that will use the default MPK */

tools/testing/selftests/mm/protection_keys.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ int sys_pkey_alloc(unsigned long flags, unsigned long init_val)
491491
int alloc_pkey(void)
492492
{
493493
int ret;
494-
unsigned long init_val = 0x0;
494+
unsigned long init_val = PKEY_UNRESTRICTED;
495495

496496
dprintf1("%s()::%d, pkey_reg: 0x%016llx shadow: %016llx\n",
497497
__func__, __LINE__, __read_pkey_reg(), shadow_pkey_reg);

tools/testing/selftests/powerpc/include/pkeys.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int pkeys_unsupported(void)
8585
SKIP_IF(!hash_mmu);
8686

8787
/* Check if the system call is supported */
88-
pkey = sys_pkey_alloc(0, 0);
88+
pkey = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
8989
SKIP_IF(pkey < 0);
9090
sys_pkey_free(pkey);
9191

tools/testing/selftests/powerpc/mm/pkey_exec_prot.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static void segv_handler(int signum, siginfo_t *sinfo, void *ctx)
7272

7373
switch (fault_type) {
7474
case PKEY_DISABLE_ACCESS:
75-
pkey_set_rights(fault_pkey, 0);
75+
pkey_set_rights(fault_pkey, PKEY_UNRESTRICTED);
7676
break;
7777
case PKEY_DISABLE_EXECUTE:
7878
/*

tools/testing/selftests/powerpc/mm/pkey_siginfo.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static void segv_handler(int signum, siginfo_t *sinfo, void *ctx)
8383
mprotect(pgstart, pgsize, PROT_EXEC))
8484
_exit(1);
8585
else
86-
pkey_set_rights(pkey, 0);
86+
pkey_set_rights(pkey, PKEY_UNRESTRICTED);
8787

8888
fault_count++;
8989
}

tools/testing/selftests/powerpc/ptrace/core-pkey.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,16 @@ static int child(struct shared_info *info)
124124
/* Get some pkeys so that we can change their bits in the AMR. */
125125
pkey1 = sys_pkey_alloc(0, PKEY_DISABLE_EXECUTE);
126126
if (pkey1 < 0) {
127-
pkey1 = sys_pkey_alloc(0, 0);
127+
pkey1 = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
128128
FAIL_IF(pkey1 < 0);
129129

130130
disable_execute = false;
131131
}
132132

133-
pkey2 = sys_pkey_alloc(0, 0);
133+
pkey2 = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
134134
FAIL_IF(pkey2 < 0);
135135

136-
pkey3 = sys_pkey_alloc(0, 0);
136+
pkey3 = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
137137
FAIL_IF(pkey3 < 0);
138138

139139
info->amr |= 3ul << pkeyshift(pkey1) | 2ul << pkeyshift(pkey2);

tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ static int child(struct shared_info *info)
8181
/* Get some pkeys so that we can change their bits in the AMR. */
8282
pkey1 = sys_pkey_alloc(0, PKEY_DISABLE_EXECUTE);
8383
if (pkey1 < 0) {
84-
pkey1 = sys_pkey_alloc(0, 0);
84+
pkey1 = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
8585
CHILD_FAIL_IF(pkey1 < 0, &info->child_sync);
8686

8787
disable_execute = false;
8888
}
8989

90-
pkey2 = sys_pkey_alloc(0, 0);
90+
pkey2 = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
9191
CHILD_FAIL_IF(pkey2 < 0, &info->child_sync);
9292

93-
pkey3 = sys_pkey_alloc(0, 0);
93+
pkey3 = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
9494
CHILD_FAIL_IF(pkey3 < 0, &info->child_sync);
9595

9696
info->amr1 |= 3ul << pkeyshift(pkey1);

0 commit comments

Comments
 (0)