Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
1860e5d1
Commit
1860e5d1
authored
Jan 14, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dynamically find libselinux.so path
parent
f2cb3c38
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
23 deletions
+23
-23
rootdir.cpp
native/jni/init/rootdir.cpp
+20
-18
twostage.cpp
native/jni/init/twostage.cpp
+3
-5
No files found.
native/jni/init/rootdir.cpp
View file @
1860e5d1
...
...
@@ -9,12 +9,6 @@
#include "init.hpp"
#include "magiskrc.inc"
#ifdef USE_64BIT
#define LIBNAME "lib64"
#else
#define LIBNAME "lib"
#endif
using
namespace
std
;
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 MONOPOLICY "/sepolicy"
#define LIBSELINUX "/system/" LIBNAME "/libselinux.so"
#define NEW_INITRC "/system/etc/init/hw/init.rc"
void
SARBase
::
patch_rootdir
()
{
...
...
@@ -231,15 +224,25 @@ void SARBase::patch_rootdir() {
close
(
dest
);
}
if
(
patch_count
!=
2
&&
access
(
LIBSELINUX
,
F_OK
)
==
0
)
{
if
(
patch_count
!=
2
)
{
// init is dynamically linked, need to patch libselinux
auto
lib
=
mmap_data
::
ro
(
LIBSELINUX
);
const
char
*
path
=
"/system/lib64/libselinux.so"
;
if
(
access
(
path
,
F_OK
)
!=
0
)
{
path
=
"/system/lib/libselinux.so"
;
if
(
access
(
path
,
F_OK
)
!=
0
)
path
=
nullptr
;
}
if
(
path
)
{
char
ovl
[
128
];
sprintf
(
ovl
,
ROOTOVL
"%s"
,
path
);
auto
lib
=
mmap_data
::
ro
(
path
);
lib
.
patch
({
make_pair
(
MONOPOLICY
,
sepol
)});
xmkdirs
(
dirname
(
ROOTOVL
LIBSELINUX
),
0755
);
int
dest
=
xopen
(
ROOTOVL
LIBSELINUX
,
O_CREAT
|
O_WRONLY
|
O_CLOEXEC
,
0
);
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
(
LIBSELINUX
,
ROOTOVL
LIBSELINUX
);
clone_attr
(
path
,
ovl
);
}
}
// sepolicy
...
...
@@ -251,10 +254,9 @@ void SARBase::patch_rootdir() {
if
(
connect
(
sockfd
,
(
struct
sockaddr
*
)
&
sun
,
setup_sockaddr
(
&
sun
,
INIT_SOCKET
))
==
0
)
{
LOGD
(
"ACK init daemon to write backup files
\n
"
);
// 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
int
ack
;
read
(
sockfd
,
&
ack
,
sizeof
(
ack
));
read_int
(
sockfd
);
}
else
{
LOGD
(
"Restore backup files locally
\n
"
);
restore_folder
(
ROOTOVL
,
overlays
);
...
...
native/jni/init/twostage.cpp
View file @
1860e5d1
...
...
@@ -142,8 +142,6 @@ void FirstStageInit::prepare() {
#define REDIR_PATH "/system/bin/am"
void
SARInit
::
first_stage_prep
()
{
int
pid
=
getpid
();
xmount
(
"tmpfs"
,
"/dev"
,
"tmpfs"
,
0
,
"mode=755"
);
// Patch init binary
...
...
@@ -174,7 +172,7 @@ void SARInit::first_stage_prep() {
sigaddset
(
&
block
,
SIGUSR1
);
sigprocmask
(
SIG_BLOCK
,
&
block
,
&
old
);
if
(
int
child
=
xfork
()
;
child
)
{
if
(
int
child
=
xfork
())
{
LOGD
(
"init daemon [%d]
\n
"
,
child
);
// Wait for children signal
int
sig
;
...
...
@@ -190,7 +188,7 @@ void SARInit::first_stage_prep() {
xlisten
(
sockfd
,
1
);
// Resume parent
kill
(
pid
,
SIGUSR1
);
kill
(
getppid
()
,
SIGUSR1
);
// Wait for second stage ack
int
client
=
xaccept4
(
sockfd
,
nullptr
,
nullptr
,
SOCK_CLOEXEC
);
...
...
@@ -204,7 +202,7 @@ void SARInit::first_stage_prep() {
restore_folder
(
ROOTOVL
,
overlays
);
// Ack and bail out!
write
(
sockfd
,
&
sockfd
,
sizeof
(
sockfd
)
);
write
_int
(
sockfd
,
0
);
close
(
client
);
close
(
sockfd
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment