tools/testing/selftests/filesystems/overlayfs/set_layers_via_fds.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/overlayfs/set_layers_via_fds.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/filesystems/overlayfs/set_layers_via_fds.c
Extension
.c
Size
23497 bytes
Lines
721
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (sys_fsconfig(fd_context, FSCONFIG_SET_FLAG, "override_creds", NULL, 0)) {
			TH_LOG("sys_fsconfig should have succeeded");
			_exit(EXIT_FAILURE);
		}

		_exit(EXIT_SUCCESS);
	}
	ASSERT_GE(sys_waitid(P_PID, pid, NULL, WEXITED), 0);
	ASSERT_GE(close(pidfd), 0);

	pid = create_child(&pidfd, 0);
	ASSERT_GE(pid, 0);
	if (pid == 0) {
		if (sys_fsconfig(fd_context, FSCONFIG_SET_FLAG, "nooverride_creds", NULL, 0)) {
			TH_LOG("sys_fsconfig should have succeeded");
			_exit(EXIT_FAILURE);
		}

		_exit(EXIT_SUCCESS);
	}
	ASSERT_GE(sys_waitid(P_PID, pid, NULL, WEXITED), 0);
	ASSERT_GE(close(pidfd), 0);

	pid = create_child(&pidfd, 0);
	ASSERT_GE(pid, 0);
	if (pid == 0) {
		if (sys_fsconfig(fd_context, FSCONFIG_SET_FLAG, "override_creds", NULL, 0)) {
			TH_LOG("sys_fsconfig should have succeeded");
			_exit(EXIT_FAILURE);
		}

		_exit(EXIT_SUCCESS);
	}
	ASSERT_GE(sys_waitid(P_PID, pid, NULL, WEXITED), 0);
	ASSERT_GE(close(pidfd), 0);

	ASSERT_EQ(sys_fsconfig(fd_context, FSCONFIG_CMD_CREATE, NULL, NULL, 0), 0);

	fd_overlay = sys_fsmount(fd_context, 0, 0);
	ASSERT_GE(fd_overlay, 0);

	ASSERT_EQ(sys_move_mount(fd_overlay, "", -EBADF, "/set_layers_via_fds", MOVE_MOUNT_F_EMPTY_PATH), 0);

	ASSERT_EQ(close(fd_context), 0);
	ASSERT_EQ(close(fd_overlay), 0);
}

TEST_F(set_layers_via_fds, set_override_creds_invalid)
{
	int fd_context, fd_tmpfs, fd_overlay, ret;
	int layer_fds[] = { [0 ... 3] = -EBADF };
	pid_t pid;
	int fd_userns1, fd_userns2;
	int ipc_sockets[2];
	char c;
	const unsigned int predictable_fd_context_nr = 123;

	fd_userns1 = get_userns_fd(0, 0, 10000);
	ASSERT_GE(fd_userns1, 0);

	fd_userns2 = get_userns_fd(0, 1234, 10000);
	ASSERT_GE(fd_userns2, 0);

	ret = socketpair(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0, ipc_sockets);
	ASSERT_GE(ret, 0);

	pid = create_child(&self->pidfd, 0);
	ASSERT_GE(pid, 0);
	if (pid == 0) {
		if (close(ipc_sockets[0])) {
			TH_LOG("close should have succeeded");
			_exit(EXIT_FAILURE);
		}

		if (!switch_userns(fd_userns2, 0, 0, false)) {
			TH_LOG("switch_userns should have succeeded");
			_exit(EXIT_FAILURE);
		}

		if (read_nointr(ipc_sockets[1], &c, 1) != 1) {
			TH_LOG("read_nointr should have succeeded");
			_exit(EXIT_FAILURE);
		}

		if (close(ipc_sockets[1])) {
			TH_LOG("close should have succeeded");
			_exit(EXIT_FAILURE);
		}

		if (!sys_fsconfig(predictable_fd_context_nr, FSCONFIG_SET_FLAG, "override_creds", NULL, 0)) {

Annotation

Implementation Notes