if (child == 0) { /* * The child sets itself for as tracee and * waits in signal for parent to trace it, * then it calls bp_1 and quits.
*/ int err = ptrace(PTRACE_TRACEME, 0, NULL, NULL);
if (err) {
pr_debug("failed to PTRACE_TRACEME\n"); exit(1);
}
raise(SIGCONT);
bp_1(); exit(0);
}
return child;
}
/* * This tests creates HW breakpoint, tries to * change it and checks it was properly changed.
*/ staticint bp_modify1(void)
{
pid_t child; int status; unsignedlong rip = 0, dr7 = 1;
/* * The parent does following steps: * - creates a new breakpoint (id 0) for bp_2 function * - changes that breakpoint to bp_1 function * - waits for the breakpoint to hit and checks * it has proper rip of bp_1 function * - detaches the child
*/ if (ptrace(PTRACE_POKEUSER, child,
offsetof(struct user, u_debugreg[0]), bp_2)) {
pr_debug("failed to set breakpoint, 1st time: %s\n",
strerror(errno)); goto out;
}
if (ptrace(PTRACE_POKEUSER, child,
offsetof(struct user, u_debugreg[0]), bp_1)) {
pr_debug("failed to set breakpoint, 2nd time: %s\n",
strerror(errno)); goto out;
}
if (ptrace(PTRACE_POKEUSER, child,
offsetof(struct user, u_debugreg[7]), dr7)) {
pr_debug("failed to set dr7: %s\n", strerror(errno)); goto out;
}
if (ptrace(PTRACE_CONT, child, NULL, NULL)) {
pr_debug("failed to PTRACE_CONT: %s\n", strerror(errno)); goto out;
}
/* * This tests creates HW breakpoint, tries to * change it to bogus value and checks the original * breakpoint is hit.
*/ staticint bp_modify2(void)
{
pid_t child; int status; unsignedlong rip = 0, dr7 = 1;
/* * The parent does following steps: * - creates a new breakpoint (id 0) for bp_1 function * - tries to change that breakpoint to (-1) address * - waits for the breakpoint to hit and checks * it has proper rip of bp_1 function * - detaches the child
*/ if (ptrace(PTRACE_POKEUSER, child,
offsetof(struct user, u_debugreg[0]), bp_1)) {
pr_debug("failed to set breakpoint: %s\n",
strerror(errno)); goto out;
}
if (ptrace(PTRACE_POKEUSER, child,
offsetof(struct user, u_debugreg[7]), dr7)) {
pr_debug("failed to set dr7: %s\n", strerror(errno)); goto out;
}
if (!ptrace(PTRACE_POKEUSER, child,
offsetof(struct user, u_debugreg[0]), (unsignedlong) (-1))) {
pr_debug("failed, breakpoint set to bogus address\n"); goto out;
}
if (ptrace(PTRACE_CONT, child, NULL, NULL)) {
pr_debug("failed to PTRACE_CONT: %s\n", strerror(errno)); goto out;
}
int test__bp_modify(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
{
TEST_ASSERT_VAL("modify test 1 failed\n", !bp_modify1());
TEST_ASSERT_VAL("modify test 2 failed\n", !bp_modify2());
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.