Skip to content

Commit a075f69

Browse files
kvaneeshgregkh
authored andcommitted
selftests/powerpc: ptrace-pkey: Update the test to mark an invalid pkey correctly
[ Upstream commit 0eaa3b5 ] Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20200709032946.881753-22-aneesh.kumar@linux.ibm.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 9f00bbb commit a075f69

1 file changed

Lines changed: 12 additions & 18 deletions

File tree

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

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ static int sys_pkey_alloc(unsigned long flags, unsigned long init_access_rights)
6666
return syscall(__NR_pkey_alloc, flags, init_access_rights);
6767
}
6868

69-
static int sys_pkey_free(int pkey)
70-
{
71-
return syscall(__NR_pkey_free, pkey);
72-
}
73-
7469
static int child(struct shared_info *info)
7570
{
7671
unsigned long reg;
@@ -100,7 +95,11 @@ static int child(struct shared_info *info)
10095

10196
info->amr1 |= 3ul << pkeyshift(pkey1);
10297
info->amr2 |= 3ul << pkeyshift(pkey2);
103-
info->invalid_amr |= info->amr2 | 3ul << pkeyshift(pkey3);
98+
/*
99+
* invalid amr value where we try to force write
100+
* things which are deined by a uamor setting.
101+
*/
102+
info->invalid_amr = info->amr2 | (~0x0UL & ~info->expected_uamor);
104103

105104
if (disable_execute)
106105
info->expected_iamr |= 1ul << pkeyshift(pkey1);
@@ -111,17 +110,12 @@ static int child(struct shared_info *info)
111110

112111
info->expected_uamor |= 3ul << pkeyshift(pkey1) |
113112
3ul << pkeyshift(pkey2);
114-
info->invalid_iamr |= 1ul << pkeyshift(pkey1) | 1ul << pkeyshift(pkey2);
115-
info->invalid_uamor |= 3ul << pkeyshift(pkey1);
116-
117113
/*
118-
* We won't use pkey3. We just want a plausible but invalid key to test
119-
* whether ptrace will let us write to AMR bits we are not supposed to.
120-
*
121-
* This also tests whether the kernel restores the UAMOR permissions
122-
* after a key is freed.
114+
* Create an IAMR value different from expected value.
115+
* Kernel will reject an IAMR and UAMOR change.
123116
*/
124-
sys_pkey_free(pkey3);
117+
info->invalid_iamr = info->expected_iamr | (1ul << pkeyshift(pkey1) | 1ul << pkeyshift(pkey2));
118+
info->invalid_uamor = info->expected_uamor & ~(0x3ul << pkeyshift(pkey1));
125119

126120
printf("%-30s AMR: %016lx pkey1: %d pkey2: %d pkey3: %d\n",
127121
user_write, info->amr1, pkey1, pkey2, pkey3);
@@ -196,9 +190,9 @@ static int parent(struct shared_info *info, pid_t pid)
196190
PARENT_SKIP_IF_UNSUPPORTED(ret, &info->child_sync);
197191
PARENT_FAIL_IF(ret, &info->child_sync);
198192

199-
info->amr1 = info->amr2 = info->invalid_amr = regs[0];
200-
info->expected_iamr = info->invalid_iamr = regs[1];
201-
info->expected_uamor = info->invalid_uamor = regs[2];
193+
info->amr1 = info->amr2 = regs[0];
194+
info->expected_iamr = regs[1];
195+
info->expected_uamor = regs[2];
202196

203197
/* Wake up child so that it can set itself up. */
204198
ret = prod_child(&info->child_sync);

0 commit comments

Comments
 (0)