mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-10 07:42:06 +00:00
Use LD_PRELOAD to intercept sepolicy on 2SI init
This commit is contained in:
23
native/jni/init/preload.c
Normal file
23
native/jni/init/preload.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
int security_load_policy(void *data, size_t len) {
|
||||
// Make sure our next exec won't get bugged
|
||||
unsetenv("LD_PRELOAD");
|
||||
unlink("/dev/preload.so");
|
||||
|
||||
int (*load_policy)(void *, size_t) = dlsym(RTLD_NEXT, "security_load_policy");
|
||||
// Skip checking errors, because if we cannot find the symbol, there
|
||||
// isn't much we can do other than crashing anyways.
|
||||
int result = load_policy(data, len);
|
||||
|
||||
// Wait for ack
|
||||
int fd = open("/sys/fs/selinux/enforce", O_RDONLY);
|
||||
char c;
|
||||
read(fd, &c, 1);
|
||||
close(fd);
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user