Last active
October 1, 2025 15:03
-
-
Save ayasa520/7fa952f3d3cc3391fc90792baaa2b119 to your computer and use it in GitHub Desktop.
A workaround to make NeoZygisk work on devices with SELinux disabled
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/zygiskd/src/utils.rs b/zygiskd/src/utils.rs | |
| index b5d9f82..4afd2af 100644 | |
| --- a/zygiskd/src/utils.rs | |
| +++ b/zygiskd/src/utils.rs | |
| @@ -172,12 +172,21 @@ pub fn unix_listener_from_path(path: &str) -> Result<UnixListener> { | |
| /// Sends a datagram packet to a Unix socket path. | |
| pub fn unix_datagram_sendto(path: &str, buf: &[u8]) -> Result<()> { | |
| - set_socket_create_context(&get_current_attr()?)?; | |
| + // Best-effort: ignore failures when SELinux is disabled or context is invalid | |
| + if let Ok(current) = get_current_attr() { | |
| + if let Err(e) = set_socket_create_context(¤t) { | |
| + log::debug!("sockcreate(set current) ignored: {}", e); | |
| + } | |
| + } else { | |
| + log::debug!("sockcreate(get current) ignored: failed to read current context"); | |
| + } | |
| let addr = SocketAddrUnix::new(path.as_bytes())?; | |
| let socket = socket(AddressFamily::UNIX, SocketType::DGRAM, None)?; | |
| connect(&socket, &addr)?; | |
| sendto(socket, buf, SendFlags::empty(), &addr)?; | |
| - set_socket_create_context("u:r:zygote:s0")?; | |
| + if let Err(e) = set_socket_create_context("u:r:zygote:s0") { | |
| + log::debug!("sockcreate(reset) ignored: {}", e); | |
| + } | |
| Ok(()) | |
| } | |
| diff --git a/zygiskd/src/zygiskd.rs b/zygiskd/src/zygiskd.rs | |
| index 4b279ff..de43a0f 100644 | |
| --- a/zygiskd/src/zygiskd.rs | |
| +++ b/zygiskd/src/zygiskd.rs | |
| @@ -194,8 +194,10 @@ fn send_startup_info(modules: &[Module]) -> Result<()> { | |
| msg.extend_from_slice(&(info.len() as u32 + 1).to_le_bytes()); | |
| msg.extend_from_slice(info.as_bytes()); | |
| msg.push(0); // Null terminator | |
| - utils::unix_datagram_sendto(CONTROLLER_SOCKET.get().unwrap(), &msg) | |
| - .context("Failed to send startup info to controller") | |
| + if let Err(e) = utils::unix_datagram_sendto(CONTROLLER_SOCKET.get().unwrap(), &msg) { | |
| + warn!("Failed to send startup info to controller: {}", e); | |
| + } | |
| + Ok(()) | |
| } | |
| /// Detects the device architecture. | |
| @@ -276,7 +278,10 @@ fn create_library_fd(so_path: &Path) -> Result<OwnedFd> { | |
| /// Creates and binds the main daemon Unix socket. | |
| fn create_daemon_socket() -> Result<UnixListener> { | |
| - utils::set_socket_create_context("u:r:zygote:s0")?; | |
| + // Best-effort: ignore failures when SELinux is disabled or context is invalid | |
| + if let Err(e) = utils::set_socket_create_context("u:r:zygote:s0") { | |
| + debug!("sockcreate(listener) ignored: {}", e); | |
| + } | |
| let listener = utils::unix_listener_from_path(DAEMON_SOCKET_PATH.get().unwrap())?; | |
| Ok(listener) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment