From c7c9fb95765a6b578815987015ca1ec79862e71e Mon Sep 17 00:00:00 2001 From: vvb2060 Date: Fri, 22 Jul 2022 03:08:37 +0800 Subject: [PATCH] Restore context before copy fix magiskpolicy context --- native/jni/base/include/selinux.hpp | 1 + native/jni/core/bootstages.cpp | 2 ++ native/jni/core/restorecon.cpp | 3 +++ 3 files changed, 6 insertions(+) diff --git a/native/jni/base/include/selinux.hpp b/native/jni/base/include/selinux.hpp index ea4cf0f40..bc31ed213 100644 --- a/native/jni/base/include/selinux.hpp +++ b/native/jni/base/include/selinux.hpp @@ -40,3 +40,4 @@ bool selinux_enabled(); void enable_selinux(); void restorecon(); void restore_tmpcon(); +void restore_databincon(); diff --git a/native/jni/core/bootstages.cpp b/native/jni/core/bootstages.cpp index 20bc43969..bd32ca73a 100644 --- a/native/jni/core/bootstages.cpp +++ b/native/jni/core/bootstages.cpp @@ -152,6 +152,8 @@ static bool magisk_env() { xmkdir(SECURE_DIR "/post-fs-data.d", 0755); xmkdir(SECURE_DIR "/service.d", 0755); + restore_databincon(); + if (access(DATABIN "/busybox", X_OK)) return false; diff --git a/native/jni/core/restorecon.cpp b/native/jni/core/restorecon.cpp index 72dd90c79..bab2df857 100644 --- a/native/jni/core/restorecon.cpp +++ b/native/jni/core/restorecon.cpp @@ -74,6 +74,9 @@ void restorecon() { close(fd); lsetfilecon(MODULEROOT, SYSTEM_CON); restore_syscon(xopen(MODULEROOT, O_RDONLY | O_CLOEXEC)); +} + +void restore_databincon() { restore_magiskcon(xopen(DATABIN, O_RDONLY | O_CLOEXEC)); }