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
d2c2456f
Unverified
Commit
d2c2456f
authored
Feb 05, 2022
by
LoveSy
Committed by
GitHub
Feb 05, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't use `getmntent_r` from system's libc
Fix #5354 Co-authored-by:
topjohnwu
<
topjohnwu@gmail.com
>
parent
e9f562a8
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
49 deletions
+57
-49
bootstages.cpp
native/jni/core/bootstages.cpp
+29
-22
compat.cpp
native/jni/utils/compat/compat.cpp
+0
-26
files.cpp
native/jni/utils/files.cpp
+28
-1
No files found.
native/jni/core/bootstages.cpp
View file @
d2c2456f
...
...
@@ -25,6 +25,7 @@ bool zygisk_enabled = false;
*********/
#define MNT_DIR_IS(dir) (me->mnt_dir == string_view(dir))
#define MNT_TYPE_IS(type) (me->mnt_type == string_view(type))
#define SETMIR(b, part) snprintf(b, sizeof(b), "%s/" MIRRDIR "/" #part, MAGISKTMP.data())
#define SETBLK(b, part) snprintf(b, sizeof(b), "%s/" BLOCKDIR "/" #part, MAGISKTMP.data())
...
...
@@ -39,8 +40,11 @@ bool zygisk_enabled = false;
}
#define mount_mirror(part, flag) \
else if (MNT_DIR_IS("/" #part) && me->mnt_type != "tmpfs"sv && me->mnt_type != "overlay"sv && lstat(me->mnt_dir, &st) == 0) \
do_mount_mirror(part, flag)
if (MNT_DIR_IS("/" #part) && !MNT_TYPE_IS("tmpfs") && !MNT_TYPE_IS("overlay") && \
lstat(me->mnt_dir, &st) == 0) { \
do_mount_mirror(part, flag); \
break; \
}
#define link_mirror(part) \
SETMIR(buf1, part); \
...
...
@@ -50,11 +54,12 @@ if (access("/system/" #part, F_OK) == 0 && access(buf1, F_OK) != 0) { \
}
#define link_orig_dir(dir, part) \
else if (MNT_DIR_IS(dir) && me->mnt_type != "tmpfs"sv && me->mnt_type != "overlay"sv
) { \
if (MNT_DIR_IS(dir) && !MNT_TYPE_IS("tmpfs") && !MNT_TYPE_IS("overlay")
) { \
SETMIR(buf1, part); \
rmdir(buf1); \
xsymlink(dir, buf1); \
LOGI("link: %s\n", buf1); \
break; \
}
#define link_orig(part) link_orig_dir("/" #part, part)
...
...
@@ -66,8 +71,8 @@ static void mount_mirrors() {
LOGI
(
"* Mounting mirrors
\n
"
);
parse_mnt
(
"/proc/mounts"
,
[
&
](
mntent
*
me
)
{
struct
stat
st
;
if
(
0
)
{}
struct
stat
st
{}
;
do
{
mount_mirror
(
system
,
MS_RDONLY
)
mount_mirror
(
vendor
,
MS_RDONLY
)
mount_mirror
(
product
,
MS_RDONLY
)
...
...
@@ -77,9 +82,11 @@ static void mount_mirrors() {
link_orig
(
metadata
)
link_orig
(
persist
)
link_orig_dir
(
"/mnt/vendor/persist"
,
persist
)
else
if
(
SDK_INT
>=
24
&&
MNT_DIR_IS
(
"/proc"
)
&&
!
strstr
(
me
->
mnt_opts
,
"hidepid=2"
))
{
if
(
SDK_INT
>=
24
&&
MNT_DIR_IS
(
"/proc"
)
&&
!
strstr
(
me
->
mnt_opts
,
"hidepid=2"
))
{
xmount
(
nullptr
,
"/proc"
,
nullptr
,
MS_REMOUNT
,
"hidepid=2,gid=3009"
);
break
;
}
}
while
(
false
);
return
true
;
});
SETMIR
(
buf1
,
system
);
...
...
native/jni/utils/compat/compat.cpp
View file @
d2c2456f
...
...
@@ -53,32 +53,6 @@ ssize_t getline(char **buf, size_t *bufsiz, FILE *fp) {
return
getdelim
(
buf
,
bufsiz
,
'\n'
,
fp
);
}
// Original source: https://android.googlesource.com/platform/bionic/+/master/libc/bionic/mntent.cpp
// License: AOSP, full copyright notice please check original source
struct
mntent
*
getmntent_r
(
FILE
*
fp
,
struct
mntent
*
e
,
char
*
buf
,
int
buf_len
)
{
memset
(
e
,
0
,
sizeof
(
*
e
));
while
(
fgets
(
buf
,
buf_len
,
fp
)
!=
nullptr
)
{
// Entries look like "proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0".
// That is: mnt_fsname mnt_dir mnt_type mnt_opts 0 0.
int
fsname0
,
fsname1
,
dir0
,
dir1
,
type0
,
type1
,
opts0
,
opts1
;
if
(
sscanf
(
buf
,
" %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d"
,
&
fsname0
,
&
fsname1
,
&
dir0
,
&
dir1
,
&
type0
,
&
type1
,
&
opts0
,
&
opts1
,
&
e
->
mnt_freq
,
&
e
->
mnt_passno
)
==
2
)
{
e
->
mnt_fsname
=
&
buf
[
fsname0
];
buf
[
fsname1
]
=
'\0'
;
e
->
mnt_dir
=
&
buf
[
dir0
];
buf
[
dir1
]
=
'\0'
;
e
->
mnt_type
=
&
buf
[
type0
];
buf
[
type1
]
=
'\0'
;
e
->
mnt_opts
=
&
buf
[
opts0
];
buf
[
opts1
]
=
'\0'
;
return
e
;
}
}
return
nullptr
;
}
FILE
*
setmntent
(
const
char
*
path
,
const
char
*
mode
)
{
return
fopen
(
path
,
mode
);
}
...
...
native/jni/utils/files.cpp
View file @
d2c2456f
...
...
@@ -352,12 +352,39 @@ void parse_prop_file(const char *file, const function<bool(string_view, string_v
});
}
// Original source: https://android.googlesource.com/platform/bionic/+/master/libc/bionic/mntent.cpp
// License: AOSP, full copyright notice please check original source
static
struct
mntent
*
compat_getmntent_r
(
FILE
*
fp
,
struct
mntent
*
e
,
char
*
buf
,
int
buf_len
)
{
memset
(
e
,
0
,
sizeof
(
*
e
));
while
(
fgets
(
buf
,
buf_len
,
fp
)
!=
nullptr
)
{
// Entries look like "proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0".
// That is: mnt_fsname mnt_dir mnt_type mnt_opts 0 0.
int
fsname0
,
fsname1
,
dir0
,
dir1
,
type0
,
type1
,
opts0
,
opts1
;
if
(
sscanf
(
buf
,
" %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d"
,
&
fsname0
,
&
fsname1
,
&
dir0
,
&
dir1
,
&
type0
,
&
type1
,
&
opts0
,
&
opts1
,
&
e
->
mnt_freq
,
&
e
->
mnt_passno
)
==
2
)
{
e
->
mnt_fsname
=
&
buf
[
fsname0
];
buf
[
fsname1
]
=
'\0'
;
e
->
mnt_dir
=
&
buf
[
dir0
];
buf
[
dir1
]
=
'\0'
;
e
->
mnt_type
=
&
buf
[
type0
];
buf
[
type1
]
=
'\0'
;
e
->
mnt_opts
=
&
buf
[
opts0
];
buf
[
opts1
]
=
'\0'
;
return
e
;
}
}
return
nullptr
;
}
void
parse_mnt
(
const
char
*
file
,
const
function
<
bool
(
mntent
*
)
>
&
fn
)
{
auto
fp
=
sFILE
(
setmntent
(
file
,
"re"
),
endmntent
);
if
(
fp
)
{
mntent
mentry
{};
char
buf
[
4096
];
while
(
getmntent_r
(
fp
.
get
(),
&
mentry
,
buf
,
sizeof
(
buf
)))
{
// getmntent_r from system's libc.so is broken on old platform
// use the compat one instead
while
(
compat_getmntent_r
(
fp
.
get
(),
&
mentry
,
buf
,
sizeof
(
buf
)))
{
if
(
!
fn
(
&
mentry
))
break
;
}
...
...
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