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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
Dependency Surface
fcntl.hsched.hstdio.hstring.hsys/socket.hsys/stat.hsys/sysmacros.hsys/mount.hunistd.hkselftest_harness.h../../pidfd/pidfd.hlog.h../utils.h../wrappers.h
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
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
- Immediate include surface: `fcntl.h`, `sched.h`, `stdio.h`, `string.h`, `sys/socket.h`, `sys/stat.h`, `sys/sysmacros.h`, `sys/mount.h`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.