Commit 0b4baad7 authored by topjohnwu's avatar topjohnwu

Add mount namespace mode

parent 201e32d4
Subproject commit bc576a9659651703dc4cd4eaebaa9293381a2ac8 Subproject commit d3ff482c9b46f58626fdcb6289ffa0cefbf2afcc
...@@ -56,7 +56,6 @@ int hide_daemon() { ...@@ -56,7 +56,6 @@ int hide_daemon() {
// When an error occurs, report its failure to main process // When an error occurs, report its failure to main process
err_handler = hide_daemon_err; err_handler = hide_daemon_err;
int fd;
char buffer[4096], cache_block[256], *line; char buffer[4096], cache_block[256], *line;
struct vector mount_list; struct vector mount_list;
...@@ -73,13 +72,8 @@ int hide_daemon() { ...@@ -73,13 +72,8 @@ int hide_daemon() {
manage_selinux(); manage_selinux();
relink_sbin(); relink_sbin();
snprintf(buffer, sizeof(buffer), "/proc/%d/ns/mnt", pid); if (switch_mnt_ns(pid))
if(access(buffer, F_OK) == -1) continue; // Maybe process died.. continue;
fd = xopen(buffer, O_RDONLY);
// Switch to its namespace
xsetns(fd, 0);
close(fd);
snprintf(buffer, sizeof(buffer), "/proc/%d/mounts", pid); snprintf(buffer, sizeof(buffer), "/proc/%d/mounts", pid);
vec_init(&mount_list); vec_init(&mount_list);
......
Subproject commit 38cc9dfec88bca246725d79157657e43e9363425 Subproject commit 1bbf96a0a7a942798df58883a376b8024d0fae7f
/* misc.c - Store all functions that are unable to be catagorized clearly /* misc.c - Store all functions that are unable to be catagorized clearly
*/ */
#define _GNU_SOURCE
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -10,6 +11,7 @@ ...@@ -10,6 +11,7 @@
#include <pwd.h> #include <pwd.h>
#include <signal.h> #include <signal.h>
#include <errno.h> #include <errno.h>
#include <sched.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/mount.h> #include <sys/mount.h>
...@@ -457,3 +459,17 @@ int resize_img(const char *img, int size) { ...@@ -457,3 +459,17 @@ int resize_img(const char *img, int size) {
snprintf(buffer, PATH_MAX, "e2fsck -yf %s; resize2fs %s %dM;", img, img, size); snprintf(buffer, PATH_MAX, "e2fsck -yf %s; resize2fs %s %dM;", img, img, size);
return system(buffer); return system(buffer);
} }
int switch_mnt_ns(int pid) {
char mnt[32];
snprintf(mnt, sizeof(mnt), "/proc/%d/ns/mnt", pid);
if(access(mnt, R_OK) == -1) return 1; // Maybe process died..
int fd, ret;
fd = xopen(mnt, O_RDONLY);
if (fd < 0) return 1;
// Switch to its namespace
ret = setns(fd, 0);
close(fd);
return ret;
}
...@@ -94,5 +94,6 @@ void get_client_cred(int fd, struct ucred *cred); ...@@ -94,5 +94,6 @@ void get_client_cred(int fd, struct ucred *cred);
int create_img(const char *img, int size); int create_img(const char *img, int size);
int get_img_size(const char *img, int *used, int *total); int get_img_size(const char *img, int *used, int *total);
int resize_img(const char *img, int size); int resize_img(const char *img, int size);
int switch_mnt_ns(int pid);
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment