diff --git a/native/jni/magiskhide/hide_policy.cpp b/native/jni/magiskhide/hide_policy.cpp index 63b0136f6..e462c32d1 100644 --- a/native/jni/magiskhide/hide_policy.cpp +++ b/native/jni/magiskhide/hide_policy.cpp @@ -41,7 +41,10 @@ void hide_daemon(int pid) { tgkill(pid, pid, SIGCONT); _exit(0); }); + hide_unmount(pid); +} +void hide_unmount(int pid) { if (switch_mnt_ns(pid)) return; diff --git a/native/jni/magiskhide/magiskhide.cpp b/native/jni/magiskhide/magiskhide.cpp index 688e5c0c0..0eef9e766 100644 --- a/native/jni/magiskhide/magiskhide.cpp +++ b/native/jni/magiskhide/magiskhide.cpp @@ -6,9 +6,11 @@ #include #include #include +#include #include #include +#include #include #include "magiskhide.h" @@ -28,6 +30,8 @@ bool hide_enabled = false; " add PKG [PROC] Add a new target to the hide list\n" " rm PKG [PROC] Remove target(s) from the hide list\n" " ls Print the current hide list\n" + " exec CMDs... Execute commands in isolated mount\n" + " namespace and do all hide unmounts\n" #ifdef MAGISK_DEBUG " test Run process monitor test\n" #endif @@ -99,6 +103,13 @@ int magiskhide_main(int argc, char *argv[]) { req = LS_HIDELIST; else if (opt == "status"sv) req = HIDE_STATUS; + else if (opt == "exec"sv && argc > 2) { + xunshare(CLONE_NEWNS); + xmount(nullptr, "/", nullptr, MS_PRIVATE | MS_REC, nullptr); + hide_unmount(); + execvp(argv[2], argv + 2); + exit(1); + } #ifdef MAGISK_DEBUG else if (opt == "test"sv) test_proc_monitor(); diff --git a/native/jni/magiskhide/magiskhide.h b/native/jni/magiskhide/magiskhide.h index 05d0f65ea..d271861d5 100644 --- a/native/jni/magiskhide/magiskhide.h +++ b/native/jni/magiskhide/magiskhide.h @@ -37,6 +37,7 @@ void crawl_procfs(DIR *dir, const std::function &fn); // Hide policies void hide_daemon(int pid); +void hide_unmount(int pid = getpid()); void hide_sensitive_props(); extern bool hide_enabled;