staticbool test_priv_mount_unpriv_remount(void)
{
pid_t child; int ret; constchar *orig_path = "/dev"; constchar *dest_path = "/tmp"; int orig_mnt_flags, remount_mnt_flags;
child = fork(); if (child == -1) {
die("fork failed: %s\n",
strerror(errno));
} if (child != 0) { /* parent */
pid_t pid; int status;
pid = waitpid(child, &status, 0); if (pid == -1) {
die("waitpid failed: %s\n",
strerror(errno));
} if (pid != child) {
die("waited for %d got %d\n",
child, pid);
} if (!WIFEXITED(status)) {
die("child did not terminate cleanly\n");
} return WEXITSTATUS(status) == EXIT_SUCCESS;
}
orig_mnt_flags = read_mnt_flags(orig_path);
create_and_enter_userns();
ret = unshare(CLONE_NEWNS); if (ret != 0) {
die("unshare(CLONE_NEWNS) failed: %s\n",
strerror(errno));
}
ret = mount(orig_path, dest_path, "bind", MS_BIND | MS_REC, NULL); if (ret != 0) {
die("recursive bind mount of %s onto %s failed: %s\n",
orig_path, dest_path, strerror(errno));
}
ret = mount(dest_path, dest_path, "none",
MS_REMOUNT | MS_BIND | orig_mnt_flags , NULL); if (ret != 0) { /* system("cat /proc/self/mounts"); */
die("remount of /tmp failed: %s\n",
strerror(errno));
}
remount_mnt_flags = read_mnt_flags(dest_path); if (orig_mnt_flags != remount_mnt_flags) {
die("Mount flags unexpectedly changed during remount of %s originally mounted on %s\n",
dest_path, orig_path);
} exit(EXIT_SUCCESS);
}
int main(int argc, char **argv)
{ if (!test_unpriv_remount_simple(MS_RDONLY)) {
die("MS_RDONLY malfunctions\n");
} if (!test_unpriv_remount("devpts", "newinstance", MS_NODEV, MS_NODEV, 0)) {
die("MS_NODEV malfunctions\n");
} if (!test_unpriv_remount_simple(MS_NOSUID)) {
die("MS_NOSUID malfunctions\n");
} if (!test_unpriv_remount_simple(MS_NOEXEC)) {
die("MS_NOEXEC malfunctions\n");
} if (!test_unpriv_remount_atime(MS_RELATIME,
MS_NOATIME))
{
die("MS_RELATIME malfunctions\n");
} if (!test_unpriv_remount_atime(MS_STRICTATIME,
MS_NOATIME))
{
die("MS_STRICTATIME malfunctions\n");
} if (!test_unpriv_remount_atime(MS_NOATIME,
MS_STRICTATIME))
{
die("MS_NOATIME malfunctions\n");
} if (!test_unpriv_remount_atime(MS_RELATIME|MS_NODIRATIME,
MS_NOATIME))
{
die("MS_RELATIME|MS_NODIRATIME malfunctions\n");
} if (!test_unpriv_remount_atime(MS_STRICTATIME|MS_NODIRATIME,
MS_NOATIME))
{
die("MS_STRICTATIME|MS_NODIRATIME malfunctions\n");
} if (!test_unpriv_remount_atime(MS_NOATIME|MS_NODIRATIME,
MS_STRICTATIME))
{
die("MS_NOATIME|MS_DIRATIME malfunctions\n");
} if (!test_unpriv_remount("ramfs", NULL, MS_STRICTATIME, 0, MS_NOATIME))
{
die("Default atime malfunctions\n");
} if (!test_priv_mount_unpriv_remount()) {
die("Mount flags unexpectedly changed after remount\n");
} return EXIT_SUCCESS;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.