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
be5f00aa
Commit
be5f00aa
authored
Nov 08, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent stack overflow when managing hide list
parent
59ba350f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
38 deletions
+40
-38
hide_utils.cpp
native/jni/magiskhide/hide_utils.cpp
+40
-38
No files found.
native/jni/magiskhide/hide_utils.cpp
View file @
be5f00aa
...
@@ -27,8 +27,10 @@ static const char *prop_value[] =
...
@@ -27,8 +27,10 @@ static const char *prop_value[] =
"enforcing"
,
"0"
,
"0"
,
"0"
,
"enforcing"
,
"0"
,
"0"
,
"0"
,
"1"
,
"user"
,
"release-keys"
,
"0"
,
nullptr
};
"1"
,
"user"
,
"release-keys"
,
"0"
,
nullptr
};
static
const
char
*
proc_name
;
struct
ps_arg
{
static
gid_t
proc_gid
;
const
char
*
name
;
uid_t
uid
;
};
void
manage_selinux
()
{
void
manage_selinux
()
{
char
val
;
char
val
;
...
@@ -53,8 +55,7 @@ void hide_sensitive_props() {
...
@@ -53,8 +55,7 @@ void hide_sensitive_props() {
}
}
}
}
/* Call func for each process */
static
void
ps
(
void
(
*
cb
)(
int
,
void
*
),
void
*
arg
)
{
static
void
ps
(
void
(
*
func
)(
int
))
{
DIR
*
dir
;
DIR
*
dir
;
struct
dirent
*
entry
;
struct
dirent
*
entry
;
...
@@ -62,69 +63,70 @@ static void ps(void (*func)(int)) {
...
@@ -62,69 +63,70 @@ static void ps(void (*func)(int)) {
return
;
return
;
while
((
entry
=
xreaddir
(
dir
)))
{
while
((
entry
=
xreaddir
(
dir
)))
{
if
(
entry
->
d_type
==
DT_DIR
)
{
if
(
entry
->
d_type
==
DT_DIR
&&
is_num
(
entry
->
d_name
))
if
(
is_num
(
entry
->
d_name
))
cb
(
atoi
(
entry
->
d_name
),
arg
);
func
(
atoi
(
entry
->
d_name
));
}
}
}
closedir
(
dir
);
closedir
(
dir
);
}
}
static
int
check_proc_name
(
int
pid
,
const
char
*
name
)
{
static
bool
check_proc_name
(
int
pid
,
const
char
*
name
)
{
char
buf
[
128
];
char
buf
[
4019
];
FILE
*
f
;
FILE
*
f
;
sprintf
(
buf
,
"/proc/%d/comm"
,
pid
);
sprintf
(
buf
,
"/proc/%d/comm"
,
pid
);
if
((
f
=
fopen
(
buf
,
"r"
)))
{
if
((
f
=
fopen
(
buf
,
"r"
)))
{
fgets
(
buf
,
sizeof
(
buf
),
f
);
fgets
(
buf
,
sizeof
(
buf
),
f
);
if
(
strcmp
(
buf
,
name
)
==
0
)
if
(
strcmp
(
buf
,
name
)
==
0
)
return
1
;
return
true
;
}
else
{
}
else
{
// The PID is already killed
// The PID is already killed
return
0
;
return
false
;
}
}
fclose
(
f
);
fclose
(
f
);
sprintf
(
buf
,
"/proc/%d/cmdline"
,
pid
);
sprintf
(
buf
,
"/proc/%d/cmdline"
,
pid
);
f
=
fopen
(
buf
,
"r"
);
if
((
f
=
fopen
(
buf
,
"r"
)))
{
fgets
(
buf
,
sizeof
(
buf
),
f
);
fgets
(
buf
,
sizeof
(
buf
),
f
);
if
(
strcmp
(
basename
(
buf
),
name
)
==
0
)
return
true
;
}
else
{
// The PID is already killed
return
false
;
}
fclose
(
f
);
fclose
(
f
);
if
(
strcmp
(
basename
(
buf
),
name
)
==
0
)
return
1
;
sprintf
(
buf
,
"/proc/%d/exe"
,
pid
);
sprintf
(
buf
,
"/proc/%d/exe"
,
pid
);
if
(
access
(
buf
,
F_OK
)
!=
0
)
if
(
access
(
buf
,
F_OK
)
!=
0
)
return
0
;
return
false
;
xreadlink
(
buf
,
buf
,
sizeof
(
buf
));
xreadlink
(
buf
,
buf
,
sizeof
(
buf
));
if
(
strcmp
(
basename
(
buf
),
name
)
==
0
)
return
strcmp
(
basename
(
buf
),
name
)
==
0
;
return
1
;
return
0
;
}
}
static
void
kill_proc_cb
(
int
pid
)
{
static
void
kill_proc_cb
(
int
pid
,
void
*
v
)
{
if
(
check_proc_name
(
pid
,
proc_name
))
ps_arg
*
args
=
static_cast
<
ps_arg
*>
(
v
);
if
(
check_proc_name
(
pid
,
args
->
name
))
kill
(
pid
,
SIGTERM
);
kill
(
pid
,
SIGTERM
);
else
if
(
proc_g
id
>
0
)
{
else
if
(
args
->
u
id
>
0
)
{
char
buf
[
128
];
char
buf
[
64
];
struct
stat
st
;
struct
stat
st
;
sprintf
(
buf
,
"/proc/%d"
,
pid
);
sprintf
(
buf
,
"/proc/%d"
,
pid
);
stat
(
buf
,
&
st
);
stat
(
buf
,
&
st
);
if
(
proc_gid
==
st
.
st_g
id
)
if
(
args
->
uid
==
st
.
st_u
id
)
kill
(
pid
,
SIGTERM
);
kill
(
pid
,
SIGTERM
);
}
}
}
}
static
void
kill_process
(
const
char
*
name
)
{
static
void
kill_process
(
const
char
*
name
)
{
proc_name
=
name
;
ps_arg
args
=
{
.
name
=
name
};
char
buf
[
128
];
struct
stat
st
;
struct
stat
st
;
sprintf
(
buf
,
"/data/data/%s"
,
name
);
int
fd
=
xopen
(
"/data/data"
,
O_RDONLY
|
O_CLOEXEC
);
if
(
stat
(
buf
,
&
st
)
==
0
)
if
(
fstatat
(
fd
,
name
,
&
st
,
0
)
==
0
)
proc_gid
=
st
.
st_g
id
;
args
.
uid
=
st
.
st_u
id
;
else
else
proc_gid
=
0
;
args
.
uid
=
0
;
ps
(
kill_proc_cb
);
close
(
fd
);
ps
(
kill_proc_cb
,
&
args
);
}
}
void
clean_magisk_props
()
{
void
clean_magisk_props
()
{
...
@@ -143,16 +145,16 @@ static int add_list(sqlite3 *db, const char *proc) {
...
@@ -143,16 +145,16 @@ static int add_list(sqlite3 *db, const char *proc) {
}
}
LOGI
(
"hide_list add: [%s]
\n
"
,
proc
);
LOGI
(
"hide_list add: [%s]
\n
"
,
proc
);
kill_process
(
proc
);
// Critical region
// Critical region
pthread_mutex_lock
(
&
list_lock
);
pthread_mutex_lock
(
&
list_lock
);
hide_list
.
push_back
(
proc
);
hide_list
.
push_back
(
proc
);
kill_process
(
proc
);
pthread_mutex_unlock
(
&
list_lock
);
pthread_mutex_unlock
(
&
list_lock
);
// Add to database
// Add to database
char
sql
[
128
];
char
sql
[
4096
];
s
printf
(
sql
,
"INSERT INTO hidelist (process) VALUES('%s')"
,
proc
);
s
nprintf
(
sql
,
sizeof
(
sql
)
,
"INSERT INTO hidelist (process) VALUES('%s')"
,
proc
);
sqlite3_exec
(
db
,
sql
,
nullptr
,
nullptr
,
nullptr
);
sqlite3_exec
(
db
,
sql
,
nullptr
,
nullptr
,
nullptr
);
return
DAEMON_SUCCESS
;
return
DAEMON_SUCCESS
;
...
@@ -184,18 +186,18 @@ static int rm_list(const char *proc) {
...
@@ -184,18 +186,18 @@ static int rm_list(const char *proc) {
do_rm
=
true
;
do_rm
=
true
;
LOGI
(
"hide_list rm: [%s]
\n
"
,
proc
);
LOGI
(
"hide_list rm: [%s]
\n
"
,
proc
);
hide_list
.
erase
(
it
);
hide_list
.
erase
(
it
);
kill_process
(
proc
);
break
;
break
;
}
}
}
}
pthread_mutex_unlock
(
&
list_lock
);
pthread_mutex_unlock
(
&
list_lock
);
if
(
do_rm
)
{
if
(
do_rm
)
{
kill_process
(
proc
);
sqlite3
*
db
=
get_magiskdb
();
sqlite3
*
db
=
get_magiskdb
();
if
(
db
==
nullptr
)
if
(
db
==
nullptr
)
return
DAEMON_ERROR
;
return
DAEMON_ERROR
;
char
sql
[
128
];
char
sql
[
4096
];
s
printf
(
sql
,
"DELETE FROM hidelist WHERE process='%s'"
,
proc
);
s
nprintf
(
sql
,
sizeof
(
sql
)
,
"DELETE FROM hidelist WHERE process='%s'"
,
proc
);
sqlite3_exec
(
db
,
sql
,
nullptr
,
nullptr
,
nullptr
);
sqlite3_exec
(
db
,
sql
,
nullptr
,
nullptr
,
nullptr
);
sqlite3_close_v2
(
db
);
sqlite3_close_v2
(
db
);
return
DAEMON_SUCCESS
;
return
DAEMON_SUCCESS
;
...
...
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