Fix liboat_hook.so inaccessible in some device (#190)

User has reported `dex2oat` failure with SELinux log:

```
W dex2oat64: type=1400 audit(0.0:922): avc: denied { read } for path="/data/adb/modules/zygisk_lsposed/bin/liboat_hook64.so" dev="dm-58" ino=91204 scontext=u:r:dex2oat:s0 tcontext=u:object_r:adb_data_file:s0 tclass=file permissive=0
```

Hence, we now set the SELinux context of `liboat_hook.so` in Dex2OatService.

Moreover, by the pull-request #194, we have to move `putenv` out of the if block by testing.
Indeed, if we call `putenv` inside the if block, then it is no longer valid out of the block.
This commit is contained in:
JingMatrix 2025-02-17 11:42:36 +01:00
parent f8236f607b
commit bfa38b0d53
2 changed files with 8 additions and 0 deletions

View File

@ -50,6 +50,8 @@ public class Dex2OatService implements Runnable {
private static final String TAG = "LSPosedDex2Oat"; private static final String TAG = "LSPosedDex2Oat";
private static final String WRAPPER32 = "bin/dex2oat32"; private static final String WRAPPER32 = "bin/dex2oat32";
private static final String WRAPPER64 = "bin/dex2oat64"; private static final String WRAPPER64 = "bin/dex2oat64";
private static final String HOOKER32 = "bin/liboat_hook32.so";
private static final String HOOKER64 = "bin/liboat_hook64.so";
private final String[] dex2oatArray = new String[6]; private final String[] dex2oatArray = new String[6];
private final FileDescriptor[] fdArray = new FileDescriptor[6]; private final FileDescriptor[] fdArray = new FileDescriptor[6];
@ -186,6 +188,8 @@ public class Dex2OatService implements Runnable {
SELinux.setFileContext(WRAPPER64, xposed_file); SELinux.setFileContext(WRAPPER64, xposed_file);
setSockCreateContext("u:r:installd:s0"); setSockCreateContext("u:r:installd:s0");
} }
SELinux.setFileContext(HOOKER32, xposed_file);
SELinux.setFileContext(HOOKER64, xposed_file);
try (var server = new LocalServerSocket(sockPath)) { try (var server = new LocalServerSocket(sockPath)) {
setSockCreateContext(null); setSockCreateContext(null);
while (true) { while (true) {

View File

@ -117,6 +117,9 @@ int main(int argc, char **argv) {
read_int(sock_fd); read_int(sock_fd);
close(sock_fd); close(sock_fd);
if (hooker_fd == -1) {
PLOGE("failed to read liboat_hook.so");
}
LOGD("sock: %s %d", sock.sun_path + 1, stock_fd); LOGD("sock: %s %d", sock.sun_path + 1, stock_fd);
const char *new_argv[argc + 2]; const char *new_argv[argc + 2];
@ -136,6 +139,7 @@ int main(int argc, char **argv) {
char env_str[STRING_BUFFER]; char env_str[STRING_BUFFER];
snprintf(env_str, STRING_BUFFER, "LD_PRELOAD=/proc/%d/fd/%d", getpid(), hooker_fd); snprintf(env_str, STRING_BUFFER, "LD_PRELOAD=/proc/%d/fd/%d", getpid(), hooker_fd);
putenv(env_str); putenv(env_str);
LOGD("Set env %s", env_str);
fexecve(stock_fd, (char **)new_argv, environ); fexecve(stock_fd, (char **)new_argv, environ);