mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-08-22 13:17:43 +00:00
Add mount namespace mode
This commit is contained in:
Submodule MagiskManager updated: bc576a9659...d3ff482c9b
@@ -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() {
|
|||||||
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);
|
||||||
|
2
jni/su
2
jni/su
Submodule jni/su updated: 38cc9dfec8...1bbf96a0a7
@@ -1,6 +1,7 @@
|
|||||||
/* 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 @@
|
|||||||
#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) {
|
|||||||
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);
|
|||||||
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
|
||||||
|
Reference in New Issue
Block a user