4 Commits

Author SHA1 Message Date
Nullptr
9d648d9aa4 Bump to 0.6.2 2023-03-03 18:20:50 +08:00
Nullptr
843086f6f3 Add more sepolicy 2023-03-03 18:20:50 +08:00
Nullptr
49e3ac9d7a Fix dependency bug: OnceCell crashes on 32 bit 2023-03-03 18:20:36 +08:00
Nullptr
446ed92f26 Change module dir and bump to 0.6.1 2023-03-01 12:42:12 +08:00
11 changed files with 39 additions and 37 deletions

6
.gitmodules vendored
View File

@@ -1,6 +1,6 @@
[submodule "loader/src/external/liblsplt"] [submodule "loader/src/external/lsplt"]
path = loader/src/external/liblsplt path = loader/src/external/lsplt
url = https://github.com/LSPosed/LSPlt url = https://github.com/LSPosed/lsplt
[submodule "loader/src/external/parallel-hashmap"] [submodule "loader/src/external/parallel-hashmap"]
path = loader/src/external/parallel-hashmap path = loader/src/external/parallel-hashmap
url = https://github.com/greg7mdp/parallel-hashmap url = https://github.com/greg7mdp/parallel-hashmap

View File

@@ -13,11 +13,8 @@ Also works as standalone loader for Magisk on purpose of getting rid of LD_PRELO
### KernelSU ### KernelSU
+ Minimal KernelSU version: 10654 + Minimal KernelSU version: 10654
+ Minimal ksud version: 10647 + Minimal ksud version: 10670
+ Kernel has full SELinux patch support + Kernel has full SELinux patch support
+ For old kernels, you may need to manually add the following code to `sepolicy.rule`:
`allow zygote appdomain_tmpfs file *`
`allow zygote appdomain_tmpfs dir *`
### Magisk ### Magisk

View File

@@ -31,10 +31,10 @@ val gitCommitHash = "git rev-parse --verify --short HEAD".execute()
val moduleId by extra("zygisksu") val moduleId by extra("zygisksu")
val moduleName by extra("Zygisk on KernelSU") val moduleName by extra("Zygisk on KernelSU")
val verName by extra("v4-0.6.0") val verName by extra("v4-0.6.2")
val verCode by extra(gitCommitCount) val verCode by extra(gitCommitCount)
val minKsuVersion by extra(10654) val minKsuVersion by extra(10654)
val minKsudVersion by extra(10647) val minKsudVersion by extra(10670)
val maxKsuVersion by extra(20000) val maxKsuVersion by extra(20000)
val minMagiskVersion by extra(25208) val minMagiskVersion by extra(25208)

View File

@@ -3,14 +3,14 @@ LOCAL_PATH := $(call my-dir)
# liblsplt.a # liblsplt.a
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE:= liblsplt LOCAL_MODULE:= liblsplt
LOCAL_C_INCLUDES := $(LOCAL_PATH)/liblsplt/lsplt/src/main/jni/include LOCAL_C_INCLUDES := $(LOCAL_PATH)/lsplt/lsplt/src/main/jni/include
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES) LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
LOCAL_CFLAGS := -Wall -Wextra -Werror -fvisibility=hidden LOCAL_CFLAGS := -Wall -Wextra -Werror -fvisibility=hidden -DLOG_DISABLED
LOCAL_CPPFLAGS := -std=c++20 LOCAL_CPPFLAGS := -std=c++20
LOCAL_STATIC_LIBRARIES := libcxx LOCAL_STATIC_LIBRARIES := libcxx
LOCAL_SRC_FILES := \ LOCAL_SRC_FILES := \
liblsplt/lsplt/src/main/jni/elf_util.cc \ lsplt/lsplt/src/main/jni/elf_util.cc \
liblsplt/lsplt/src/main/jni/lsplt.cc lsplt/lsplt/src/main/jni/lsplt.cc
include $(BUILD_STATIC_LIBRARY) include $(BUILD_STATIC_LIBRARY)
# Header only library # Header only library

View File

