Skip to content

Commit bfa38b0

Browse files
committed
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.
1 parent f8236f6 commit bfa38b0

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

daemon/src/main/java/org/lsposed/lspd/service/Dex2OatService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public class Dex2OatService implements Runnable {
5050
private static final String TAG = "LSPosedDex2Oat";
5151
private static final String WRAPPER32 = "bin/dex2oat32";
5252
private static final String WRAPPER64 = "bin/dex2oat64";
53+
private static final String HOOKER32 = "bin/liboat_hook32.so";
54+
private static final String HOOKER64 = "bin/liboat_hook64.so";
5355

5456
private final String[] dex2oatArray = new String[6];
5557
private final FileDescriptor[] fdArray = new FileDescriptor[6];
@@ -186,6 +188,8 @@ public void run() {
186188
SELinux.setFileContext(WRAPPER64, xposed_file);
187189
setSockCreateContext("u:r:installd:s0");
188190
}
191+
SELinux.setFileContext(HOOKER32, xposed_file);
192+
SELinux.setFileContext(HOOKER64, xposed_file);
189193
try (var server = new LocalServerSocket(sockPath)) {
190194
setSockCreateContext(null);
191195
while (true) {

dex2oat/src/main/cpp/dex2oat.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ int main(int argc, char **argv) {
117117
read_int(sock_fd);
118118
close(sock_fd);
119119

120+
if (hooker_fd == -1) {
121+
PLOGE("failed to read liboat_hook.so");
122+
}
120123
LOGD("sock: %s %d", sock.sun_path + 1, stock_fd);
121124

122125
const char *new_argv[argc + 2];
@@ -136,6 +139,7 @@ int main(int argc, char **argv) {
136139
char env_str[STRING_BUFFER];
137140
snprintf(env_str, STRING_BUFFER, "LD_PRELOAD=/proc/%d/fd/%d", getpid(), hooker_fd);
138141
putenv(env_str);
142+
LOGD("Set env %s", env_str);
139143

140144
fexecve(stock_fd, (char **)new_argv, environ);
141145

0 commit comments

Comments
 (0)