From d19fcd5e21421724e03f2280c0c52cbac11e1eb2 Mon Sep 17 00:00:00 2001 From: vvb2060 Date: Sun, 29 May 2022 14:28:56 +0800 Subject: [PATCH] Check path when start daemon --- native/jni/core/daemon.cpp | 8 ++++++++ native/jni/core/restorecon.cpp | 7 ------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/native/jni/core/daemon.cpp b/native/jni/core/daemon.cpp index 384791bde..433977627 100644 --- a/native/jni/core/daemon.cpp +++ b/native/jni/core/daemon.cpp @@ -416,6 +416,14 @@ int connect_daemon(int req, bool create) { return -1; } + char buf[64]; + xreadlink("/proc/self/exe", buf, sizeof(buf)); + if (str_starts(buf, "/system/bin/")) { + LOGE("Start daemon on /dev or /sbin\n"); + close(fd); + return -1; + } + if (fork_dont_care() == 0) { close(fd); daemon_entry(); diff --git a/native/jni/core/restorecon.cpp b/native/jni/core/restorecon.cpp index e2750cad8..a6495d32c 100644 --- a/native/jni/core/restorecon.cpp +++ b/native/jni/core/restorecon.cpp @@ -76,13 +76,6 @@ void restorecon() { } void restore_tmpcon() { - if (MAGISKTMP == "/system/bin") { - // Running with emulator.sh - if (SDK_INT >= 26) - lsetfilecon("/system/bin/magisk", EXEC_CON); - return; - } - if (MAGISKTMP == "/sbin") setfilecon(MAGISKTMP.data(), ROOT_CON); else