1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| static void init_rootless_container(struct CONTAINER *_Nonnull container) {
chdir(container->container_dir); mkdir("./sys", S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP); mount("/sys", "./sys", NULL, MS_BIND | MS_REC, NULL); mkdir("./proc", S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP); mount("proc", "./proc", "proc", MS_NOSUID | MS_NOEXEC | MS_NODEV, NULL); mkdir("./dev", S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP); mount("tmpfs", "./dev", "tmpfs", MS_NOSUID, "size=65536k,mode=755"); close(open("./dev/tty", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP)); mount("/dev/tty", "./dev/tty", NULL, MS_BIND, NULL); close(open("./dev/console", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP)); mount("/dev/console", "./dev/console", NULL, MS_BIND, NULL); close(open("./dev/null", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP)); mount("/dev/null", "./dev/null", NULL, MS_BIND, NULL); close(open("./dev/ptmx", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP)); mount("/dev/ptmx", "./dev/ptmx", NULL, MS_BIND, NULL); close(open("./dev/random", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP)); mount("/dev/random", "./dev/random", NULL, MS_BIND, NULL); close(open("./dev/urandom", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP)); mount("/dev/urandom", "./dev/urandom", NULL, MS_BIND, NULL); close(open("./dev/zero", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP)); mount("/dev/zero", "./dev/zero", NULL, MS_BIND, NULL); symlink("/proc/self/fd", "./dev/fd"); symlink("/proc/self/fd/0", "./dev/stdin"); symlink("/proc/self/fd/1", "./dev/stdout"); symlink("/proc/self/fd/2", "./dev/stderr"); symlink("/dev/null", "./dev/tty0"); mkdir("./dev/pts", S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP); mount("devpts", "./dev/pts", "devpts", 0, "gid=4,mode=620"); mkdir("./dev/shm", S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP); mount("tmpfs", "./dev/shm", "tmpfs", MS_NOSUID | MS_NOEXEC | MS_NODEV, "mode=1777"); mount("./proc/bus", "./proc/bus", NULL, MS_BIND | MS_REC, NULL); mount("./proc/bus", "./proc/bus", NULL, MS_BIND | MS_RDONLY | MS_REMOUNT, NULL); mount("./proc/fs", "./proc/fs", NULL, MS_BIND | MS_REC, NULL); mount("./proc/fs", "./proc/fs", NULL, MS_BIND | MS_RDONLY | MS_REMOUNT, NULL); mount("./proc/irq", "./proc/irq", NULL, MS_BIND | MS_REC, NULL); mount("./proc/irq", "./proc/irq", NULL, MS_BIND | MS_RDONLY | MS_REMOUNT, NULL); mount("./proc/sys", "./proc/sys", NULL, MS_BIND | MS_REC, NULL); mount("./proc/sys", "./proc/sys", NULL, MS_BIND | MS_RDONLY | MS_REMOUNT, NULL); mount("./proc/sys-trigger", "./proc/sys-trigger", NULL, MS_BIND | MS_REC, NULL); mount("./proc/sys-trigger", "./proc/sys-trigger", NULL, MS_BIND | MS_RDONLY | MS_REMOUNT, NULL); mount("tmpfs", "./proc/asound", "tmpfs", MS_RDONLY, NULL); mount("tmpfs", "./proc/acpi", "tmpfs", MS_RDONLY, NULL); mount("/dev/null", "./proc/kcore", "", MS_BIND, NULL); mount("/dev/null", "./proc/keys", "", MS_BIND, NULL); mount("/dev/null", "./proc/latency_stats", "", MS_BIND, NULL); mount("/dev/null", "./proc/timer_list", "", MS_BIND, NULL); mount("/dev/null", "./proc/timer_stats", "", MS_BIND, NULL); mount("/dev/null", "./proc/sched_debug", "", MS_BIND, NULL); mount("tmpfs", "./proc/scsi", "tmpfs", MS_RDONLY, NULL); mount("tmpfs", "./sys/firmware", "tmpfs", MS_RDONLY, NULL); mount("tmpfs", "./sys/devices/virtual/powercap", "tmpfs", MS_RDONLY, NULL); mount("tmpfs", "./sys/block", "tmpfs", MS_RDONLY, NULL); }
|