tools/testing/selftests/landlock/fs_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/landlock/fs_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/landlock/fs_test.c- Extension
.c- Size
- 275589 bytes
- Lines
- 10193
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
asm/termbits.hfcntl.hlibgen.hlinux/fiemap.hlinux/landlock.hlinux/magic.hsched.hstddef.hstdio.hstring.hsys/capability.hsys/ioctl.hsys/mount.hsys/prctl.hsys/resource.hsys/sendfile.hsys/socket.hsys/stat.hsys/sysmacros.hsys/un.hsys/vfs.hunistd.hlinux/fs.hlinux/mount.hlinux/fcntl.haudit.hcommon.hscoped_base_variants.h
Detected Declarations
struct mnt_optstruct rulestruct space_resvstruct a_rulestruct a_layerstruct a_targetenum relative_accessfunction renameat2function open_treefunction sys_execveatfunction fgrepfunction supports_filesystemfunction cwd_matches_fsfunction mkdir_parentsfunction ASSERT_FALSEfunction create_directoryfunction create_filefunction remove_pathfunction mount_optfunction prepare_layout_optfunction prepare_layoutfunction cleanup_layoutfunction create_layout1function remove_layout1function test_open_relfunction test_openfunction add_path_beneathfunction create_rulesetfunction enforce_fsfunction test_relative_pathfunction ASSERT_EQfunction ASSERT_EQfunction copy_filefunction test_executefunction ASSERT_EQfunction test_check_execfunction bin_sandbox_and_launchfunction test_renamefunction test_exchangefunction test_renameatfunction test_exchangeatfunction refer_denied_by_defaultfunction accessfunction accessfunction reparent_exdev_layers_enforce1function reparent_exdev_layers_enforce2function test_make_filefunction ASSERT_EQ
Annotated Snippet
struct mnt_opt {
const char *const source;
const char *const type;
const unsigned long flags;
const char *const data;
};
#define MNT_TMP_DATA "size=4m,mode=700"
static const struct mnt_opt mnt_tmp = {
.type = "tmpfs",
.data = MNT_TMP_DATA,
};
static int mount_opt(const struct mnt_opt *const mnt, const char *const target)
{
return mount(mnt->source ?: mnt->type, target, mnt->type, mnt->flags,
mnt->data);
}
static void prepare_layout_opt(struct __test_metadata *const _metadata,
const struct mnt_opt *const mnt)
{
disable_caps(_metadata);
umask(0077);
create_directory(_metadata, TMP_DIR);
/*
* Do not pollute the rest of the system: creates a private mount point
* for tests relying on pivot_root(2) and move_mount(2).
*/
set_cap(_metadata, CAP_SYS_ADMIN);
ASSERT_EQ(0, unshare(CLONE_NEWNS | CLONE_NEWCGROUP));
ASSERT_EQ(0, mount_opt(mnt, TMP_DIR))
{
TH_LOG("Failed to mount the %s filesystem: %s", mnt->type,
strerror(errno));
/*
* FIXTURE_TEARDOWN() is not called when FIXTURE_SETUP()
* failed, so we need to explicitly do a minimal cleanup to
* avoid cascading errors with other tests that don't depend on
* the same filesystem.
*/
remove_path(TMP_DIR);
}
ASSERT_EQ(0, mount(NULL, TMP_DIR, NULL, MS_PRIVATE | MS_REC, NULL));
clear_cap(_metadata, CAP_SYS_ADMIN);
}
static void prepare_layout(struct __test_metadata *const _metadata)
{
prepare_layout_opt(_metadata, &mnt_tmp);
}
static void cleanup_layout(struct __test_metadata *const _metadata)
{
set_cap(_metadata, CAP_SYS_ADMIN);
if (umount(TMP_DIR)) {
/*
* According to the test environment, the mount point of the
* current directory may be shared or not, which changes the
* visibility of the nested TMP_DIR mount point for the test's
* parent process doing this cleanup.
*/
ASSERT_EQ(EINVAL, errno);
}
clear_cap(_metadata, CAP_SYS_ADMIN);
EXPECT_EQ(0, remove_path(TMP_DIR));
}
/* clang-format off */
FIXTURE(layout0) {};
/* clang-format on */
FIXTURE_SETUP(layout0)
{
prepare_layout(_metadata);
}
FIXTURE_TEARDOWN_PARENT(layout0)
{
cleanup_layout(_metadata);
}
static void create_layout1(struct __test_metadata *const _metadata)
{
create_file(_metadata, file1_s1d1);
create_file(_metadata, file1_s1d2);
create_file(_metadata, file1_s1d3);
create_file(_metadata, file2_s1d1);
Annotation
- Immediate include surface: `asm/termbits.h`, `fcntl.h`, `libgen.h`, `linux/fiemap.h`, `linux/landlock.h`, `linux/magic.h`, `sched.h`, `stddef.h`.
- Detected declarations: `struct mnt_opt`, `struct rule`, `struct space_resv`, `struct a_rule`, `struct a_layer`, `struct a_target`, `enum relative_access`, `function renameat2`, `function open_tree`, `function sys_execveat`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.