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
dbbc8571
Commit
dbbc8571
authored
Nov 13, 2016
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MagiskHide: Unmount cache mounts and check UID
parent
0ddb6c3f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
17 deletions
+38
-17
magiskhide.c
jni/magiskhide.c
+37
-14
magic_mask.sh
scripts/magic_mask.sh
+1
-3
No files found.
jni/magiskhide.c
View file @
dbbc8571
...
@@ -11,6 +11,8 @@
...
@@ -11,6 +11,8 @@
#include <sys/mount.h>
#include <sys/mount.h>
#include <sys/inotify.h>
#include <sys/inotify.h>
#include <sys/wait.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
#define LOGFILE "/cache/magisk.log"
#define LOGFILE "/cache/magisk.log"
#define HIDELIST "/magisk/.core/magiskhide/hidelist"
#define HIDELIST "/magisk/.core/magiskhide/hidelist"
...
@@ -55,40 +57,61 @@ void lazy_unmount(const char* mountpoint) {
...
@@ -55,40 +57,61 @@ void lazy_unmount(const char* mountpoint) {
//WARNING: Calling this will change our current namespace
//WARNING: Calling this will change our current namespace
//We don't care because we don't want to run from here anyway
//We don't care because we don't want to run from here anyway
int
hideMagisk
(
int
pid
)
{
int
hideMagisk
(
int
pid
,
int
uid
)
{
char
*
path
=
NULL
;
struct
stat
info
;
asprintf
(
&
path
,
"/proc/%d/ns/mnt"
,
pid
);
char
path
[
256
];
snprintf
(
path
,
256
,
"/proc/%d"
,
pid
);
if
(
stat
(
path
,
&
info
)
==
-
1
)
{
fprintf
(
logfile
,
"MagiskHide: Unable to get info for pid=%d
\n
"
,
pid
);
return
1
;
}
if
(
info
.
st_uid
!=
uid
)
{
fprintf
(
logfile
,
"MagiskHide: Incorrect uid=%d, expect uid=%d
\n
"
,
info
.
st_uid
,
uid
);
return
1
;
}
snprintf
(
path
,
256
,
"/proc/%d/ns/mnt"
,
pid
);
int
fd
=
open
(
path
,
O_RDONLY
);
int
fd
=
open
(
path
,
O_RDONLY
);
if
(
fd
==
-
1
)
return
2
;
// Maybe process died..
if
(
fd
==
-
1
)
return
2
;
// Maybe process died..
if
(
setns
(
fd
,
0
)
==
-
1
)
{
if
(
setns
(
fd
,
0
)
==
-
1
)
{
fprintf
(
logfile
,
"Unable to change namespace for pid=%d
\n
"
,
pid
);
fprintf
(
logfile
,
"
MagiskHide:
Unable to change namespace for pid=%d
\n
"
,
pid
);
return
3
;
return
3
;
}
}
free
(
path
);
snprintf
(
path
,
256
,
"/proc/%d/mounts"
,
pid
);
path
=
NULL
;
asprintf
(
&
path
,
"/proc/%d/mounts"
,
pid
);
FILE
*
mount_fp
=
fopen
(
path
,
"r"
);
FILE
*
mount_fp
=
fopen
(
path
,
"r"
);
if
(
mount_fp
==
NULL
)
{
if
(
mount_fp
==
NULL
)
{
fprintf
(
logfile
,
"Error opening mount list!
\n
"
);
fprintf
(
logfile
,
"
MagiskHide:
Error opening mount list!
\n
"
);
return
4
;
return
4
;
}
}
free
(
path
);
int
mount_size
;
int
mount_size
;
char
**
mount_list
=
file_to_str_arr
(
mount_fp
,
&
mount_size
),
mountpoint
[
256
],
*
sbstr
;
char
**
mount_list
=
file_to_str_arr
(
mount_fp
,
&
mount_size
),
mountpoint
[
256
],
cache_block
[
256
]
;
fclose
(
mount_fp
);
fclose
(
mount_fp
);
// Find the cache block
for
(
i
=
0
;
i
<
mount_size
;
++
i
)
{
if
(
strstr
(
mount_list
[
i
],
"/cache"
))
{
sscanf
(
mount_list
[
i
],
"%256s"
,
cache_block
);
break
;
}
}
// Unmount in inverse order
// Unmount in inverse order
for
(
i
=
mount_size
-
1
;
i
>=
0
;
--
i
)
{
for
(
i
=
mount_size
-
1
;
i
>=
0
;
--
i
)
{
if
(
strstr
(
mount_list
[
i
],
"/dev/block/loop"
))
{
if
(
strstr
(
mount_list
[
i
],
cache_block
)
&&
strstr
(
mount_list
[
i
],
"/system"
))
{
sscanf
(
mount_list
[
i
],
"%256s %256s"
,
mountpoint
,
mountpoint
);
}
else
if
(
strstr
(
mount_list
[
i
],
"/dev/block/loop"
))
{
if
(
strstr
(
mount_list
[
i
],
"/dev/magisk"
))
continue
;
if
(
strstr
(
mount_list
[
i
],
"/dev/magisk"
))
continue
;
// Everything from loop mount
// Everything from loop mount
sscanf
(
mount_list
[
i
],
"%256s %256s"
,
mountpoint
,
mountpoint
);
sscanf
(
mount_list
[
i
],
"%256s %256s"
,
mountpoint
,
mountpoint
);
}
else
if
(
strstr
(
mount_list
[
i
],
"tmpfs /system/"
))
{
}
else
if
(
strstr
(
mount_list
[
i
],
"tmpfs /system/"
))
{
// Directly unmount skeletons
// Directly unmount skeletons
sscanf
(
mount_list
[
i
],
"%256s %256s"
,
mountpoint
,
mountpoint
);
sscanf
(
mount_list
[
i
],
"%256s %256s"
,
mountpoint
,
mountpoint
);
}
else
continue
;
}
else
{
free
(
mount_list
[
i
]);
continue
;
}
lazy_unmount
(
mountpoint
);
lazy_unmount
(
mountpoint
);
free
(
mount_list
[
i
]);
free
(
mount_list
[
i
]);
}
}
...
@@ -116,7 +139,7 @@ void update_list(const char *listpath) {
...
@@ -116,7 +139,7 @@ void update_list(const char *listpath) {
fclose
(
hide_fp
);
fclose
(
hide_fp
);
if
(
list_size
)
fprintf
(
logfile
,
"MagiskHide: Update process/package list:
\n
"
);
if
(
list_size
)
fprintf
(
logfile
,
"MagiskHide: Update process/package list:
\n
"
);
for
(
i
=
0
;
i
<
list_size
;
i
++
)
for
(
i
=
0
;
i
<
list_size
;
i
++
)
fprintf
(
logfile
,
"MagiskHide:
%s
\n
"
,
hide_list
[
i
]);
fprintf
(
logfile
,
"MagiskHide:
[%s]
\n
"
,
hide_list
[
i
]);
}
}
void
quit_pthread
(
int
sig
)
{
void
quit_pthread
(
int
sig
)
{
...
@@ -209,7 +232,7 @@ int main(int argc, char **argv, char **envp) {
...
@@ -209,7 +232,7 @@ int main(int argc, char **argv, char **envp) {
if
(
forkpid
<
0
)
if
(
forkpid
<
0
)
break
;
break
;
if
(
forkpid
==
0
)
{
if
(
forkpid
==
0
)
{
hideMagisk
(
pid
);
hideMagisk
(
pid
,
uid
);
return
0
;
return
0
;
}
}
waitpid
(
forkpid
,
NULL
,
0
);
waitpid
(
forkpid
,
NULL
,
0
);
...
...
scripts/magic_mask.sh
View file @
dbbc8571
...
@@ -377,9 +377,7 @@ case $1 in
...
@@ -377,9 +377,7 @@ case $1 in
done
done
# Proper permissions for generated items
# Proper permissions for generated items
$TOOLPATH
/find
$TMPDIR
-type
d
-exec
chmod
755
"{}"
\;
chcon
-R
"u:object_r:system_file:s0"
$TMPDIR
$TOOLPATH
/find
$TMPDIR
-type
f
-exec
chmod
644
"{}"
\;
$TOOLPATH
/find
$TMPDIR
-exec
chcon
"u:object_r:system_file:s0"
"{}"
\;
# Stage 2
# Stage 2
log_print
"Bind mount module items"
log_print
"Bind mount module items"
...
...
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