示例#1
0
文件: userns03.c 项目: xingdl2007/ltp
int main(int argc, char *argv[])
{
	pid_t cpid2;
	char path[BUFSIZ];
	int lc;
	int fd;

	tst_parse_opts(argc, argv, NULL, NULL);
	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;

		parentuid = geteuid();
		parentgid = getegid();

		cpid1 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
			(void *)child_fn1, NULL);
		if (cpid1 < 0)
			tst_brkm(TBROK | TERRNO, cleanup,
				"cpid1 clone failed");

		cpid2 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
			(void *)child_fn2, NULL);
		if (cpid2 < 0)
			tst_brkm(TBROK | TERRNO, cleanup,
				"cpid2 clone failed");

		if (setgroupstag == false) {
			sprintf(path, "/proc/%d/setgroups", cpid1);
			fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
			SAFE_WRITE(cleanup, 1, fd, "deny", 4);
			SAFE_CLOSE(cleanup, fd);

			sprintf(path, "/proc/%d/setgroups", cpid2);
			fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
			SAFE_WRITE(cleanup, 1, fd, "deny", 4);
			SAFE_CLOSE(cleanup, fd);
		}

		updatemap(cpid1, UID_MAP, CHILD1UID, parentuid, cleanup);
		updatemap(cpid2, UID_MAP, CHILD2UID, parentuid, cleanup);

		updatemap(cpid1, GID_MAP, CHILD1GID, parentuid, cleanup);
		updatemap(cpid2, GID_MAP, CHILD2GID, parentuid, cleanup);

		TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(cleanup, 1);

		tst_record_childstatus(cleanup, cpid1);
		tst_record_childstatus(cleanup, cpid2);
	}
	cleanup();
	tst_exit();
}
示例#2
0
文件: execl01.c 项目: Semihalf/ltp
int main(int ac, char **av)
{
	int lc;
	pid_t pid;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		switch (pid = FORK_OR_VFORK()) {
		case 0:
			execl("execl01_child", "execl01_child", "canary", NULL);
			tst_brkm(TFAIL | TERRNO, NULL,
			         "Failed to execute execl01_child");
		case -1:
			tst_brkm(TBROK | TERRNO, NULL, "fork failed");
		default:
			tst_record_childstatus(NULL, pid);
		}

	}

	tst_exit();
}
示例#3
0
文件: execv01.c 项目: 1587/ltp
int main(int ac, char **av)
{
	int lc;
	pid_t pid;
	char *const args[] = { "execv01_child", "canary", NULL};
	char path[2048];

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

	if (tst_get_path("execv01_child", path, sizeof(path)))
		tst_brkm(TCONF, NULL, "Couldn't find execv01_child in $PATH");

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		switch (pid = FORK_OR_VFORK()) {
		case 0:
			execv(path, args);
			tst_brkm(TFAIL | TERRNO, NULL,
			         "Failed to execute execv01_child");
		case -1:
			tst_brkm(TBROK, NULL, "fork failed");
		default:
			tst_record_childstatus(NULL, pid);
		}
	}

	tst_exit();
}
示例#4
0
文件: kcmp01.c 项目: AiprNick/ltp
int main(int ac, char **av)
{
	int lc;
	int i;

	tst_parse_opts(ac, av, NULL, NULL);
	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;

		for (i = 0; i < TST_TOTAL; ++i) {
			pid2 = tst_fork();

			if (pid2 == -1)
				tst_brkm(TBROK, cleanup, "fork failed");

			if (!pid2)
				do_child(&test_cases[i]);
			else
				tst_record_childstatus(cleanup, pid2);
			tst_count++;
		}
	}

	cleanup();
	tst_exit();
}
示例#5
0
文件: fcntl33.c 项目: CSRedRat/ltp
static void do_test(int i)
{
	pid_t cpid;

	cpid = tst_fork();
	if (cpid < 0)
		tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");

	if (cpid == 0)
		do_child(i);

	fd = SAFE_OPEN(cleanup, "file", O_RDONLY);

	TEST(fcntl(fd, F_SETLEASE, test_cases[i].lease_type));
	if (TEST_RETURN == -1) {
		tst_resm(TFAIL | TTERRNO, "fcntl() failed to set lease");
		SAFE_WAITPID(cleanup, cpid, NULL, 0);
		SAFE_CLOSE(cleanup, fd);
		fd = 0;
		return;
	}

	/* Wait for SIGIO caused by lease breaker. */
	TEST(sigtimedwait(&newset, NULL, &timeout));
	if (TEST_RETURN == -1) {
		if (TEST_ERRNO == EAGAIN) {
			tst_resm(TFAIL | TTERRNO, "failed to receive SIGIO "
				 "within %lis", timeout.tv_sec);
			SAFE_WAITPID(cleanup, cpid, NULL, 0);
			SAFE_CLOSE(cleanup, fd);
			fd = 0;
			return;
		}
		tst_brkm(TBROK | TTERRNO, cleanup, "sigtimedwait() failed");
	}

	/* Try to downgrade or remove the lease. */
	switch (test_cases[i].lease_type) {
	case F_WRLCK:
		TEST(fcntl(fd, F_SETLEASE, F_RDLCK));
		if (TEST_RETURN == 0)
			break;
	case F_RDLCK:
		TEST(fcntl(fd, F_SETLEASE, F_UNLCK));
		if (TEST_RETURN == -1) {
			tst_resm(TFAIL | TTERRNO,
				 "fcntl() failed to remove the lease");
		}
		break;
	default:
		break;
	}

	tst_record_childstatus(cleanup, cpid);

	SAFE_CLOSE(cleanup, fd);
	fd = 0;
}
示例#6
0
文件: setresuid02.c 项目: 1587/ltp
int main(int ac, char **av)
{
	int lc;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		int i, pid;

		/* reset tst_count in case we are looping */
		tst_count = 0;

		/* set the appropriate ownership values */
		if (setresuid(nobody_pw_uid, bin_pw_uid, nobody_pw_uid) == -1) {
			tst_brkm(TFAIL, cleanup, "Initial setresuid failed");
		}

		if ((pid = FORK_OR_VFORK()) == -1) {
			tst_brkm(TBROK, cleanup, "fork failed");
		} else if (pid == 0) {	/* child */

			for (i = 0; i < TST_TOTAL; i++) {

				/* Set the real, effective or saved user id */
				TEST(SETRESUID(NULL, *test_data[i].real_uid,
					       *test_data[i].eff_uid,
					       *test_data[i].sav_uid));

				if (TEST_RETURN != -1) {
					tst_resm(TPASS, "setresuid(%d, %d, %d) "
						 "succeeded as expected.",
						 *test_data[i].real_uid,
						 *test_data[i].eff_uid,
						 *test_data[i].sav_uid);
				} else {
					tst_resm(TFAIL, "setresuid(%d, %d, %d) "
						 "did not return as expected.",
						 *test_data[i].real_uid,
						 *test_data[i].eff_uid,
						 *test_data[i].sav_uid);
					flag = -1;
				}

				uid_verify(test_data[i].exp_real_usr,
					   test_data[i].exp_eff_usr,
					   test_data[i].exp_sav_usr,
					   test_data[i].test_msg);
			}
			exit(flag);
		} else {	/* parent */
			tst_record_childstatus(cleanup, pid);
		}
	}
	cleanup();
	tst_exit();
}
示例#7
0
文件: futex_wake02.c 项目: 1587/ltp
/*
 * We do the real test in a child because with the test -i parameter the loop
 * that checks that all threads are sleeping may fail with ENOENT. That is
 * because some of the threads from previous run may still be there.
 *
 * Which is because the userspace part of pthread_join() sleeps in a futex on a
 * pthread tid which is woken up at the end of the exit_mm(tsk) which is before
 * the process is removed from the parent thread_group list. So there is a
 * small race window where the readdir() returns the process tid as a directory
 * under /proc/$PID/tasks/, but the subsequent open() fails with ENOENT because
 * the thread was removed meanwhile.
 */
