/* Information shared between the parent and the child. */ struct shared_info { struct child_sync child_sync;
/* AMR value the parent expects to read from the child. */ unsignedlong amr1;
/* AMR value the parent is expected to write to the child. */ unsignedlong amr2;
/* AMR value that ptrace should refuse to write to the child. */ unsignedlong invalid_amr;
/* IAMR value the parent expects to read from the child. */ unsignedlong expected_iamr;
/* UAMOR value the parent expects to read from the child. */ unsignedlong expected_uamor;
/* * IAMR and UAMOR values that ptrace should refuse to write to the child * (even though they're valid ones) because userspace doesn't have * access to those registers.
*/ unsignedlong invalid_iamr; unsignedlong invalid_uamor;
};
staticint child(struct shared_info *info)
{ unsignedlong reg; bool disable_execute = true; int pkey1, pkey2, pkey3; int ret;
/* Wait until parent fills out the initial register values. */
ret = wait_parent(&info->child_sync); if (ret) return ret;
/* Get some pkeys so that we can change their bits in the AMR. */
pkey1 = sys_pkey_alloc(0, PKEY_DISABLE_EXECUTE); if (pkey1 < 0) {
pkey1 = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
CHILD_FAIL_IF(pkey1 < 0, &info->child_sync);
info->amr1 |= 3ul << pkeyshift(pkey1);
info->amr2 |= 3ul << pkeyshift(pkey2); /* * invalid amr value where we try to force write * things which are deined by a uamor setting.
*/
info->invalid_amr = info->amr2 | (~0x0UL & ~info->expected_uamor);
/* * if PKEY_DISABLE_EXECUTE succeeded we should update the expected_iamr
*/ if (disable_execute)
info->expected_iamr |= 1ul << pkeyshift(pkey1); else
info->expected_iamr &= ~(1ul << pkeyshift(pkey1));
/* * We allocated pkey2 and pkey 3 above. Clear the IAMR bits.
*/
info->expected_iamr &= ~(1ul << pkeyshift(pkey2));
info->expected_iamr &= ~(1ul << pkeyshift(pkey3));
/* * Create an IAMR value different from expected value. * Kernel will reject an IAMR and UAMOR change.
*/
info->invalid_iamr = info->expected_iamr | (1ul << pkeyshift(pkey1) | 1ul << pkeyshift(pkey2));
info->invalid_uamor = info->expected_uamor & ~(0x3ul << pkeyshift(pkey1));
/* * Wait for parent to try to write an IAMR and a UAMOR value. We can't * verify them, but we can verify that the AMR didn't change.
*/
ret = prod_parent(&info->child_sync);
CHILD_FAIL_IF(ret, &info->child_sync);
ret = wait_parent(&info->child_sync); if (ret) return ret;
/* * Get the initial values for AMR, IAMR and UAMOR and communicate them * to the child.
*/
ret = ptrace_read_regs(pid, NT_PPC_PKEY, regs, 3);
PARENT_SKIP_IF_UNSUPPORTED(ret, &info->child_sync, "PKEYs not supported");
PARENT_FAIL_IF(ret, &info->child_sync);
/* Wake up child so that it can set itself up. */
ret = prod_child(&info->child_sync);
PARENT_FAIL_IF(ret, &info->child_sync);
ret = wait_child(&info->child_sync); if (ret) return ret;
/* Verify that we can read the pkey registers from the child. */
ret = ptrace_read_regs(pid, NT_PPC_PKEY, regs, 3);
PARENT_FAIL_IF(ret, &info->child_sync);
/* Try to write to IAMR and UAMOR. */
regs[2] = info->invalid_uamor;
ret = ptrace_write_regs(pid, NT_PPC_PKEY, regs, 3);
PARENT_FAIL_IF(!ret, &info->child_sync);
/* Verify that all registers still have their expected values. */
ret = ptrace_read_regs(pid, NT_PPC_PKEY, regs, 3);
PARENT_FAIL_IF(ret, &info->child_sync);
/* Wake up child so that it can verify AMR didn't change and wrap up. */
ret = prod_child(&info->child_sync);
PARENT_FAIL_IF(ret, &info->child_sync);
ret = wait(&status); if (ret != pid) {
printf("Child's exit status not captured\n");
ret = TEST_PASS;
} elseif (!WIFEXITED(status)) {
printf("Child exited abnormally\n");
ret = TEST_FAIL;
} else
ret = WEXITSTATUS(status) ? TEST_FAIL : TEST_PASS;
return ret;
}
staticint ptrace_pkey(void)
{ struct shared_info *info; int shm_id; int ret;
pid_t pid;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.