int main(int argc, char **argv) { srand(time(NULL)); if (argc > 1 && strcmp(argv[1], "intercept") == 0) return do_intercept(atoi(argv[2]), atoi(argv[3])); if (argc > 1 && strcmp(argv[1], "release") == 0) return do_release(atoi(argv[2]), atoi(argv[3])); if (argc > 1 && strcmp(argv[1], "start") == 0) return do_start(atoi(argv[2]), atoi(argv[3]), atoi(argv[4])); if (argc > 1 && strcmp(argv[1], "stop") == 0) return do_stop(atoi(argv[2]), atoi(argv[3]), atoi(argv[4])); if (argc > 1 && strcmp(argv[1], "monitor") == 0) return test_monitor(atoi(argv[2]), TRUE); if (argc > 1 && strcmp(argv[1], "nonroot") == 0) return do_nonroot(atoi(argv[2])); struct sigaction sa; sa.sa_flags = SA_SIGINFO; sigemptyset(&sa.sa_mask); sa.sa_sigaction = on_quit; if (sigaction(SIGQUIT, &sa, NULL) == -1) perror("Cannot register signal handler"); test("insmod interceptor.ko %s", "", system("insmod interceptor.ko") == 0); test("bad MY_SYSCALL args%s", "", vsyscall_arg(MY_CUSTOM_SYSCALL, 3, 100, 0, 0) == -EINVAL); do_intercept(MY_CUSTOM_SYSCALL, -EINVAL); do_release(MY_CUSTOM_SYSCALL, -EINVAL); do_intercept(-1, -EINVAL); do_release(-1, -EINVAL); do_intercept(__NR_exit, 0); do_release(__NR_exit, 0); test_syscall(SYS_open); /* The above line of code tests SYS_open. Feel free to add more tests here for other system calls, once you get everything to work; check Linux documentation for other syscall number definitions. */ do_intercept(SYS_open, 0); do_start(SYS_open, -1, 0); test_monitor(SYS_open, TRUE); test("rmmod interceptor.ko %s", "", system("rmmod interceptor") == 0); test_monitor(SYS_open, FALSE); return 0; }
/* for each of the different `who` values and make sure nothing segfaults */ int main(int argc, char* argv[]) { test_monitor(SELF, true, false); BIG_SEP(); test_monitor(SELF, true, true); BIG_SEP(); test_monitor(CHILDREN, false, true); /* should be 0 */ BIG_SEP(); test_monitor(THREAD, false, true); BIG_SEP(); DONE(); return 0; }
int main() { adam_init(); test_move(); test_return(); test_const(); test_monitor(); test_packed(); test_sparse(); test_arrayops(); test_instanceops(); test_invoke(); adam_finalize(); return 0; }
/* note this test is run after all processes have been intercepted*/ int do_nonroot(int syscall) { do_intercept(syscall, -EPERM); do_release(syscall, -EPERM); do_start(syscall, 0, -EPERM); do_stop(syscall, 0, -EPERM); do_start(syscall, 1, -EPERM); do_stop(syscall, 1, -EPERM); do_start(syscall, getpid(), 0); do_start(syscall, getpid(), -EBUSY); test_monitor(syscall, TRUE); do_stop(syscall, getpid(), 0); do_stop(syscall, getpid(), -EINVAL); puts("----- START OF test_B -----"); test_B(syscall, FALSE); puts("----- END OF test_B -----"); return 0; }
void test_PASS(int syscall) { int child; subtest("intercept"); do_intercept(syscall, 0); do_release(syscall, 0); subtest("monitor"); do_intercept(syscall, 0); test_monitor(syscall, FALSE); do_start(syscall, -1, 0); test_monitor(syscall, TRUE); do_stop(syscall, -1, 0); test_monitor(syscall, FALSE); do_release(syscall, 0); subtest("monitor & kill monitored process"); do_intercept(syscall, 0); switch (child = fork()) { case -1: assert(0); case 0: // monitor the child process then exit do_start(syscall, -1, 0); test_monitor(syscall, TRUE); exit(0); default: waitpid(child, NULL, 0); // child should have been unmonitored automatically // there is no way to start process with specific pid... do_start(syscall, child, -EINVAL); do_stop(syscall, child, -EINVAL); } do_release(syscall, 0); subtest("monitor all pids"); do_intercept(syscall, 0); test_monitor2(syscall, FALSE, FALSE); do_start(syscall, 0, 0); test_monitor2(syscall, TRUE, TRUE); subtest("stop monitor current pid"); do_stop(syscall, -1, 0); test_monitor2(syscall, FALSE, TRUE); subtest("monitor all -> stop one -> monitor all"); do_start(syscall, 0, 0); do_stop(syscall, -1, 0); do_start(syscall, 0, 0); do_stop(syscall, 0, 0); subtest("monitor one -> stop all"); do_start(syscall, -1, 0); do_stop(syscall, 0, 0); subtest("monitor all -> stop one -> stop all"); do_start(syscall, 0, 0); do_stop(syscall, -1, 0); do_stop(syscall, 0, 0); subtest("reset"); do_start(syscall, -1, 0); test_monitor2(syscall, TRUE, FALSE); do_stop(syscall, 0, 0); test_monitor2(syscall, FALSE, FALSE); do_release(syscall, 0); }