@@ -9,7 +9,7 @@
using namespace std::string_view_literals; using namespace std::string_view_literals;
namespace { namespace {
constexpr auto KSU_MODULE_DIR = "/data/adb/ksu/modules"; constexpr auto MODULE_DIR = "/data/adb/modules";
struct overlay_backup { struct overlay_backup {
std::string target; std::string target;
@@ -38,10 +38,10 @@ void revert_unmount_ksu() {
std::list<overlay_backup> backups; std::list<overlay_backup> backups;
// Unmount ksu module dir last // Unmount ksu module dir last
targets.emplace_back(KSU_MODULE_DIR); targets.emplace_back(MODULE_DIR);
for (auto& info: parse_mount_info("self")) { for (auto& info: parse_mount_info("self")) {
if (info.target == KSU_MODULE_DIR) { if (info.target == MODULE_DIR) {
ksu_loop = info.source; ksu_loop = info.source;
continue; continue;
} }
@@ -51,8 +51,7 @@ void revert_unmount_ksu() {
} }
// Unmount ksu overlays // Unmount ksu overlays
if (info.type == "overlay") { if (info.type == "overlay") {
LOGV("Overlay: %s (%s)", info.target.data(), info.fs_option.data()); if (str_contains(info.fs_option, MODULE_DIR)) {
if (str_contains(info.fs_option, KSU_MODULE_DIR)) {
targets.emplace_back(info.target); targets.emplace_back(info.target);
} else { } else {
auto backup = overlay_backup{ auto backup = overlay_backup{
@@ -66,7 +65,7 @@ void revert_unmount_ksu() {
} }
for (auto& info: parse_mount_info("self")) { for (auto& info: parse_mount_info("self")) {
// Unmount everything from ksu loop except ksu module dir // Unmount everything from ksu loop except ksu module dir
if (info.source == ksu_loop && info.target != KSU_MODULE_DIR) { if (info.source == ksu_loop && info.target != MODULE_DIR) {
targets.emplace_back(info.target); targets.emplace_back(info.target);
} }
} }

View File

@@ -82,6 +82,10 @@ extract "$ZIPFILE" 'sepolicy.rule' "$TMPDIR"
if [ "$KSU" ]; then if [ "$KSU" ]; then
ui_print "- Checking SELinux patches" ui_print "- Checking SELinux patches"
if [ "$(getprop ro.product.first_api_level)" -lt 31 ]; then
echo "allow zygote appdomain_tmpfs file *" >> "$TMPDIR/sepolicy.rule"
echo "allow zygote appdomain_tmpfs dir *" >> "$TMPDIR/sepolicy.rule"
fi
if ! check_sepolicy "$TMPDIR/sepolicy.rule"; then if ! check_sepolicy "$TMPDIR/sepolicy.rule"; then
ui_print "*********************************************************" ui_print "*********************************************************"
ui_print "! Unable to apply SELinux patches!" ui_print "! Unable to apply SELinux patches!"
@@ -93,8 +97,8 @@ fi
ui_print "- Extracting module files" ui_print "- Extracting module files"
extract "$ZIPFILE" 'module.prop' "$MODPATH" extract "$ZIPFILE" 'module.prop' "$MODPATH"
extract "$ZIPFILE" 'post-fs-data.sh' "$MODPATH" extract "$ZIPFILE" 'post-fs-data.sh' "$MODPATH"
extract "$ZIPFILE" 'sepolicy.rule' "$MODPATH"
extract "$ZIPFILE" 'service.sh' "$MODPATH" extract "$ZIPFILE" 'service.sh' "$MODPATH"
mv "$TMPDIR/sepolicy.rule" "$MODPATH"
HAS32BIT=false && [ -d "/system/lib" ] && HAS32BIT=true HAS32BIT=false && [ -d "/system/lib" ] && HAS32BIT=true
HAS64BIT=false && [ -d "/system/lib64" ] && HAS64BIT=true HAS64BIT=false && [ -d "/system/lib64" ] && HAS64BIT=true

View File

@@ -9,7 +9,7 @@ cd "$MODDIR"
getprop ro.dalvik.vm.native.bridge > /dev/.native_bridge getprop ro.dalvik.vm.native.bridge > /dev/.native_bridge
resetprop ro.dalvik.vm.native.bridge libzygisk_loader.so resetprop ro.dalvik.vm.native.bridge libzygisk_loader.so
if [ "$(which magisk)" ] && [ ".." -ef "/data/adb/modules" ]; then if [ "$(which magisk)" ]; then
for file in ../*; do for file in ../*; do
if [ -d "$file" ] && [ -d "$file/zygisk" ] && ! [ -f "$file/disable" ]; then if [ -d "$file" ] && [ -d "$file/zygisk" ] && ! [ -f "$file/disable" ]; then
if [ -f "$file/post-fs-data.sh" ]; then if [ -f "$file/post-fs-data.sh" ]; then

View File

@@ -10,6 +10,7 @@ allow * magisk_file lnk_file *
allow * magisk_file sock_file * allow * magisk_file sock_file *
allow system_server system_server process execmem allow system_server system_server process execmem
allow zygote adb_data_file dir search
allow zygote mnt_vendor_file dir search allow zygote mnt_vendor_file dir search
allow zygote system_file dir mounton allow zygote system_file dir mounton
allow zygote labeledfs filesystem mount allow zygote labeledfs filesystem mount

View File

@@ -11,7 +11,7 @@ cd "$MODDIR"
export NATIVE_BRIDGE=$(cat /dev/.native_bridge) export NATIVE_BRIDGE=$(cat /dev/.native_bridge)
rm /dev/.native_bridge rm /dev/.native_bridge
if [ "$(which magisk)" ] && [ ".." -ef "/data/adb/modules" ]; then if [ "$(which magisk)" ]; then
for file in ../*; do for file in ../*; do
if [ -d "$file" ] && [ -d "$file/zygisk" ] && ! [ -f "$file/disable" ]; then if [ -d "$file" ] && [ -d "$file/zygisk" ] && ! [ -f "$file/disable" ]; then
if [ -f "$file/service.sh" ]; then if [ -f "$file/service.sh" ]; then

View File

@@ -1,8 +1,6 @@
mod kernelsu; mod kernelsu;
mod magisk; mod magisk;
use once_cell::sync::OnceCell;
pub enum RootImpl { pub enum RootImpl {
None, None,
TooOld, TooOld,
@@ -12,47 +10,50 @@ pub enum RootImpl {
Magisk, Magisk,
} }
static ROOT_IMPL: OnceCell<RootImpl> = OnceCell::new(); // FIXME: OnceCell bugs on 32 bit
static mut ROOT_IMPL: RootImpl = RootImpl::None;
pub fn setup() { pub fn setup() {
let ksu_version = kernelsu::get_kernel_su(); let ksu_version = kernelsu::get_kernel_su();
let magisk_version = magisk::get_magisk(); let magisk_version = magisk::get_magisk();
let _ = match (ksu_version, magisk_version) { let impl_ = match (ksu_version, magisk_version) {
(None, None) => ROOT_IMPL.set(RootImpl::None), (None, None) => RootImpl::None,
(Some(_), Some(_)) => ROOT_IMPL.set(RootImpl::Multiple), (Some(_), Some(_)) => RootImpl::Multiple,
(Some(ksu_version), None) => { (Some(ksu_version), None) => {
let val = match ksu_version { match ksu_version {
kernelsu::Version::Supported => RootImpl::KernelSU, kernelsu::Version::Supported => RootImpl::KernelSU,
kernelsu::Version::TooOld => RootImpl::TooOld, kernelsu::Version::TooOld => RootImpl::TooOld,
kernelsu::Version::Abnormal => RootImpl::Abnormal, kernelsu::Version::Abnormal => RootImpl::Abnormal,
}; }
ROOT_IMPL.set(val)
} }
(None, Some(magisk_version)) => { (None, Some(magisk_version)) => {
let val = match magisk_version { match magisk_version {
magisk::Version::Supported => RootImpl::Magisk, magisk::Version::Supported => RootImpl::Magisk,
magisk::Version::TooOld => RootImpl::TooOld, magisk::Version::TooOld => RootImpl::TooOld,
}; }
ROOT_IMPL.set(val)
} }
}; };
unsafe { ROOT_IMPL = impl_; }
} }
pub fn get_impl() -> &'static RootImpl { pub fn get_impl() -> &'static RootImpl {
ROOT_IMPL.get().unwrap() unsafe { &ROOT_IMPL }
} }
// FIXME: Without #[inline(never)], this function will lag forever
#[inline(never)]
pub fn uid_on_allowlist(uid: i32) -> bool { pub fn uid_on_allowlist(uid: i32) -> bool {
match ROOT_IMPL.get().unwrap() { match get_impl() {
RootImpl::KernelSU => kernelsu::uid_on_allowlist(uid), RootImpl::KernelSU => kernelsu::uid_on_allowlist(uid),
RootImpl::Magisk => magisk::uid_on_allowlist(uid), RootImpl::Magisk => magisk::uid_on_allowlist(uid),
_ => unreachable!(), _ => unreachable!(),
} }
} }
#[inline(never)]
pub fn uid_on_denylist(uid: i32) -> bool { pub fn uid_on_denylist(uid: i32) -> bool {
match ROOT_IMPL.get().unwrap() { match get_impl() {
RootImpl::KernelSU => kernelsu::uid_on_denylist(uid), RootImpl::KernelSU => kernelsu::uid_on_denylist(uid),
RootImpl::Magisk => magisk::uid_on_denylist(uid), RootImpl::Magisk => magisk::uid_on_denylist(uid),
_ => unreachable!(), _ => unreachable!(),