mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-02-20 07:58:30 +00:00
Dynamically find libselinux.so path
This commit is contained in:
parent
f2cb3c38fe
commit
1860e5d133
@ -9,12 +9,6 @@
|
|||||||
#include "init.hpp"
|
#include "init.hpp"
|
||||||
#include "magiskrc.inc"
|
#include "magiskrc.inc"
|
||||||
|
|
||||||
#ifdef USE_64BIT
|
|
||||||
#define LIBNAME "lib64"
|
|
||||||
#else
|
|
||||||
#define LIBNAME "lib"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static vector<string> rc_list;
|
static vector<string> rc_list;
|
||||||
@ -182,7 +176,6 @@ static void magic_mount(const string &sdir, const string &ddir = "") {
|
|||||||
|
|
||||||
#define ROOTMIR MIRRDIR "/system_root"
|
#define ROOTMIR MIRRDIR "/system_root"
|
||||||
#define MONOPOLICY "/sepolicy"
|
#define MONOPOLICY "/sepolicy"
|
||||||
#define LIBSELINUX "/system/" LIBNAME "/libselinux.so"
|
|
||||||
#define NEW_INITRC "/system/etc/init/hw/init.rc"
|
#define NEW_INITRC "/system/etc/init/hw/init.rc"
|
||||||
|
|
||||||
void SARBase::patch_rootdir() {
|
void SARBase::patch_rootdir() {
|
||||||
@ -231,15 +224,25 @@ void SARBase::patch_rootdir() {
|
|||||||
close(dest);
|
close(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (patch_count != 2 && access(LIBSELINUX, F_OK) == 0) {
|
if (patch_count != 2) {
|
||||||
// init is dynamically linked, need to patch libselinux
|
// init is dynamically linked, need to patch libselinux
|
||||||
auto lib = mmap_data::ro(LIBSELINUX);
|
const char *path = "/system/lib64/libselinux.so";
|
||||||
lib.patch({make_pair(MONOPOLICY, sepol)});
|
if (access(path, F_OK) != 0) {
|
||||||
xmkdirs(dirname(ROOTOVL LIBSELINUX), 0755);
|
path = "/system/lib/libselinux.so";
|
||||||
int dest = xopen(ROOTOVL LIBSELINUX, O_CREAT | O_WRONLY | O_CLOEXEC, 0);
|
if (access(path, F_OK) != 0)
|
||||||
xwrite(dest, lib.buf, lib.sz);
|
path = nullptr;
|
||||||
close(dest);
|
}
|
||||||
clone_attr(LIBSELINUX, ROOTOVL LIBSELINUX);
|
if (path) {
|
||||||
|
char ovl[128];
|
||||||
|
sprintf(ovl, ROOTOVL "%s", path);
|
||||||
|
auto lib = mmap_data::ro(path);
|
||||||
|
lib.patch({make_pair(MONOPOLICY, sepol)});
|
||||||
|
xmkdirs(dirname(ovl), 0755);
|
||||||
|
int dest = xopen(ovl, O_CREAT | O_WRONLY | O_CLOEXEC, 0);
|
||||||
|
xwrite(dest, lib.buf, lib.sz);
|
||||||
|
close(dest);
|
||||||
|
clone_attr(path, ovl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sepolicy
|
// sepolicy
|
||||||
@ -251,10 +254,9 @@ void SARBase::patch_rootdir() {
|
|||||||
if (connect(sockfd, (struct sockaddr*) &sun, setup_sockaddr(&sun, INIT_SOCKET)) == 0) {
|
if (connect(sockfd, (struct sockaddr*) &sun, setup_sockaddr(&sun, INIT_SOCKET)) == 0) {
|
||||||
LOGD("ACK init daemon to write backup files\n");
|
LOGD("ACK init daemon to write backup files\n");
|
||||||
// Let daemon know where tmp_dir is
|
// Let daemon know where tmp_dir is
|
||||||
write_string(sockfd, tmp_dir.data());
|
write_string(sockfd, tmp_dir);
|
||||||
// Wait for daemon to finish restoring files
|
// Wait for daemon to finish restoring files
|
||||||
int ack;
|
read_int(sockfd);
|
||||||
read(sockfd, &ack, sizeof(ack));
|
|
||||||
} else {
|
} else {
|
||||||
LOGD("Restore backup files locally\n");
|
LOGD("Restore backup files locally\n");
|
||||||
restore_folder(ROOTOVL, overlays);
|
restore_folder(ROOTOVL, overlays);
|
||||||
|
@ -142,8 +142,6 @@ void FirstStageInit::prepare() {
|
|||||||
#define REDIR_PATH "/system/bin/am"
|
#define REDIR_PATH "/system/bin/am"
|
||||||
|
|
||||||
void SARInit::first_stage_prep() {
|
void SARInit::first_stage_prep() {
|
||||||
int pid = getpid();
|
|
||||||
|
|
||||||
xmount("tmpfs", "/dev", "tmpfs", 0, "mode=755");
|
xmount("tmpfs", "/dev", "tmpfs", 0, "mode=755");
|
||||||
|
|
||||||
// Patch init binary
|
// Patch init binary
|
||||||
@ -174,7 +172,7 @@ void SARInit::first_stage_prep() {
|
|||||||
sigaddset(&block, SIGUSR1);
|
sigaddset(&block, SIGUSR1);
|
||||||
sigprocmask(SIG_BLOCK, &block, &old);
|
sigprocmask(SIG_BLOCK, &block, &old);
|
||||||
|
|
||||||
if (int child = xfork(); child) {
|
if (int child = xfork()) {
|
||||||
LOGD("init daemon [%d]\n", child);
|
LOGD("init daemon [%d]\n", child);
|
||||||
// Wait for children signal
|
// Wait for children signal
|
||||||
int sig;
|
int sig;
|
||||||
@ -190,7 +188,7 @@ void SARInit::first_stage_prep() {
|
|||||||
xlisten(sockfd, 1);
|
xlisten(sockfd, 1);
|
||||||
|
|
||||||
// Resume parent
|
// Resume parent
|
||||||
kill(pid, SIGUSR1);
|
kill(getppid(), SIGUSR1);
|
||||||
|
|
||||||
// Wait for second stage ack
|
// Wait for second stage ack
|
||||||
int client = xaccept4(sockfd, nullptr, nullptr, SOCK_CLOEXEC);
|
int client = xaccept4(sockfd, nullptr, nullptr, SOCK_CLOEXEC);
|
||||||
@ -204,7 +202,7 @@ void SARInit::first_stage_prep() {
|
|||||||
restore_folder(ROOTOVL, overlays);
|
restore_folder(ROOTOVL, overlays);
|
||||||
|
|
||||||
// Ack and bail out!
|
// Ack and bail out!
|
||||||
write(sockfd, &sockfd, sizeof(sockfd));
|
write_int(sockfd, 0);
|
||||||
close(client);
|
close(client);
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user