2019-05-26 02:47:57 -07:00
|
|
|
#include <sys/mount.h>
|
|
|
|
|
2020-03-09 01:50:30 -07:00
|
|
|
#include <magisk.hpp>
|
|
|
|
#include <utils.hpp>
|
|
|
|
#include <selinux.hpp>
|
|
|
|
#include <resetprop.hpp>
|
2019-05-26 02:47:57 -07:00
|
|
|
|
2021-09-12 12:40:34 -07:00
|
|
|
#include "deny.hpp"
|
2019-05-26 02:47:57 -07:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2020-05-17 15:01:20 -07:00
|
|
|
static void lazy_unmount(const char* mountpoint) {
|
2020-12-30 22:11:24 -08:00
|
|
|
if (umount2(mountpoint, MNT_DETACH) != -1)
|
2021-09-12 12:40:34 -07:00
|
|
|
LOGD("denylist: Unmounted (%s)\n", mountpoint);
|
2019-05-26 02:47:57 -07:00
|
|
|
}
|
|
|
|
|
2021-09-12 12:40:34 -07:00
|
|
|
void revert_daemon(int pid, int client) {
|
2020-12-30 22:11:24 -08:00
|
|
|
if (fork_dont_care() == 0) {
|
2021-09-12 12:40:34 -07:00
|
|
|
revert_unmount(pid);
|
2021-08-19 04:55:17 -07:00
|
|
|
write_int(client, 0);
|
2020-12-30 22:11:24 -08:00
|
|
|
_exit(0);
|
|
|
|
}
|
2019-06-04 22:27:19 -07:00
|
|
|
}
|
2019-05-26 02:47:57 -07:00
|
|
|
|
2021-08-18 02:01:54 -07:00
|
|
|
#define TMPFS_MNT(dir) (mentry->mnt_type == "tmpfs"sv && str_starts(mentry->mnt_dir, "/" #dir))
|
2019-06-23 03:53:41 -07:00
|
|
|
|
2021-09-12 12:40:34 -07:00
|
|
|
void revert_unmount(int pid) {
|
2021-08-26 03:09:56 -07:00
|
|
|
if (pid > 0) {
|
|
|
|
if (switch_mnt_ns(pid))
|
|
|
|
return;
|
2021-09-12 12:40:34 -07:00
|
|
|
LOGD("denylist: handling PID=[%d]\n", pid);
|
2021-08-26 03:09:56 -07:00
|
|
|
}
|
2020-12-30 22:11:24 -08:00
|
|
|
|
|
|
|
vector<string> targets;
|
|
|
|
|
2021-08-26 03:09:56 -07:00
|
|
|
// Unmount dummy skeletons and MAGISKTMP
|
2020-12-30 22:11:24 -08:00
|
|
|
targets.push_back(MAGISKTMP);
|
|
|
|
parse_mnt("/proc/self/mounts", [&](mntent *mentry) {
|
|
|
|
if (TMPFS_MNT(system) || TMPFS_MNT(vendor) || TMPFS_MNT(product) || TMPFS_MNT(system_ext))
|
|
|
|
targets.emplace_back(mentry->mnt_dir);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
for (auto &s : reversed(targets))
|
|
|
|
lazy_unmount(s.data());
|
|
|
|
targets.clear();
|
|
|
|
|
|
|
|
// Unmount all Magisk created mounts
|
|
|
|
parse_mnt("/proc/self/mounts", [&](mntent *mentry) {
|
2021-08-18 02:01:54 -07:00
|
|
|
if (str_contains(mentry->mnt_fsname, BLOCKDIR))
|
2020-12-30 22:11:24 -08:00
|
|
|
targets.emplace_back(mentry->mnt_dir);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
for (auto &s : reversed(targets))
|
|
|
|
lazy_unmount(s.data());
|
2019-05-26 02:47:57 -07:00
|
|
|
}
|