static void verify_futex_wake(void)
{
	int pid;

	pid = tst_fork();

	switch (pid) {
	case 0:
		do_child();
	case -1:
		tst_brkm(TBROK | TERRNO, NULL, "fork() failed");
	default:
		tst_record_childstatus(NULL, pid);
	}
}
示例#8
0
文件: sighold02.c 项目: kraj/ltp
int main(int ac, char **av)
{
	int sig;
	int lc;

	tst_parse_opts(ac, av, NULL, NULL);

#ifdef UCLINUX
	maybe_run_child(&do_child, "");
#endif

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		if ((pid = FORK_OR_VFORK()) < 0) {
			tst_brkm(TBROK | TERRNO, NULL, "fork() failed");
		} else if (pid > 0) {
			TST_SAFE_CHECKPOINT_WAIT(NULL, 0);

			for (sig = 1; sig < NUMSIGS; sig++) {
				if (skip_sig(sig))
					continue;
				SAFE_KILL(NULL, pid, sig);
			}

			TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
			tst_record_childstatus(cleanup, pid);
		} else {

#ifdef UCLINUX
			if (self_exec(av[0], "") < 0) {
				tst_brkm(TBROK | TERRNO, NULL,
					 "self_exec() failed");
			}
#else
			do_child();
#endif
		}
	}

	cleanup();
	tst_exit();
}
示例#9
0
文件: setresuid04.c 项目: kraj/ltp
int main(int ac, char **av)
{
	pid_t pid;

	tst_parse_opts(ac, av, NULL, NULL);
	setup();

	pid = FORK_OR_VFORK();
	if (pid < 0)
		tst_brkm(TBROK, cleanup, "Fork failed");

	if (pid == 0)
		do_master_child();

	tst_record_childstatus(cleanup, pid);

	cleanup();
	tst_exit();
}
示例#10
0
文件: vhangup01.c 项目: AbhiramiP/ltp
int main(int argc, char **argv)
{
	int lc;

	pid_t pid;
	int retval;

	tst_parse_opts(argc, argv, NULL, NULL);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;

		if ((pid = FORK_OR_VFORK()) < 0) {
			tst_brkm(TFAIL, NULL, "fork failed");
		} else if (pid > 0) {
			tst_record_childstatus(NULL, pid);
		} else {
			retval = setreuid(nobody_uid, nobody_uid);
			if (retval < 0) {
				perror("setreuid");
				tst_brkm(TFAIL, NULL, "setreuid failed");
			}
			TEST(vhangup());
			if (TEST_RETURN != -1) {
				tst_brkm(TFAIL, NULL, "vhangup() failed to "
					 "fail");
			} else if (TEST_ERRNO == EPERM) {
				tst_resm(TPASS, "Got EPERM as expected.");
			} else {
				tst_resm(TFAIL, "expected EPERM got %d",
					 TEST_ERRNO);
			}
		}
	}

	tst_exit();
}
示例#11
0
文件: execve02.c 项目: 1587/ltp
int main(int ac, char **av)
{
	int lc;
	pid_t pid;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		if ((pid = FORK_OR_VFORK()) == -1)
			tst_brkm(TBROK | TERRNO, cleanup, "fork failed");

		if (pid == 0)
			do_child();

		tst_record_childstatus(cleanup, pid);
	}

	cleanup();
	tst_exit();
}
示例#12
0
文件: setreuid05.c 项目: MohdVara/ltp
int main(int argc, char **argv)
{
	int lc;
	const char *msg;

	if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();

	pass = 0;

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		int i, pid;

		tst_count = 0;

		if ((pid = FORK_OR_VFORK()) == -1) {
			tst_brkm(TBROK, cleanup, "fork failed");
		} else if (pid == 0) {	/* child */
			for (i = 0; i < TST_TOTAL; i++) {
				/* Set the real or effective user id */
				TEST(SETREUID(cleanup, *test_data[i].real_uid,
					      *test_data[i].eff_uid));

				if (TEST_RETURN == *test_data[i].exp_ret) {
					if (TEST_RETURN == neg_one) {
						if (TEST_ERRNO != EPERM) {
							tst_resm(TFAIL,
								 "setreuid(%d, %d) "
								 "did not set errno "
								 "value as expected.",
								 *test_data
								 [i].real_uid,
								 *test_data
								 [i].eff_uid);
							continue;
						}
						tst_resm(TPASS,
							 "setreuid(%d, %d) "
							 "failed as expected.",
							 *test_data[i].real_uid,
							 *test_data[i].eff_uid);
					} else {
						tst_resm(TPASS,
							 "setreuid(%d, %d) "
							 "succeeded as expected.",
							 *test_data[i].real_uid,
							 *test_data[i].eff_uid);
					}
				} else {
					tst_resm(TFAIL, "setreuid(%d, %d) "
						 "did not return as expected.",
						 *test_data[i].real_uid,
						 *test_data[i].eff_uid);
				}

				if (TEST_RETURN == -1) {
					TEST_ERROR_LOG(TEST_ERRNO);
				}
				uid_verify(test_data[i].exp_real_usr,
					   test_data[i].exp_eff_usr,
					   test_data[i].test_msg);
			}
			tst_exit();
		} else {	/* parent */
			tst_record_childstatus(cleanup, pid);
		}
	}
	cleanup();
	tst_exit();
}
示例#13
0
文件: userns03.c 项目: AiprNick/ltp
int main(int argc, char *argv[])
{
	pid_t cpid2;
	char path[BUFSIZ];
	int lc;
	int fd;
	int ret;

	tst_parse_opts(argc, argv, NULL, NULL);
	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;

		parentuid = geteuid();
		parentgid = getegid();

		cpid1 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
			(void *)child_fn1, NULL);
		if (cpid1 < 0)
			tst_brkm(TBROK | TERRNO, cleanup,
				"cpid1 clone failed");

		cpid2 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
			(void *)child_fn2, NULL);
		if (cpid2 < 0)
			tst_brkm(TBROK | TERRNO, cleanup,
				"cpid2 clone failed");

		if (access("/proc/self/setgroups", F_OK) == 0) {
			sprintf(path, "/proc/%d/setgroups", cpid1);
			fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
			SAFE_WRITE(cleanup, 1, fd, "deny", 4);
			SAFE_CLOSE(cleanup, fd);
			/* If the setgroups file has the value "deny",
			 * then the setgroups(2) system call can't
			 * subsequently be reenabled (by writing "allow" to
			 * the file) in this user namespace.  (Attempts to
			 * do so will fail with the error EPERM.)
			*/

			/* test that setgroups can't be re-enabled */
			fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
			ret = write(fd, "allow", 5);

			if (ret != -1) {
				tst_brkm(TBROK | TERRNO, cleanup,
					"write action should fail");
			} else if (errno != EPERM) {
				tst_brkm(TBROK | TERRNO, cleanup,
					"unexpected error: \n");
			}
			SAFE_CLOSE(cleanup, fd);
			tst_resm(TPASS, "setgroups can't be re-enabled");

			sprintf(path, "/proc/%d/setgroups", cpid2);
			fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
			SAFE_WRITE(cleanup, 1, fd, "deny", 4);
			SAFE_CLOSE(cleanup, fd);
		}

		updatemap(cpid1, UID_MAP, CHILD1UID, parentuid, cleanup);
		updatemap(cpid2, UID_MAP, CHILD2UID, parentuid, cleanup);

		updatemap(cpid1, GID_MAP, CHILD1GID, parentgid, cleanup);
		updatemap(cpid2, GID_MAP, CHILD2GID, parentgid, cleanup);

		TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(cleanup, 1);

		tst_record_childstatus(cleanup, cpid1);
		tst_record_childstatus(cleanup, cpid2);
	}
	cleanup();
	tst_exit();
}