tools/testing/selftests/mount/unprivileged-remount-test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mount/unprivileged-remount-test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mount/unprivileged-remount-test.c- Extension
.c- Size
- 8385 bytes
- Lines
- 372
- 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
sched.hstdio.herrno.hstring.hsys/types.hsys/mount.hsys/wait.hsys/vfs.hsys/statvfs.hstdlib.hunistd.hfcntl.hgrp.hstdbool.hstdarg.h
Detected Declarations
function diefunction vmaybe_write_filefunction maybe_write_filefunction write_filefunction read_mnt_flagsfunction create_and_enter_usernsfunction test_unpriv_remountfunction test_unpriv_remount_simplefunction test_unpriv_remount_atimefunction test_priv_mount_unpriv_remountfunction main
Annotated Snippet
if (written >= 0) {
die("short write to %s\n", filename);
} else {
die("write to %s failed: %s\n",
filename, strerror(errno));
}
}
if (close(fd) != 0) {
die("close of %s failed: %s\n",
filename, strerror(errno));
}
}
static void maybe_write_file(char *filename, char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vmaybe_write_file(true, filename, fmt, ap);
va_end(ap);
}
static void write_file(char *filename, char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vmaybe_write_file(false, filename, fmt, ap);
va_end(ap);
}
static int read_mnt_flags(const char *path)
{
int ret;
struct statvfs stat;
int mnt_flags;
ret = statvfs(path, &stat);
if (ret != 0) {
die("statvfs of %s failed: %s\n",
path, strerror(errno));
}
if (stat.f_flag & ~(ST_RDONLY | ST_NOSUID | ST_NODEV | \
ST_NOEXEC | ST_NOATIME | ST_NODIRATIME | ST_RELATIME | \
ST_SYNCHRONOUS | ST_MANDLOCK)) {
die("Unrecognized mount flags\n");
}
mnt_flags = 0;
if (stat.f_flag & ST_RDONLY)
mnt_flags |= MS_RDONLY;
if (stat.f_flag & ST_NOSUID)
mnt_flags |= MS_NOSUID;
if (stat.f_flag & ST_NODEV)
mnt_flags |= MS_NODEV;
if (stat.f_flag & ST_NOEXEC)
mnt_flags |= MS_NOEXEC;
if (stat.f_flag & ST_NOATIME)
mnt_flags |= MS_NOATIME;
if (stat.f_flag & ST_NODIRATIME)
mnt_flags |= MS_NODIRATIME;
if (stat.f_flag & ST_RELATIME)
mnt_flags |= MS_RELATIME;
if (stat.f_flag & ST_SYNCHRONOUS)
mnt_flags |= MS_SYNCHRONOUS;
if (stat.f_flag & ST_MANDLOCK)
mnt_flags |= ST_MANDLOCK;
return mnt_flags;
}
static void create_and_enter_userns(void)
{
uid_t uid;
gid_t gid;
uid = getuid();
gid = getgid();
if (unshare(CLONE_NEWUSER) !=0) {
die("unshare(CLONE_NEWUSER) failed: %s\n",
strerror(errno));
}
maybe_write_file("/proc/self/setgroups", "deny");
write_file("/proc/self/uid_map", "0 %d 1", uid);
write_file("/proc/self/gid_map", "0 %d 1", gid);
if (setgid(0) != 0) {
Annotation
- Immediate include surface: `sched.h`, `stdio.h`, `errno.h`, `string.h`, `sys/types.h`, `sys/mount.h`, `sys/wait.h`, `sys/vfs.h`.
- Detected declarations: `function die`, `function vmaybe_write_file`, `function maybe_write_file`, `function write_file`, `function read_mnt_flags`, `function create_and_enter_userns`, `function test_unpriv_remount`, `function test_unpriv_remount_simple`, `function test_unpriv_remount_atime`, `function test_priv_mount_unpriv_remount`.
- 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.