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
63cfe7b4
Commit
63cfe7b4
authored
Sep 18, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sanitize_environ work properly
parent
db590091
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
19 deletions
+22
-19
rules.cpp
native/jni/magiskpolicy/rules.cpp
+3
-0
entry.cpp
native/jni/zygisk/entry.cpp
+19
-19
No files found.
native/jni/magiskpolicy/rules.cpp
View file @
63cfe7b4
...
@@ -165,6 +165,9 @@ void sepolicy::magisk_rules() {
...
@@ -165,6 +165,9 @@ void sepolicy::magisk_rules() {
// For changing file context
// For changing file context
allow
(
"rootfs"
,
"tmpfs"
,
"filesystem"
,
"associate"
);
allow
(
"rootfs"
,
"tmpfs"
,
"filesystem"
,
"associate"
);
// Allow Zygisk to prctl PR_SET_MM
allow
(
"zygote"
,
"zygote"
,
"capability"
,
"sys_resource"
);
// Allow update_engine/addon.d-v2 to run permissive on all ROMs
// Allow update_engine/addon.d-v2 to run permissive on all ROMs
permissive
(
"update_engine"
);
permissive
(
"update_engine"
);
...
...
native/jni/zygisk/entry.cpp
View file @
63cfe7b4
...
@@ -54,25 +54,26 @@ static void *unload_first_stage(void *v) {
...
@@ -54,25 +54,26 @@ static void *unload_first_stage(void *v) {
return
nullptr
;
return
nullptr
;
}
}
// Make sure /proc/self/environ
does not reveal our secrets
// Make sure /proc/self/environ
is sanitized
//
Copy all env to a contiguous memory and set the memory region as MM_ENV
//
Filter env and reset MM_ENV_END
static
void
sanitize_environ
()
{
static
void
sanitize_environ
()
{
static
string
env
;
char
*
cur
=
environ
[
0
]
;
for
(
int
i
=
0
;
environ
[
i
];
++
i
)
{
for
(
int
i
=
0
;
environ
[
i
];
++
i
)
{
if
(
str_starts
(
environ
[
i
],
INJECT_ENV_1
"="
))
if
(
str_starts
(
environ
[
i
],
INJECT_ENV_1
"="
))
{
// This specific env has to live in heap
environ
[
i
]
=
strdup
(
environ
[
i
]);
continue
;
continue
;
env
+=
environ
[
i
];
}
env
+=
'\0'
;
}
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
// Copy all filtered env onto the original stack
bool
success
=
true
;
int
len
=
strlen
(
environ
[
i
]);
success
&=
(
0
<=
prctl
(
PR_SET_MM
,
PR_SET_MM_ENV_START
,
env
.
data
(),
0
,
0
));
memmove
(
cur
,
environ
[
i
],
len
+
1
);
success
&=
(
0
<=
prctl
(
PR_SET_MM
,
PR_SET_MM_ENV_END
,
env
.
data
()
+
env
.
size
(),
0
,
0
));
environ
[
i
]
=
cur
;
if
(
success
)
cur
+=
len
+
1
;
break
;
}
}
prctl
(
PR_SET_MM
,
PR_SET_MM_ENV_END
,
cur
,
0
,
0
);
}
}
__attribute__
((
destructor
))
__attribute__
((
destructor
))
...
@@ -108,24 +109,23 @@ static void inject_init() {
...
@@ -108,24 +109,23 @@ static void inject_init() {
// Update path to 1st stage lib
// Update path to 1st stage lib
*
(
strrchr
(
env
,
'.'
)
-
1
)
=
'1'
;
*
(
strrchr
(
env
,
'.'
)
-
1
)
=
'1'
;
// Some cleanup
sanitize_environ
();
active_threads
++
;
active_threads
++
;
new_daemon_thread
(
&
unload_first_stage
,
env
);
new_daemon_thread
(
&
unload_first_stage
,
env
);
}
else
if
(
getenv
(
INJECT_ENV_1
))
{
}
else
if
(
getenv
(
INJECT_ENV_1
))
{
android_logging
();
android_logging
();
LOGD
(
"zygisk: inject 1st stage
\n
"
);
LOGD
(
"zygisk: inject 1st stage
\n
"
);
char
*
ld
=
getenv
(
"LD_PRELOAD"
);
string
ld
=
getenv
(
"LD_PRELOAD"
);
char
*
path
;
char
*
path
;
if
(
char
*
c
=
strrchr
(
ld
,
':'
))
{
if
(
char
*
c
=
strrchr
(
ld
.
data
()
,
':'
))
{
*
c
=
'\0'
;
*
c
=
'\0'
;
setenv
(
"LD_PRELOAD"
,
ld
,
1
);
// Restore original LD_PRELOAD
setenv
(
"LD_PRELOAD"
,
ld
.
data
()
,
1
);
// Restore original LD_PRELOAD
path
=
c
+
1
;
path
=
c
+
1
;
}
else
{
}
else
{
unsetenv
(
"LD_PRELOAD"
);
unsetenv
(
"LD_PRELOAD"
);
path
=
ld
;
path
=
ld
.
data
()
;
}
}
sanitize_environ
();
// Update path to 2nd stage lib
// Update path to 2nd stage lib
*
(
strrchr
(
path
,
'.'
)
-
1
)
=
'2'
;
*
(
strrchr
(
path
,
'.'
)
-
1
)
=
'2'
;
...
...
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