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
660e0dc0
Commit
660e0dc0
authored
Feb 19, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix MagiskHide unmount daemon
Close #1101
parent
3ebc886f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
19 deletions
+42
-19
proc_monitor.cpp
native/jni/magiskhide/proc_monitor.cpp
+25
-14
utils.h
native/jni/utils/include/utils.h
+17
-5
No files found.
native/jni/magiskhide/proc_monitor.cpp
View file @
660e0dc0
...
...
@@ -95,41 +95,52 @@ static bool is_snet(const int pid) {
}
static
void
hide_daemon
(
int
pid
)
{
char
buffer
[
4096
];
RunFinally
fin
([
=
]()
->
void
{
// Send resume signal
kill
(
pid
,
SIGCONT
);
_exit
(
0
);
});
if
(
switch_mnt_ns
(
pid
))
goto
exit
;
return
;
LOGD
(
"hide_daemon: handling PID=[%d]
\n
"
,
pid
);
manage_selinux
();
clean_magisk_props
();
snprintf
(
buffer
,
sizeof
(
buffer
),
"/proc/%d"
,
pid
);
chdir
(
buffer
)
;
vector
<
string
>
targets
;
// Unmount dummy skeletons and /sbin links
file_readline
(
"mounts"
,
[
&
](
string_view
&
s
)
->
bool
{
file_readline
(
"
/proc/self/
mounts"
,
[
&
](
string_view
&
s
)
->
bool
{
if
(
str_contains
(
s
,
"tmpfs /system/"
)
||
str_contains
(
s
,
"tmpfs /vendor/"
)
||
str_contains
(
s
,
"tmpfs /sbin"
))
{
sscanf
(
s
.
data
(),
"%*s %4096s"
,
buffer
);
lazy_unmount
(
buffer
);
char
*
path
=
(
char
*
)
s
.
data
();
// Skip first token
strtok_r
(
nullptr
,
" "
,
&
path
);
targets
.
emplace_back
(
strtok_r
(
nullptr
,
" "
,
&
path
));
}
return
true
;
});
for
(
auto
&
s
:
targets
)
lazy_unmount
(
s
.
data
());
targets
.
clear
();
// Unmount everything under /system, /vendor, and data mounts
file_readline
(
"mounts"
,
[
&
](
string_view
&
s
)
->
bool
{
file_readline
(
"
/proc/self/
mounts"
,
[
&
](
string_view
&
s
)
->
bool
{
if
((
str_contains
(
s
,
" /system/"
)
||
str_contains
(
s
,
" /vendor/"
))
&&
(
str_contains
(
s
,
system_block
)
||
str_contains
(
s
,
vendor_block
)
||
str_contains
(
s
,
data_block
)))
{
sscanf
(
s
.
data
(),
"%*s %4096s"
,
buffer
);
lazy_unmount
(
buffer
);
char
*
path
=
(
char
*
)
s
.
data
();
// Skip first token
strtok_r
(
nullptr
,
" "
,
&
path
);
targets
.
emplace_back
(
strtok_r
(
nullptr
,
" "
,
&
path
));
}
return
true
;
});
exit:
// Send resume signal
kill
(
pid
,
SIGCONT
);
_exit
(
0
);
for
(
auto
&
s
:
targets
)
lazy_unmount
(
s
.
data
());
}
// A mapping from pid to namespace inode to avoid time-consuming GC
...
...
native/jni/utils/include/utils.h
View file @
660e0dc0
...
...
@@ -146,11 +146,7 @@ void write_zero(int fd, size_t size);
#define str_contains(s, ss) ((ss) != nullptr && (s).find(ss) != std::string::npos)
#define str_starts(s, ss) ((ss) != nullptr && (s).compare(0, strlen(ss), ss) == 0)
// file.cpp
void
file_readline
(
const
char
*
filename
,
const
std
::
function
<
bool
(
std
::
string_view
&
)
>
&
fn
,
bool
trim
=
false
);
// misc.cpp
// RAII
class
MutexGuard
{
public
:
...
...
@@ -170,6 +166,22 @@ private:
pthread_mutex_t
*
mutex
;
};
class
RunFinally
{
public
:
explicit
RunFinally
(
std
::
function
<
void
()
>
&&
fn
)
:
fn
(
std
::
move
(
fn
))
{}
~
RunFinally
()
{
fn
();
}
private
:
const
std
::
function
<
void
()
>
fn
;
};
// file.cpp
void
file_readline
(
const
char
*
filename
,
const
std
::
function
<
bool
(
std
::
string_view
&
)
>
&
fn
,
bool
trim
=
false
);
// misc.cpp
int
new_daemon_thread
(
void
*
(
*
start_routine
)
(
void
*
),
void
*
arg
=
nullptr
,
const
pthread_attr_t
*
attr
=
nullptr
);
...
...
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