mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
Bump minSdk to 24 and drop API 23 workarounds
- Bump minSdk to 24 in Setup.kt, APP_PLATFORM to android-24 in Application.mk, and update CI AVD matrices and scripts. - Unify SePatchStrategy::Legacy with SePatchStrategy::SelinuxFs in magiskinit to use MOCK_ENFORCE FIFO blocking and remove MOCK_REQPROT. - Make APP_DATA_DIR a compile-time "/data/user_de" constant and remove pre-API 24 /data/user and /data/adb fallbacks. - Remove Android 6.0 Samsung forkAndSpecialize JNI hook signature. - Remove pre-API 24 device-protected storage wrappers, Api23Impl in LocaleSetting, AndroidManifest.xml stub resource workaround, and ServiceCompat/ProcessCompat/InlinedApi workarounds in the app. Assisted-by: Gemini 4 Argon
This commit is contained in:
@@ -2,7 +2,7 @@ APP_BUILD_SCRIPT := src/Android.mk
|
||||
APP_CFLAGS := -Wall -Oz -fomit-frame-pointer -D_FILE_OFFSET_BITS=64
|
||||
APP_CPPFLAGS := -std=c++23
|
||||
APP_STL := none
|
||||
APP_PLATFORM := android-23
|
||||
APP_PLATFORM := android-24
|
||||
APP_THIN_ARCHIVE := true
|
||||
APP_STRIP_MODE := none
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::consts::{APP_PACKAGE_NAME, BBPATH, DATABIN, MODULEROOT, SECURE_DIR};
|
||||
use crate::consts::{APP_DATA_DIR, APP_PACKAGE_NAME, BBPATH, DATABIN, MODULEROOT, SECURE_DIR};
|
||||
use crate::daemon::MagiskD;
|
||||
use crate::db::MultiuserMode;
|
||||
use crate::ffi::{
|
||||
@@ -36,7 +36,7 @@ impl MagiskD {
|
||||
let mut buf = cstr::buf::default();
|
||||
|
||||
for user in self.get_users() {
|
||||
buf.append_path(self.app_data_dir())
|
||||
buf.append_path(APP_DATA_DIR)
|
||||
.append_path_fmt(user)
|
||||
.append_path(APP_PACKAGE_NAME)
|
||||
.append_path("install");
|
||||
@@ -118,14 +118,9 @@ impl MagiskD {
|
||||
self.preserve_stub_apk();
|
||||
|
||||
// Check secure dir
|
||||
let secure_dir = cstr!(SECURE_DIR);
|
||||
if !secure_dir.exists() {
|
||||
if self.sdk_int < 24 {
|
||||
secure_dir.mkdir(0o700).log_ok();
|
||||
} else {
|
||||
error!("* {} is not present, abort", SECURE_DIR);
|
||||
return true;
|
||||
}
|
||||
if !cstr!(SECURE_DIR).exists() {
|
||||
error!("* {} is not present, abort", SECURE_DIR);
|
||||
return true;
|
||||
}
|
||||
|
||||
self.prune_su_access();
|
||||
|
||||
@@ -78,14 +78,6 @@ impl MagiskD {
|
||||
self.sdk_int
|
||||
}
|
||||
|
||||
pub fn app_data_dir(&self) -> &'static Utf8CStr {
|
||||
if self.sdk_int >= 24 {
|
||||
cstr!("/data/user_de")
|
||||
} else {
|
||||
cstr!("/data/user")
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_request_sync(&self, mut client: UnixStream, code: RequestCode) {
|
||||
match code {
|
||||
RequestCode::CHECK_VERSION => {
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#define to_user_id(uid) (uid / AID_USER_OFFSET)
|
||||
|
||||
#define SDK_INT (MagiskD::Get().sdk_int())
|
||||
#define APP_DATA_DIR (SDK_INT >= 24 ? "/data/user_de" : "/data/user")
|
||||
|
||||
inline int connect_daemon(RequestCode req) {
|
||||
return connect_daemon(req, false);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::consts::{APP_PACKAGE_NAME, MAGISK_VER_CODE};
|
||||
use crate::consts::{APP_DATA_DIR, APP_PACKAGE_NAME, MAGISK_VER_CODE};
|
||||
use crate::daemon::{AID_APP_END, AID_APP_START, AID_USER_OFFSET, MagiskD, to_app_id};
|
||||
use crate::ffi::{DbEntryKey, get_magisk_tmp, install_apk, uninstall_pkg};
|
||||
use base::WalkResult::{Abort, Continue, Skip};
|
||||
@@ -227,9 +227,9 @@ impl TrackedFile {
|
||||
}
|
||||
|
||||
impl ManagerInfo {
|
||||
fn check_dyn(&mut self, daemon: &MagiskD, user: i32, pkg: &str) -> Status {
|
||||
fn check_dyn(&mut self, user: i32, pkg: &str) -> Status {
|
||||
let apk = cstr::buf::default()
|
||||
.join_path(daemon.app_data_dir())
|
||||
.join_path(APP_DATA_DIR)
|
||||
.join_path_fmt(user)
|
||||
.join_path(pkg)
|
||||
.join_path("dyn")
|
||||
@@ -349,7 +349,7 @@ impl ManagerInfo {
|
||||
return (-1, "");
|
||||
}
|
||||
// dyn APK is still the same
|
||||
if file.path.starts_with(daemon.app_data_dir().as_str()) {
|
||||
if file.path.starts_with(APP_DATA_DIR) {
|
||||
return (
|
||||
user * AID_USER_OFFSET + self.repackaged_app_id,
|
||||
&self.repackaged_pkg,
|
||||
@@ -358,7 +358,7 @@ impl ManagerInfo {
|
||||
// stub APK is still the same
|
||||
if !self.repackaged_pkg.is_empty() {
|
||||
return if matches!(
|
||||
self.check_dyn(daemon, user, self.repackaged_pkg.clone().as_str()),
|
||||
self.check_dyn(user, self.repackaged_pkg.clone().as_str()),
|
||||
Status::Installed
|
||||
) {
|
||||
(
|
||||
@@ -381,7 +381,7 @@ impl ManagerInfo {
|
||||
if !db_pkg.is_empty() {
|
||||
match self.check_stub(user, &db_pkg) {
|
||||
Status::Installed => {
|
||||
return if matches!(self.check_dyn(daemon, user, &db_pkg), Status::Installed) {
|
||||
return if matches!(self.check_dyn(user, &db_pkg), Status::Installed) {
|
||||
(
|
||||
user * AID_USER_OFFSET + self.repackaged_app_id,
|
||||
&self.repackaged_pkg,
|
||||
@@ -430,7 +430,7 @@ impl ManagerInfo {
|
||||
impl MagiskD {
|
||||
fn get_package_uid(&self, user: i32, pkg: &str) -> i32 {
|
||||
let path = cstr::buf::default()
|
||||
.join_path(self.app_data_dir())
|
||||
.join_path(APP_DATA_DIR)
|
||||
.join_path_fmt(user)
|
||||
.join_path(pkg);
|
||||
path.get_attr()
|
||||
@@ -483,7 +483,7 @@ impl MagiskD {
|
||||
pub fn get_app_no_list(&self) -> BitSet {
|
||||
let mut list = BitSet::new();
|
||||
let _ = || -> LoggedResult<()> {
|
||||
let mut app_data_dir = Directory::open(self.app_data_dir())?;
|
||||
let mut app_data_dir = Directory::open(cstr!(APP_DATA_DIR))?;
|
||||
// For each user
|
||||
loop {
|
||||
let entry = match app_data_dir.read()? {
|
||||
@@ -512,7 +512,7 @@ impl MagiskD {
|
||||
pub fn get_users(&self) -> Vec<i32> {
|
||||
let mut users = Vec::new();
|
||||
let _ = || -> LoggedResult<()> {
|
||||
let mut app_data_dir = Directory::open(self.app_data_dir())?;
|
||||
let mut app_data_dir = Directory::open(cstr!(APP_DATA_DIR))?;
|
||||
while let Some(e) = app_data_dir.read()? {
|
||||
if e.is_dir()
|
||||
&& let Ok(user) = e.name().parse::<i32>()
|
||||
|
||||
@@ -370,25 +370,6 @@ fas_c = ForkApp(
|
||||
],
|
||||
)
|
||||
|
||||
fas_samsung_m = ForkApp(
|
||||
"samsung_m",
|
||||
[
|
||||
uid,
|
||||
gid,
|
||||
gids,
|
||||
runtime_flags,
|
||||
rlimits,
|
||||
mount_external,
|
||||
se_info,
|
||||
Anon(jint),
|
||||
Anon(jint),
|
||||
nice_name,
|
||||
fds_to_close,
|
||||
instruction_set,
|
||||
app_data_dir,
|
||||
],
|
||||
)
|
||||
|
||||
fas_samsung_n = ForkApp(
|
||||
"samsung_n",
|
||||
[
|
||||
@@ -718,7 +699,6 @@ with open("jni_hooks.hpp", "w") as f:
|
||||
fas_samsung_p,
|
||||
fas_samsung_o,
|
||||
fas_samsung_n,
|
||||
fas_samsung_m,
|
||||
],
|
||||
)
|
||||
)
|
||||
|
||||
@@ -6,7 +6,7 @@ static JniHookDefinitions *get_defs();
|
||||
|
||||
struct JniHookDefinitions {
|
||||
|
||||
std::array<JNINativeMethod, 13> fork_app_methods = {{
|
||||
std::array<JNINativeMethod, 12> fork_app_methods = {{
|
||||
// nativeForkAndSpecialize_c
|
||||
{
|
||||
"nativeForkAndSpecialize",
|
||||
@@ -177,7 +177,7 @@ std::array<JNINativeMethod, 13> fork_app_methods = {{
|
||||
"nativeForkAndSpecialize",
|
||||
// IIILILILLLLZLLZZLLZZZL
|
||||
"(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/String;ZZ[Ljava/lang/String;[Ljava/lang/String;ZZZLjava/lang/String;)I",
|
||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jboolean use_fifo_ui, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jstring _9) static -> jint {
|
||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jboolean use_fifo_ui, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jstring _7) static -> jint {
|
||||
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
||||
args.fds_to_ignore = &fds_to_ignore;
|
||||
args.is_child_zygote = &is_child_zygote;
|
||||
@@ -189,8 +189,8 @@ std::array<JNINativeMethod, 13> fork_app_methods = {{
|
||||
args.mount_sysprop_overrides = &mount_sysprop_overrides;
|
||||
ZygiskContext ctx(env, &args);
|
||||
ctx.nativeForkAndSpecialize_pre();
|
||||
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jboolean use_fifo_ui, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jstring _9)>(get_defs()->fork_app_methods[8].fnPtr)(
|
||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, fds_to_close, fds_to_ignore, is_child_zygote, instruction_set, app_data_dir, is_top_app, use_fifo_ui, pkg_data_info_list, whitelisted_data_info_list, mount_data_dirs, mount_storage_dirs, mount_sysprop_overrides, _9
|
||||
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jboolean use_fifo_ui, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jstring _7)>(get_defs()->fork_app_methods[8].fnPtr)(
|
||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, fds_to_close, fds_to_ignore, is_child_zygote, instruction_set, app_data_dir, is_top_app, use_fifo_ui, pkg_data_info_list, whitelisted_data_info_list, mount_data_dirs, mount_storage_dirs, mount_sysprop_overrides, _7
|
||||
);
|
||||
ctx.nativeForkAndSpecialize_post();
|
||||
return ctx.pid;
|
||||
@@ -201,14 +201,14 @@ std::array<JNINativeMethod, 13> fork_app_methods = {{
|
||||
"nativeForkAndSpecialize",
|
||||
// IIILILILIILLLZLL
|
||||
"(II[II[[IILjava/lang/String;IILjava/lang/String;[I[IZLjava/lang/String;Ljava/lang/String;)I",
|
||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _7, jint _8, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir) static -> jint {
|
||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _5, jint _6, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir) static -> jint {
|
||||
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
||||
args.fds_to_ignore = &fds_to_ignore;
|
||||
args.is_child_zygote = &is_child_zygote;
|
||||
ZygiskContext ctx(env, &args);
|
||||
ctx.nativeForkAndSpecialize_pre();
|
||||
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _7, jint _8, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir)>(get_defs()->fork_app_methods[9].fnPtr)(
|
||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, _7, _8, nice_name, fds_to_close, fds_to_ignore, is_child_zygote, instruction_set, app_data_dir
|
||||
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _5, jint _6, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir)>(get_defs()->fork_app_methods[9].fnPtr)(
|
||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, _5, _6, nice_name, fds_to_close, fds_to_ignore, is_child_zygote, instruction_set, app_data_dir
|
||||
);
|
||||
ctx.nativeForkAndSpecialize_post();
|
||||
return ctx.pid;
|
||||
@@ -219,13 +219,13 @@ std::array<JNINativeMethod, 13> fork_app_methods = {{
|
||||
"nativeForkAndSpecialize",
|
||||
// IIILILILIILLLLL
|
||||
"(II[II[[IILjava/lang/String;IILjava/lang/String;[I[ILjava/lang/String;Ljava/lang/String;)I",
|
||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _5, jint _6, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jstring instruction_set, jstring app_data_dir) static -> jint {
|
||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _3, jint _4, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jstring instruction_set, jstring app_data_dir) static -> jint {
|
||||
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
||||
args.fds_to_ignore = &fds_to_ignore;
|
||||
ZygiskContext ctx(env, &args);
|
||||
ctx.nativeForkAndSpecialize_pre();
|
||||
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _5, jint _6, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jstring instruction_set, jstring app_data_dir)>(get_defs()->fork_app_methods[10].fnPtr)(
|
||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, _5, _6, nice_name, fds_to_close, fds_to_ignore, instruction_set, app_data_dir
|
||||
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _3, jint _4, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jstring instruction_set, jstring app_data_dir)>(get_defs()->fork_app_methods[10].fnPtr)(
|
||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, _3, _4, nice_name, fds_to_close, fds_to_ignore, instruction_set, app_data_dir
|
||||
);
|
||||
ctx.nativeForkAndSpecialize_post();
|
||||
return ctx.pid;
|
||||
@@ -236,28 +236,12 @@ std::array<JNINativeMethod, 13> fork_app_methods = {{
|
||||
"nativeForkAndSpecialize",
|
||||
// IIILILILIILLLLI
|
||||
"(II[II[[IILjava/lang/String;IILjava/lang/String;[ILjava/lang/String;Ljava/lang/String;I)I",
|
||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _2, jint _3, jstring nice_name, jintArray fds_to_close, jstring instruction_set, jstring app_data_dir, jint _4) static -> jint {
|
||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _0, jint _1, jstring nice_name, jintArray fds_to_close, jstring instruction_set, jstring app_data_dir, jint _2) static -> jint {
|
||||
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
||||
ZygiskContext ctx(env, &args);
|
||||
ctx.nativeForkAndSpecialize_pre();
|
||||
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _2, jint _3, jstring nice_name, jintArray fds_to_close, jstring instruction_set, jstring app_data_dir, jint _4)>(get_defs()->fork_app_methods[11].fnPtr)(
|
||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, _2, _3, nice_name, fds_to_close, instruction_set, app_data_dir, _4
|
||||
);
|
||||
ctx.nativeForkAndSpecialize_post();
|
||||
return ctx.pid;
|
||||
}
|
||||
},
|
||||
// nativeForkAndSpecialize_samsung_m
|
||||
{
|
||||
"nativeForkAndSpecialize",
|
||||
// IIILILILIILLLL
|
||||
"(II[II[[IILjava/lang/String;IILjava/lang/String;[ILjava/lang/String;Ljava/lang/String;)I",
|
||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _0, jint _1, jstring nice_name, jintArray fds_to_close, jstring instruction_set, jstring app_data_dir) static -> jint {
|
||||
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
||||
ZygiskContext ctx(env, &args);
|
||||
ctx.nativeForkAndSpecialize_pre();
|
||||
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _0, jint _1, jstring nice_name, jintArray fds_to_close, jstring instruction_set, jstring app_data_dir)>(get_defs()->fork_app_methods[12].fnPtr)(
|
||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, _0, _1, nice_name, fds_to_close, instruction_set, app_data_dir
|
||||
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _0, jint _1, jstring nice_name, jintArray fds_to_close, jstring instruction_set, jstring app_data_dir, jint _2)>(get_defs()->fork_app_methods[11].fnPtr)(
|
||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, _0, _1, nice_name, fds_to_close, instruction_set, app_data_dir, _2
|
||||
);
|
||||
ctx.nativeForkAndSpecialize_post();
|
||||
return ctx.pid;
|
||||
@@ -352,7 +336,7 @@ std::array<JNINativeMethod, 8> specialize_app_methods = {{
|
||||
"nativeSpecializeAppProcess",
|
||||
// VIILILILLZLLZLLZZZL
|
||||
"(II[II[[IILjava/lang/String;Ljava/lang/String;ZLjava/lang/String;Ljava/lang/String;Z[Ljava/lang/String;[Ljava/lang/String;ZZZLjava/lang/String;)V",
|
||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jstring _12) static -> void {
|
||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jstring _10) static -> void {
|
||||
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
||||
args.is_child_zygote = &is_child_zygote;
|
||||
args.is_top_app = &is_top_app;
|
||||
@@ -363,8 +347,8 @@ std::array<JNINativeMethod, 8> specialize_app_methods = {{
|
||||
args.mount_sysprop_overrides = &mount_sysprop_overrides;
|
||||
ZygiskContext ctx(env, &args);
|
||||
ctx.nativeSpecializeAppProcess_pre();
|
||||
reinterpret_cast<void(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jstring _12)>(get_defs()->specialize_app_methods[4].fnPtr)(
|
||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, is_child_zygote, instruction_set, app_data_dir, is_top_app, pkg_data_info_list, whitelisted_data_info_list, mount_data_dirs, mount_storage_dirs, mount_sysprop_overrides, _12
|
||||
reinterpret_cast<void(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jstring _10)>(get_defs()->specialize_app_methods[4].fnPtr)(
|
||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, is_child_zygote, instruction_set, app_data_dir, is_top_app, pkg_data_info_list, whitelisted_data_info_list, mount_data_dirs, mount_storage_dirs, mount_sysprop_overrides, _10
|
||||
);
|
||||
ctx.nativeSpecializeAppProcess_post();
|
||||
}
|
||||
@@ -395,13 +379,13 @@ std::array<JNINativeMethod, 8> specialize_app_methods = {{
|
||||
"nativeSpecializeAppProcess",
|
||||
// VIILILILIILZLL
|
||||
"(II[II[[IILjava/lang/String;IILjava/lang/String;ZLjava/lang/String;Ljava/lang/String;)V",
|
||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _10, jint _11, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir) static -> void {
|
||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _8, jint _9, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir) static -> void {
|
||||
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
||||
args.is_child_zygote = &is_child_zygote;
|
||||
ZygiskContext ctx(env, &args);
|
||||
ctx.nativeSpecializeAppProcess_pre();
|
||||
reinterpret_cast<void(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _10, jint _11, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir)>(get_defs()->specialize_app_methods[6].fnPtr)(
|
||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, _10, _11, nice_name, is_child_zygote, instruction_set, app_data_dir
|
||||
reinterpret_cast<void(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _8, jint _9, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir)>(get_defs()->specialize_app_methods[6].fnPtr)(
|
||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, _8, _9, nice_name, is_child_zygote, instruction_set, app_data_dir
|
||||
);
|
||||
ctx.nativeSpecializeAppProcess_post();
|
||||
}
|
||||
@@ -447,12 +431,12 @@ std::array<JNINativeMethod, 2> fork_server_methods = {{
|
||||
"nativeForkSystemServer",
|
||||
// IIILIIILJJ
|
||||
"(II[IIII[[IJJ)I",
|
||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jint _13, jint _14, jobjectArray rlimits, jlong permitted_capabilities, jlong effective_capabilities) static -> jint {
|
||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jint _11, jint _12, jobjectArray rlimits, jlong permitted_capabilities, jlong effective_capabilities) static -> jint {
|
||||
ServerSpecializeArgs_v1 args(uid, gid, gids, runtime_flags, permitted_capabilities, effective_capabilities);
|
||||
ZygiskContext ctx(env, &args);
|
||||
ctx.nativeForkSystemServer_pre();
|
||||
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jint _13, jint _14, jobjectArray rlimits, jlong permitted_capabilities, jlong effective_capabilities)>(get_defs()->fork_server_methods[1].fnPtr)(
|
||||
env, clazz, uid, gid, gids, runtime_flags, _13, _14, rlimits, permitted_capabilities, effective_capabilities
|
||||
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jint _11, jint _12, jobjectArray rlimits, jlong permitted_capabilities, jlong effective_capabilities)>(get_defs()->fork_server_methods[1].fnPtr)(
|
||||
env, clazz, uid, gid, gids, runtime_flags, _11, _12, rlimits, permitted_capabilities, effective_capabilities
|
||||
);
|
||||
ctx.nativeForkSystemServer_post();
|
||||
return ctx.pid;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#define JAVA_PACKAGE_NAME "com.topjohnwu.magisk"
|
||||
#define APP_DATA_DIR "/data/user_de"
|
||||
#define SECURE_DIR "/data/adb"
|
||||
#define MODULEROOT SECURE_DIR "/modules"
|
||||
#define DATABIN SECURE_DIR "/magisk"
|
||||
|
||||
@@ -16,6 +16,7 @@ pub const APP_PACKAGE_NAME: &str = "com.topjohnwu.magisk";
|
||||
pub const LOGFILE: &str = "/cache/magisk.log";
|
||||
|
||||
// data paths
|
||||
pub const APP_DATA_DIR: &str = "/data/user_de";
|
||||
pub const SECURE_DIR: &str = "/data/adb";
|
||||
pub const MODULEROOT: &str = concatcp!(SECURE_DIR, "/modules");
|
||||
pub const MODULEUPGRADE: &str = concatcp!(SECURE_DIR, "/modules_update");
|
||||
|
||||
@@ -15,12 +15,10 @@ use std::time::Duration;
|
||||
const MOCK_VERSION: &Utf8CStr = cstr!(concatcp!(SELINUXMOCK, "/version"));
|
||||
const MOCK_LOAD: &Utf8CStr = cstr!(concatcp!(SELINUXMOCK, "/load"));
|
||||
const MOCK_ENFORCE: &Utf8CStr = cstr!(concatcp!(SELINUXMOCK, "/enforce"));
|
||||
const MOCK_REQPROT: &Utf8CStr = cstr!(concatcp!(SELINUXMOCK, "/checkreqprot"));
|
||||
|
||||
const SELINUX_MNT: &str = "/sys/fs/selinux";
|
||||
const SELINUX_ENFORCE: &Utf8CStr = cstr!(concatcp!(SELINUX_MNT, "/enforce"));
|
||||
const SELINUX_LOAD: &Utf8CStr = cstr!(concatcp!(SELINUX_MNT, "/load"));
|
||||
const SELINUX_REQPROT: &Utf8CStr = cstr!(concatcp!(SELINUX_MNT, "/checkreqprot"));
|
||||
|
||||
enum SePatchStrategy {
|
||||
// 2SI, Android 10+
|
||||
@@ -32,7 +30,7 @@ enum SePatchStrategy {
|
||||
// selinuxfs is mounted in init.cpp. Errors when mounting selinuxfs is ignored,
|
||||
// which means that we can directly mount selinuxfs ourselves and hijack nodes in it.
|
||||
SelinuxFs,
|
||||
// Dynamic patching, Android 6.0 - 7.1
|
||||
// Dynamic patching, Android 7.0 - 7.1
|
||||
// selinuxfs is mounted in libselinux's selinux_android_load_policy(). Errors when
|
||||
// mounting selinuxfs is fatal, which means we need to block init's control flow after
|
||||
// it mounted selinuxfs for us, then we can hijack nodes in it.
|
||||
@@ -43,9 +41,9 @@ enum SePatchStrategy {
|
||||
//
|
||||
// We need to make sure the actual init process is blocked until sepolicy is loaded,
|
||||
// or else restorecon will fail and re-exec won't change context, causing boot failure.
|
||||
// We (ab)use the fact that init either reads the enforce node, or writes the checkreqprot
|
||||
// node, and because both has been replaced with FIFO files, init will block until we
|
||||
// handle it, effectively hijacking its control flow until the patched sepolicy is loaded.
|
||||
// We (ab)use the fact that init reads the enforce node, and because it has been replaced
|
||||
// with our FIFO file, init will block until we write something into the pipe, effectively
|
||||
// hijacking its control flow until the patched sepolicy is loaded.
|
||||
|
||||
fn mock_fifo(target: &Utf8CStr, mock: &Utf8CStr) -> LoggedResult<()> {
|
||||
debug!("Hijack [{}]", target);
|
||||
@@ -69,7 +67,6 @@ impl MagiskInit {
|
||||
cstr!("/init").unmount().ok();
|
||||
SELINUX_LOAD.unmount().log_ok();
|
||||
SELINUX_ENFORCE.unmount().ok();
|
||||
SELINUX_REQPROT.unmount().ok();
|
||||
|
||||
let mut sepol = SePolicy::from_file(MOCK_LOAD);
|
||||
sepol.magisk_rules();
|
||||
@@ -186,25 +183,16 @@ impl MagiskInit {
|
||||
|
||||
// Step 2: wait for selinuxfs to be mounted (only for LEGACY)
|
||||
|
||||
let wait = Duration::from_millis(100);
|
||||
|
||||
if matches!(strat, SePatchStrategy::Legacy) {
|
||||
let wait = Duration::from_millis(100);
|
||||
// Busy wait until selinuxfs is mounted
|
||||
while !SELINUX_ENFORCE.exists() {
|
||||
// Retry every 100ms
|
||||
sleep(wait);
|
||||
}
|
||||
|
||||
// On Android 6.0, init does not call security_getenforce() first; instead it directly
|
||||
// call security_setenforce() after security_load_policy(). What's even worse, it opens
|
||||
// the enforce node with O_RDWR, which will not block when opening FIFO files.
|
||||
// As a workaround, we do not mock the enforce node, and block init with mocking
|
||||
// checkreqprot instead.
|
||||
// Android 7.0 - 7.1 doesn't have this issue, but for simplicity, let's just use the
|
||||
// same blocking strategy for both since it also works just fine.
|
||||
|
||||
mock_file(SELINUX_LOAD, MOCK_LOAD)?;
|
||||
mock_fifo(SELINUX_REQPROT, MOCK_REQPROT)?;
|
||||
mock_fifo(SELINUX_ENFORCE, MOCK_ENFORCE)?;
|
||||
|
||||
// This will unblock init at selinux_android_load_policy() -> set_policy_index().
|
||||
drop(MOCK_VERSION.open(OFlag::O_WRONLY)?);
|
||||
@@ -241,7 +229,7 @@ impl MagiskInit {
|
||||
// Write ack to restore preload.so's control flow
|
||||
ack_fd.write_all("0".as_bytes())?;
|
||||
}
|
||||
SePatchStrategy::SelinuxFs => {
|
||||
SePatchStrategy::SelinuxFs | SePatchStrategy::Legacy => {
|
||||
// This open will block until init calls security_getenforce().
|
||||
let mut mock_enforce = MOCK_ENFORCE.open(OFlag::O_WRONLY)?;
|
||||
|
||||
@@ -254,29 +242,6 @@ impl MagiskInit {
|
||||
.read_to_end(&mut data)?;
|
||||
mock_enforce.write_all(&data)?;
|
||||
}
|
||||
SePatchStrategy::Legacy => {
|
||||
let mut sz = 0_usize;
|
||||
// Busy wait until sepolicy is fully written.
|
||||
loop {
|
||||
let attr = MOCK_LOAD.get_attr()?;
|
||||
if sz != 0 && sz == attr.st.st_size as usize {
|
||||
break;
|
||||
}
|
||||
sz = attr.st.st_size as usize;
|
||||
// Check every 100ms
|
||||
sleep(wait);
|
||||
}
|
||||
|
||||
self.cleanup_and_load(&rules);
|
||||
|
||||
// init is blocked on checkreqprot, write to the real node first, then
|
||||
// unblock init by opening the mock FIFO.
|
||||
SELINUX_REQPROT
|
||||
.open(OFlag::O_WRONLY)?
|
||||
.write_all("0".as_bytes())?;
|
||||
let mut v = vec![];
|
||||
MOCK_REQPROT.open(OFlag::O_RDONLY)?.read_to_end(&mut v)?;
|
||||
}
|
||||
}
|
||||
|
||||
// At this point, the init process will be unblocked
|
||||
|
||||
Reference in New Issue
Block a user