Add sepolicy.rule patching tests

This commit is contained in:
topjohnwu
2025-05-12 17:31:50 -07:00
committed by John Wu
parent 97901979dd
commit 4f4b1ff885
6 changed files with 31 additions and 21 deletions
+3 -2
View File
@@ -5,7 +5,7 @@ use crate::ffi::{
exec_module_scripts, get_magisk_tmp, initialize_denylist, setup_magisk_env,
};
use crate::logging::{magisk_logging, setup_logfile, start_log_daemon};
use crate::mount::{clean_mounts, setup_mounts};
use crate::mount::{clean_mounts, setup_module_mount, setup_preinit_dir};
use crate::package::ManagerInfo;
use crate::selinux::restore_tmpcon;
use crate::su::SuInfo;
@@ -144,7 +144,7 @@ impl MagiskD {
Ordering::Release,
);
initialize_denylist();
setup_mounts();
setup_module_mount();
let modules = self.handle_modules();
self.module_list.set(modules).ok();
clean_mounts();
@@ -175,6 +175,7 @@ impl MagiskD {
secure_dir.mkdir(0o700).log_ok();
}
setup_preinit_dir();
self.ensure_manager();
self.zygisk_reset(true)
}
+8 -13
View File
@@ -15,16 +15,13 @@ use crate::consts::{MODULEMNT, MODULEROOT, PREINITDEV, PREINITMIRR, WORKERDIR};
use crate::ffi::{get_magisk_tmp, resolve_preinit_dir, switch_mnt_ns};
use crate::get_prop;
pub fn setup_mounts() {
info!("* Setup internal mounts");
pub fn setup_preinit_dir() {
let magisk_tmp = get_magisk_tmp();
// Mount preinit directory
let dev_path = cstr::buf::new::<64>()
.join_path(magisk_tmp)
.join_path(PREINITDEV);
let mut linked = false;
if let Ok(attr) = dev_path.get_attr() {
if attr.st.st_mode & libc::S_IFMT as c_uint == libc::S_IFBLK.as_() {
// DO NOT mount the block device directly, as we do not know the flags and configs
@@ -53,23 +50,21 @@ pub fn setup_mounts() {
mnt_path.create_symlink_to(preinit_dir)?;
};
if r.is_ok() {
linked = true;
break;
info!("* Found preinit dir: {}", preinit_dir);
return;
}
}
}
}
}
if !linked {
warn!("mount: preinit dir not found");
dev_path.remove().ok();
} else {
debug!("mount: preinit dir found");
}
warn!("mount: preinit dir not found");
}
pub fn setup_module_mount() {
// Bind remount module root to clear nosuid
let module_mnt = cstr::buf::default()
.join_path(magisk_tmp)
.join_path(get_magisk_tmp())
.join_path(MODULEMNT);
let _: LoggedResult<()> = try {
module_mnt.mkdir(0o755)?;