Revert to old SElinux rules on pre 8.0 devices

Fix #2910
This commit is contained in:
topjohnwu
2020-07-06 01:13:50 -07:00
parent 7922f65243
commit 97b72a5941
4 changed files with 96 additions and 70 deletions

View File

@@ -156,6 +156,8 @@ static void daemon_entry(int ppid) {
setsid();
setcon("u:r:" SEPOL_PROC_DOMAIN ":s0");
LOGI(NAME_WITH_VER(Magisk) " daemon started\n");
// Make sure ppid is not in acct
char src[64], dest[64];
sprintf(src, "/acct/uid_0/pid_%d", ppid);
@@ -167,20 +169,6 @@ static void daemon_entry(int ppid) {
MAGISKTMP = dirname(src);
xstat("/proc/self/exe", &self_st);
restore_tmpcon();
// SAR cleanups
auto mount_list = MAGISKTMP + "/" ROOTMNT;
if (access(mount_list.data(), F_OK) == 0) {
file_readline(true, mount_list.data(), [](string_view line) -> bool {
umount2(line.data(), MNT_DETACH);
return true;
});
}
unlink("/dev/.se");
LOGI(NAME_WITH_VER(Magisk) " daemon started\n");
// Get API level
parse_prop_file("/system/build.prop", [](auto key, auto val) -> bool {
if (key == "ro.build.version.sdk") {
@@ -198,6 +186,18 @@ static void daemon_entry(int ppid) {
}
LOGI("* Device API level: %d\n", SDK_INT);
restore_tmpcon();
// SAR cleanups
auto mount_list = MAGISKTMP + "/" ROOTMNT;
if (access(mount_list.data(), F_OK) == 0) {
file_readline(true, mount_list.data(), [](string_view line) -> bool {
umount2(line.data(), MNT_DETACH);
return true;
});
}
unlink("/dev/.se");
// Load config status
auto config = MAGISKTMP + "/" INTLROOT "/config";
parse_prop_file(config.data(), [](auto key, auto val) -> bool {

View File

@@ -1,6 +1,7 @@
#include <string_view>
#include <magisk.hpp>
#include <daemon.hpp>
#include <selinux.hpp>
#include <utils.hpp>
@@ -87,7 +88,7 @@ void restore_tmpcon() {
int dfd = dirfd(dir.get());
for (dirent *entry; (entry = xreaddir(dir.get()));) {
if (entry->d_name == "magisk"sv)
if (SDK_INT >= 26 && entry->d_name == "magisk"sv)
setfilecon_at(dfd, entry->d_name, EXEC_CON);
else
setfilecon_at(dfd, entry->d_name, SYSTEM_CON);