refine mount prop

This commit is contained in:
5ec1cff
2024-01-02 23:33:15 +08:00
parent 977bd7753d
commit cbd0f0f0c3
7 changed files with 34 additions and 7 deletions

View File

@@ -125,4 +125,15 @@ namespace zygiskd {
PLOGE("Failed to request ZygoteRestart"); PLOGE("Failed to request ZygoteRestart");
} }
} }
void SystemServerStarted() {
UniqueFd fd = Connect(1);
if (fd == -1) {
PLOGE("Failed to report system server started");
} else {
if (!socket_utils::write_u8(fd, (uint8_t) SocketAction::SystemServerStarted)) {
PLOGE("Failed to report system server started");
}
}
}
} }

View File

@@ -60,6 +60,7 @@ namespace zygiskd {
RequestCompanionSocket, RequestCompanionSocket,
GetModuleDir, GetModuleDir,
ZygoteRestart, ZygoteRestart,
SystemServerStarted,
}; };
void Init(const char *path = TMP_PATH); void Init(const char *path = TMP_PATH);
@@ -77,4 +78,6 @@ namespace zygiskd {
int GetModuleDir(size_t index); int GetModuleDir(size_t index);
void ZygoteRestart(); void ZygoteRestart();
void SystemServerStarted();
} }

View File

@@ -634,6 +634,7 @@ void ZygiskContext::nativeForkSystemServer_pre() {
return; return;
run_modules_pre(); run_modules_pre();
zygiskd::SystemServerStarted();
sanitize_fds(); sanitize_fds();
} }

View File

@@ -15,6 +15,7 @@ enum Command {
DAEMON32_SET_INFO = 7, DAEMON32_SET_INFO = 7,
DAEMON64_SET_ERROR_INFO = 8, DAEMON64_SET_ERROR_INFO = 8,
DAEMON32_SET_ERROR_INFO = 9, DAEMON32_SET_ERROR_INFO = 9,
SYSTEM_SERVER_STARTED = 10
}; };
void send_control_command(Command cmd); void send_control_command(Command cmd);

View File

@@ -108,6 +108,7 @@ public:
}; };
static TracingState tracing_state = TRACING; static TracingState tracing_state = TRACING;
static std::string prop_path;
struct Status { struct Status {
@@ -170,7 +171,7 @@ struct SocketHandler : public EventHandler {
LOGE("read %zu < %zu", nread, sizeof(Command)); LOGE("read %zu < %zu", nread, sizeof(Command));
continue; continue;
} }
if (msg.cmd >= Command::DAEMON64_SET_INFO) { if (msg.cmd >= Command::DAEMON64_SET_INFO && msg.cmd != Command::SYSTEM_SERVER_STARTED) {
if (nread != sizeof(msg)) { if (nread != sizeof(msg)) {
LOGE("cmd %d size %zu != %zu", msg.cmd, nread, sizeof(MsgHead)); LOGE("cmd %d size %zu != %zu", msg.cmd, nread, sizeof(MsgHead));
continue; continue;
@@ -253,6 +254,12 @@ struct SocketHandler : public EventHandler {
status32.daemon_error_info = std::string(msg.data); status32.daemon_error_info = std::string(msg.data);
updateStatus(); updateStatus();
break; break;
case SYSTEM_SERVER_STARTED:
LOGD("system server started, mounting prop");
if (mount(prop_path.c_str(), "/data/adb/modules/zygisksu/module.prop", nullptr, MS_BIND, nullptr) == -1) {
PLOGE("failed to mount prop");
}
break;
} }
} }
} }
@@ -282,9 +289,12 @@ bool should_stop_inject##abi() { \
CREATE_ZYGOTE_START_COUNTER(64) CREATE_ZYGOTE_START_COUNTER(64)
CREATE_ZYGOTE_START_COUNTER(32) CREATE_ZYGOTE_START_COUNTER(32)
static bool ensure_daemon_created(bool is_64bit) { static bool ensure_daemon_created(bool is_64bit) {
auto &status = is_64bit ? status64 : status32; auto &status = is_64bit ? status64 : status32;
if (is_64bit) {
LOGD("new zygote started, unmounting prop ...");
umount2(prop_path.c_str(), MNT_DETACH);
}
status.zygote_injected = false; status.zygote_injected = false;
if (status.daemon_pid == -1) { if (status.daemon_pid == -1) {
auto pid = fork(); auto pid = fork();
@@ -480,7 +490,6 @@ public:
} }
}; };
static std::string prop_path;
static std::string pre_section; static std::string pre_section;
static std::string post_section; static std::string post_section;
@@ -568,10 +577,6 @@ static bool prepare_environment() {
PLOGE("chdir %s", wd); PLOGE("chdir %s", wd);
return false; return false;
} }
if (mount(prop_path.c_str(), "/data/adb/modules/zygisksu/module.prop", nullptr, MS_BIND, nullptr) == -1) {
PLOGE("failed to mount prop");
return false;
}
if (!switch_mnt_ns(0, &old_ns)) return false; if (!switch_mnt_ns(0, &old_ns)) return false;
if (chdir(wd) == -1) { if (chdir(wd) == -1) {
PLOGE("chdir %s", wd); PLOGE("chdir %s", wd);

View File

@@ -23,6 +23,7 @@ pub const PATH_MODULE_PROP: &str = "module.prop";
pub const ZYGOTE_INJECTED: i32 = lp_select!(5, 4); pub const ZYGOTE_INJECTED: i32 = lp_select!(5, 4);
pub const DAEMON_SET_INFO: i32 = lp_select!(7, 6); pub const DAEMON_SET_INFO: i32 = lp_select!(7, 6);
pub const DAEMON_SET_ERROR_INFO: i32 = lp_select!(9, 8); pub const DAEMON_SET_ERROR_INFO: i32 = lp_select!(9, 8);
pub const SYSTEM_SERVER_STARTED: i32 = 10;
pub const TMP_DIR: &str = "/debug_ramdisk/zygisksu"; pub const TMP_DIR: &str = "/debug_ramdisk/zygisksu";
pub const CONTROLLER_SOCKET: &str = concatcp!(TMP_DIR, "/init_monitor"); pub const CONTROLLER_SOCKET: &str = concatcp!(TMP_DIR, "/init_monitor");
pub const PATH_CP_NAME: &str = concatcp!(TMP_DIR, lp_select!("/cp32.sock", "/cp64.sock")); pub const PATH_CP_NAME: &str = concatcp!(TMP_DIR, lp_select!("/cp32.sock", "/cp64.sock"));
@@ -39,6 +40,7 @@ pub enum DaemonSocketAction {
RequestCompanionSocket, RequestCompanionSocket,
GetModuleDir, GetModuleDir,
ZygoteRestart, ZygoteRestart,
SystemServerStarted,
} }
// Zygisk process flags // Zygisk process flags

View File

@@ -80,6 +80,10 @@ pub fn main() -> Result<()> {
companion.take(); companion.take();
} }
} }
DaemonSocketAction::SystemServerStarted => {
let value = constants::SYSTEM_SERVER_STARTED;
utils::unix_datagram_sendto(constants::CONTROLLER_SOCKET, &value.to_le_bytes())?;
}
_ => { _ => {
thread::spawn(move || { thread::spawn(move || {
if let Err(e) = handle_daemon_action(action, stream, &context) { if let Err(e) = handle_daemon_action(action, stream, &context) {