static void verify_creat(void) { pid_t pid; pid = SAFE_FORK(); if (pid == 0) { char *av[] = {TEST_APP, NULL}; (void)execve(TEST_APP, av, tst_ipc_envp); perror("execve failed"); exit(1); } TST_CHECKPOINT_WAIT(0); TEST(creat(TEST_APP, O_WRONLY)); if (TEST_RETURN != -1) { tst_res(TFAIL, "creat() succeeded unexpectedly"); return; } if (TEST_ERRNO == ETXTBSY) tst_res(TPASS, "creat() received EXTBSY"); else tst_res(TFAIL | TTERRNO, "creat() failed unexpectedly"); SAFE_KILL(pid, SIGKILL); SAFE_WAITPID(pid, NULL, 0); }
static void do_test(void) { int i; if (!SAFE_FORK()) { SAFE_FILE_PRINTF(PATH_AUTOGROUP, "%d", 1); SAFE_SETSID(); if (SAFE_FORK()) pause(); SAFE_KILL(getppid(), SIGKILL); usleep(1000); // The child has gone, the grandchild runs with kref == 1 SAFE_FILE_PRINTF(PATH_AUTOGROUP, "%d", 0); SAFE_SETSID(); // runs with the freed ag/tg for (i = 0; i < LOOPS; i++) usleep(10); TST_CHECKPOINT_WAKE(0); exit(0); } SAFE_WAIT(NULL); // destroy the child's ag/tg TST_CHECKPOINT_WAIT(0); tst_res(TPASS, "Bug not reproduced"); }
static void do_child(void) { char *argv[3] = {TEST_APP, "canary", NULL}; TST_CHECKPOINT_WAIT(0); TEST(execve(TEST_APP, argv, environ)); tst_res(TFAIL | TERRNO, "execve() returned unexpected errno"); }
static void do_sleep(void) { TST_CHECKPOINT_WAIT(0); sleep(1); sleep(1); exit(3); }
static void do_fork(void) { pid_t fork_pid; int i; TST_CHECKPOINT_WAIT(0); for (i = 0; i < 50; i++) { fork_pid = SAFE_FORK(); if (fork_pid == 0) exit(3); if (TST_TRACE(reap_children(fork_pid, 0, &fork_pid, 1))) break; } exit(3); }
static void do_compute(void) { int i; TST_CHECKPOINT_WAIT(0); for (i = 0; i < 100000; i++) ; for (i = 0; i < 100000; i++) ; for (i = 0; i < 100000; i++) ; for (i = 0; i < 100000; i++) ; for (i = 0; i < 100000; i++) ; for (i = 0; i < 100000; i++) ; for (i = 0; i < 100000; i++) ; for (i = 0; i < 100000; i++) ; for (i = 0; i < 100000; i++) ; for (i = 0; i < 100000; i++) ; exit(3); }
static void setup(void) { sigset_t sigusr1; pthread_t defunct_thread; sigemptyset(&sigusr1); sigaddset(&sigusr1, SIGUSR1); pthread_sigmask(SIG_BLOCK, &sigusr1, NULL); parent_tgid = getpid(); parent_tid = sys_gettid(); SAFE_PTHREAD_CREATE(&child_thread, NULL, child_thread_func, NULL); TST_CHECKPOINT_WAIT(0); SAFE_PTHREAD_CREATE(&defunct_thread, NULL, defunct_thread_func, NULL); SAFE_PTHREAD_JOIN(defunct_thread, NULL); }
static void verify_execve(void) { pid_t pid; char *argv[2] = {TEST_APP, NULL}; pid = SAFE_FORK(); if (pid == 0) do_child(); TST_CHECKPOINT_WAIT(0); TEST(execve(TEST_APP, argv, environ)); if (TST_ERR != ETXTBSY) tst_res(TFAIL | TTERRNO, "execve succeeded, expected failure"); else tst_res(TPASS | TTERRNO, "execve failed as expected"); TST_CHECKPOINT_WAKE(0); }
void dirtyc0w_test(void) { int i, fd, pid, fail = 0; char c; /* Create file */ fd = SAFE_OPEN(FNAME, O_WRONLY|O_CREAT|O_EXCL, 0444); SAFE_WRITE(1, fd, STR, sizeof(STR)-1); SAFE_CLOSE(fd); pid = SAFE_FORK(); if (!pid) { SAFE_SETGID(nobody_gid); SAFE_SETUID(nobody_uid); SAFE_EXECLP("dirtyc0w_child", "dirtyc0w_child", NULL); } TST_CHECKPOINT_WAIT(0); for (i = 0; i < 100; i++) { usleep(10000); SAFE_FILE_SCANF(FNAME, "%c", &c); if (c != 't') { fail = 1; break; } } SAFE_KILL(pid, SIGUSR1); tst_reap_children(); SAFE_UNLINK(FNAME); if (fail) tst_res(TFAIL, "Bug reproduced!"); else tst_res(TPASS, "Bug not reproduced"); }