diff --git a/src/container.c b/src/container.c index 63a2d11..3eaabeb 100644 --- a/src/container.c +++ b/src/container.c @@ -102,13 +102,23 @@ static int container_setup_mount(struct hyper_container *container) hyper_mkdir("/sys"); hyper_mkdir("/dev"); - if (mount("proc", "/proc", "proc", 0, NULL) < 0 || - mount("sysfs", "/sys", "sysfs", 0, NULL) < 0 || - mount("devtmpfs", "/dev", "devtmpfs", 0, NULL) < 0) { + if (mount("proc", "/proc", "proc", MS_NOSUID| MS_NODEV| MS_NOEXEC, NULL) < 0 || + mount("sysfs", "/sys", "sysfs", MS_NOSUID| MS_NODEV| MS_NOEXEC, NULL) < 0 || + mount("devtmpfs", "/dev", "devtmpfs", MS_NOSUID, NULL) < 0) { perror("mount basic filesystem for container failed"); return -1; } + if (hyper_mkdir("/dev/shm") < 0) { + fprintf(stderr, "create /dev/shm failed\n"); + return -1; + } + + if (mount("tmpfs", "/dev/shm/", "tmpfs", MS_NOSUID| MS_NODEV, NULL) < 0) { + perror("mount shm failed"); + return -1; + } + if (hyper_mkdir("/dev/pts") < 0) { fprintf(stderr, "create /dev/pts failed\n"); return -1; diff --git a/src/init.c b/src/init.c index 58c2ecb..00b1d8b 100644 --- a/src/init.c +++ b/src/init.c @@ -319,7 +319,7 @@ static int hyper_pod_init(void *data) goto fail; } - if (mount("proc", "/proc", "proc", 0, NULL) < 0) { + if (mount("proc", "/proc", "proc", MS_NOSUID| MS_NODEV| MS_NOEXEC, NULL) < 0) { perror("mount proc filesystem failed\n"); goto fail; } @@ -1204,19 +1204,19 @@ int main(int argc, char *argv[]) return -1; } - if (mount("proc", "/proc", "proc", 0, NULL) == -1) { + if (mount("proc", "/proc", "proc", MS_NOSUID| MS_NODEV| MS_NOEXEC, NULL) == -1) { perror("mount proc failed"); return -1; } hyper_print_uptime(); - if (mount("sysfs", "/sys", "sysfs", 0, NULL) == -1) { + if (mount("sysfs", "/sys", "sysfs", MS_NOSUID| MS_NODEV| MS_NOEXEC, NULL) == -1) { perror("mount sysfs failed"); return -1; } - if (mount("dev", "/dev", "devtmpfs", 0, NULL) == -1) { + if (mount("dev", "/dev", "devtmpfs", MS_NOSUID, NULL) == -1) { perror("mount sysfs failed"); return -1; } @@ -1226,7 +1226,7 @@ int main(int argc, char *argv[]) return -1; } - if (mount("devpts", "/dev/pts", "devpts", 0, NULL) == -1) { + if (mount("devpts", "/dev/pts", "devpts", MS_NOSUID| MS_NOEXEC, NULL) == -1) { perror("mount devpts failed"); return -1; }