Skip to content

Commit

Permalink
--ro-root will make proc and sysfs read-only now
Browse files Browse the repository at this point in the history
  • Loading branch information
Moe-hacker committed Nov 23, 2024
1 parent d7213a1 commit 329fc85
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/chroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,13 @@ static void init_container(struct RURI_CONTAINER *_Nonnull container)
mkdir("/sys", S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP);
mkdir("/proc", S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP);
mkdir("/dev", S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP);
mount("proc", "/proc", "proc", MS_NOSUID | MS_NOEXEC | MS_NODEV, NULL);
mount("sysfs", "/sys", "sysfs", MS_NOSUID | MS_NOEXEC | MS_NODEV, NULL);
if (container->ro_root) {
mount("proc", "/proc", "proc", MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_RDONLY, NULL);
mount("sysfs", "/sys", "sysfs", MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_RDONLY, NULL);
} else {
mount("proc", "/proc", "proc", MS_NOSUID | MS_NOEXEC | MS_NODEV, NULL);
mount("sysfs", "/sys", "sysfs", MS_NOSUID | MS_NOEXEC | MS_NODEV, NULL);
}
mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "size=65536k,mode=755");
// Continue mounting some other directories in /dev.
mkdir("/dev/pts", S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP);
Expand Down

0 comments on commit 329fc85

Please sign in to comment.