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
34dcf49f
Commit
34dcf49f
authored
Jun 03, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update restorecon implementation
parent
ef2f8d48
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
79 additions
and
35 deletions
+79
-35
bootstages.c
native/jni/core/bootstages.c
+7
-14
magisk.c
native/jni/core/magisk.c
+1
-1
daemon.h
native/jni/include/daemon.h
+0
-1
magisk.h
native/jni/include/magisk.h
+11
-10
utils.h
native/jni/include/utils.h
+1
-1
file.c
native/jni/utils/file.c
+59
-8
No files found.
native/jni/core/bootstages.c
View file @
34dcf49f
...
@@ -311,11 +311,11 @@ static void clone_skeleton(struct node_entry *node) {
...
@@ -311,11 +311,11 @@ static void clone_skeleton(struct node_entry *node) {
if
(
IS_LNK
(
child
))
{
if
(
IS_LNK
(
child
))
{
// Copy symlinks directly
// Copy symlinks directly
cp_afc
(
buf2
,
buf
);
cp_afc
(
buf2
,
buf
);
#ifdef MAGISK_DEBUG
#ifdef MAGISK_DEBUG
LOGI
(
"creat_link: %s <- %s
\n
"
,
buf
,
buf2
);
LOGI
(
"creat_link: %s <- %s
\n
"
,
buf
,
buf2
);
#else
#else
LOGI
(
"creat_link: %s
\n
"
,
buf
);
LOGI
(
"creat_link: %s
\n
"
,
buf
);
#endif
#endif
}
else
{
}
else
{
snprintf
(
buf
,
PATH_MAX
,
"%s/%s"
,
full_path
,
child
->
name
);
snprintf
(
buf
,
PATH_MAX
,
"%s/%s"
,
full_path
,
child
->
name
);
bind_mount
(
buf2
,
buf
);
bind_mount
(
buf2
,
buf
);
...
@@ -449,18 +449,9 @@ static int prepare_img() {
...
@@ -449,18 +449,9 @@ static int prepare_img() {
// Remount them back :)
// Remount them back :)
magiskloop
=
mount_image
(
MAINIMG
,
MOUNTPOINT
);
magiskloop
=
mount_image
(
MAINIMG
,
MOUNTPOINT
);
free
(
magiskloop
);
free
(
magiskloop
);
// Fix file selinux contexts
fix_filecon
();
return
0
;
return
0
;
}
}
void
fix_filecon
()
{
int
dirfd
=
xopen
(
MOUNTPOINT
,
O_RDONLY
|
O_CLOEXEC
);
restorecon
(
dirfd
);
close
(
dirfd
);
}
/****************
/****************
* Entry points *
* Entry points *
****************/
****************/
...
@@ -675,6 +666,8 @@ void post_fs_data(int client) {
...
@@ -675,6 +666,8 @@ void post_fs_data(int client) {
if
(
prepare_img
())
if
(
prepare_img
())
goto
core_only
;
// Mounting fails, we can only do core only stuffs
goto
core_only
;
// Mounting fails, we can only do core only stuffs
restorecon
();
// Run common scripts
// Run common scripts
LOGI
(
"* Running post-fs-data.d scripts
\n
"
);
LOGI
(
"* Running post-fs-data.d scripts
\n
"
);
exec_common_script
(
"post-fs-data"
);
exec_common_script
(
"post-fs-data"
);
...
...
native/jni/core/magisk.c
View file @
34dcf49f
...
@@ -136,7 +136,7 @@ int magisk_main(int argc, char *argv[]) {
...
@@ -136,7 +136,7 @@ int magisk_main(int argc, char *argv[]) {
unlock_blocks
();
unlock_blocks
();
return
0
;
return
0
;
}
else
if
(
strcmp
(
argv
[
1
],
"--restorecon"
)
==
0
)
{
}
else
if
(
strcmp
(
argv
[
1
],
"--restorecon"
)
==
0
)
{
fix_fil
econ
();
restor
econ
();
return
0
;
return
0
;
}
else
if
(
strcmp
(
argv
[
1
],
"--clone-attr"
)
==
0
)
{
}
else
if
(
strcmp
(
argv
[
1
],
"--clone-attr"
)
==
0
)
{
if
(
argc
<
4
)
usage
();
if
(
argc
<
4
)
usage
();
...
...
native/jni/include/daemon.h
View file @
34dcf49f
...
@@ -62,7 +62,6 @@ void write_string(int fd, const char* val);
...
@@ -62,7 +62,6 @@ void write_string(int fd, const char* val);
void
startup
();
void
startup
();
void
post_fs_data
(
int
client
);
void
post_fs_data
(
int
client
);
void
late_start
(
int
client
);
void
late_start
(
int
client
);
void
fix_filecon
();
/**************
/**************
* MagiskHide *
* MagiskHide *
...
...
native/jni/include/magisk.h
View file @
34dcf49f
...
@@ -24,21 +24,22 @@
...
@@ -24,21 +24,22 @@
#define COREDIR MOUNTPOINT "/.core"
#define COREDIR MOUNTPOINT "/.core"
#define HOSTSFILE COREDIR "/hosts"
#define HOSTSFILE COREDIR "/hosts"
#define HIDELIST COREDIR "/hidelist"
#define HIDELIST COREDIR "/hidelist"
#define SECURE_DIR "/data/adb
/
"
#define SECURE_DIR "/data/adb"
#define MAINIMG SECURE_DIR "magisk.img"
#define MAINIMG SECURE_DIR "
/
magisk.img"
#define DATABIN SECURE_DIR "magisk"
#define DATABIN SECURE_DIR "
/
magisk"
#define MAGISKDB SECURE_DIR "magisk.db"
#define MAGISKDB SECURE_DIR "
/
magisk.db"
#define SIMPLEMOUNT SECURE_DIR "magisk_simple"
#define SIMPLEMOUNT SECURE_DIR "
/
magisk_simple"
#define DEBUG_LOG SECURE_DIR "magisk_debug.log"
#define DEBUG_LOG SECURE_DIR "
/
magisk_debug.log"
#define MANAGERAPK DATABIN "/magisk.apk"
#define MANAGERAPK DATABIN "/magisk.apk"
#define MAGISKRC "/init.magisk.rc"
#define MAGISKRC "/init.magisk.rc"
// selinuxfs paths
// selinuxfs paths
#define SELINUX_PATH "/sys/fs/selinux/"
#define SELINUX_PATH "/sys/fs/selinux"
#define SELINUX_ENFORCE SELINUX_PATH "enforce"
#define SELINUX_ENFORCE SELINUX_PATH "/enforce"
#define SELINUX_POLICY SELINUX_PATH "policy"
#define SELINUX_POLICY SELINUX_PATH "/policy"
#define SELINUX_LOAD SELINUX_PATH "load"
#define SELINUX_LOAD SELINUX_PATH "/load"
#define SELINUX_CONTEXT SELINUX_PATH "/context"
// split policy paths
// split policy paths
#define PLAT_POLICY_DIR "/system/etc/selinux/"
#define PLAT_POLICY_DIR "/system/etc/selinux/"
...
...
native/jni/include/utils.h
View file @
34dcf49f
...
@@ -122,7 +122,7 @@ int setattrat(int dirfd, const char *pathname, struct file_attr *a);
...
@@ -122,7 +122,7 @@ int setattrat(int dirfd, const char *pathname, struct file_attr *a);
int
fsetattr
(
int
fd
,
struct
file_attr
*
a
);
int
fsetattr
(
int
fd
,
struct
file_attr
*
a
);
void
fclone_attr
(
const
int
sourcefd
,
const
int
targetfd
);
void
fclone_attr
(
const
int
sourcefd
,
const
int
targetfd
);
void
clone_attr
(
const
char
*
source
,
const
char
*
target
);
void
clone_attr
(
const
char
*
source
,
const
char
*
target
);
void
restorecon
(
int
dirfd
);
void
restorecon
();
int
mmap_ro
(
const
char
*
filename
,
void
**
buf
,
size_t
*
size
);
int
mmap_ro
(
const
char
*
filename
,
void
**
buf
,
size_t
*
size
);
int
mmap_rw
(
const
char
*
filename
,
void
**
buf
,
size_t
*
size
);
int
mmap_rw
(
const
char
*
filename
,
void
**
buf
,
size_t
*
size
);
void
fd_full_read
(
int
fd
,
void
**
buf
,
size_t
*
size
);
void
fd_full_read
(
int
fd
,
void
**
buf
,
size_t
*
size
);
...
...
native/jni/utils/file.c
View file @
34dcf49f
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
#include <selinux/selinux.h>
#include <selinux/selinux.h>
#endif
#endif
#include "magisk.h"
#include "utils.h"
#include "utils.h"
char
**
excl_list
=
NULL
;
char
**
excl_list
=
NULL
;
...
@@ -341,17 +342,22 @@ void fclone_attr(const int sourcefd, const int targetfd) {
...
@@ -341,17 +342,22 @@ void fclone_attr(const int sourcefd, const int targetfd) {
#ifdef SELINUX
#ifdef SELINUX
#include "magiskpolicy.h"
#define UNLABEL_CON "u:object_r:unlabeled:s0"
#define UNLABEL_CON "u:object_r:unlabeled:s0"
#define SYSTEM_CON "u:object_r:system_file:s0"
#define SYSTEM_CON "u:object_r:system_file:s0"
#define ADB_CON "u:object_r:adb_data_file:s0"
#define MAGISK_CON "u:object_r:"SEPOL_FILE_DOMAIN":s0"
void
restore
con
(
int
dirfd
)
{
static
void
restore_sys
con
(
int
dirfd
)
{
struct
dirent
*
entry
;
struct
dirent
*
entry
;
DIR
*
dir
;
DIR
*
dir
;
int
fd
;
char
path
[
PATH_MAX
],
*
con
;
char
path
[
PATH_MAX
],
*
con
;
fd_getpath
(
dirfd
,
path
,
sizeof
(
path
));
fd_getpath
(
dirfd
,
path
,
sizeof
(
path
));
lgetfilecon
(
path
,
&
con
);
size_t
len
=
strlen
(
path
);
getfilecon
(
path
,
&
con
);
if
(
strlen
(
con
)
==
0
||
strcmp
(
con
,
UNLABEL_CON
)
==
0
)
if
(
strlen
(
con
)
==
0
||
strcmp
(
con
,
UNLABEL_CON
)
==
0
)
lsetfilecon
(
path
,
SYSTEM_CON
);
lsetfilecon
(
path
,
SYSTEM_CON
);
freecon
(
con
);
freecon
(
con
);
...
@@ -361,20 +367,65 @@ void restorecon(int dirfd) {
...
@@ -361,20 +367,65 @@ void restorecon(int dirfd) {
if
(
strcmp
(
entry
->
d_name
,
"."
)
==
0
||
strcmp
(
entry
->
d_name
,
".."
)
==
0
)
if
(
strcmp
(
entry
->
d_name
,
"."
)
==
0
||
strcmp
(
entry
->
d_name
,
".."
)
==
0
)
continue
;
continue
;
if
(
entry
->
d_type
==
DT_DIR
)
{
if
(
entry
->
d_type
==
DT_DIR
)
{
fd
=
xopenat
(
dirfd
,
entry
->
d_name
,
O_RDONLY
|
O_CLOEXEC
);
int
fd
=
xopenat
(
dirfd
,
entry
->
d_name
,
O_RDONLY
|
O_CLOEXEC
);
restorecon
(
fd
);
restore_syscon
(
fd
);
close
(
fd
);
}
else
{
}
else
{
fd
=
xopenat
(
dirfd
,
entry
->
d_name
,
O_PATH
|
O_NOFOLLOW
|
O_CLOEXEC
)
;
path
[
len
]
=
'/'
;
fd_getpath
(
fd
,
path
,
sizeof
(
path
)
);
strcpy
(
path
+
len
+
1
,
entry
->
d_name
);
lgetfilecon
(
path
,
&
con
);
lgetfilecon
(
path
,
&
con
);
if
(
strlen
(
con
)
==
0
||
strcmp
(
con
,
UNLABEL_CON
)
==
0
)
if
(
strlen
(
con
)
==
0
||
strcmp
(
con
,
UNLABEL_CON
)
==
0
)
lsetfilecon
(
path
,
SYSTEM_CON
);
lsetfilecon
(
path
,
SYSTEM_CON
);
freecon
(
con
);
freecon
(
con
);
path
[
len
]
=
'\0'
;
}
}
}
static
void
restore_magiskcon
(
int
dirfd
)
{
struct
dirent
*
entry
;
DIR
*
dir
;
char
path
[
PATH_MAX
];
fd_getpath
(
dirfd
,
path
,
sizeof
(
path
));
size_t
len
=
strlen
(
path
);
lsetfilecon
(
path
,
MAGISK_CON
);
lchown
(
path
,
0
,
0
);
dir
=
xfdopendir
(
dirfd
);
while
((
entry
=
xreaddir
(
dir
)))
{
if
(
strcmp
(
entry
->
d_name
,
"."
)
==
0
||
strcmp
(
entry
->
d_name
,
".."
)
==
0
)
continue
;
if
(
entry
->
d_type
==
DT_DIR
)
{
int
fd
=
xopenat
(
dirfd
,
entry
->
d_name
,
O_RDONLY
|
O_CLOEXEC
);
restore_magiskcon
(
fd
);
close
(
fd
);
}
else
{
path
[
len
]
=
'/'
;
strcpy
(
path
+
len
+
1
,
entry
->
d_name
);
lsetfilecon
(
path
,
MAGISK_CON
);
lchown
(
path
,
0
,
0
);
path
[
len
]
=
'\0'
;
}
}
close
(
fd
);
}
}
}
}
void
restorecon
()
{
int
fd
;
fd
=
xopen
(
SELINUX_CONTEXT
,
O_WRONLY
|
O_CLOEXEC
);
if
(
write
(
fd
,
ADB_CON
,
sizeof
(
ADB_CON
))
>=
0
)
{
lsetfilecon
(
SECURE_DIR
,
ADB_CON
);
}
close
(
fd
);
fd
=
xopen
(
MOUNTPOINT
,
O_RDONLY
|
O_CLOEXEC
);
restore_syscon
(
fd
);
close
(
fd
);
fd
=
xopen
(
DATABIN
,
O_RDONLY
|
O_CLOEXEC
);
restore_magiskcon
(
fd
);
close
(
fd
);
}
#endif // SELINUX
#endif // SELINUX
static
int
_mmap
(
int
rw
,
const
char
*
filename
,
void
**
buf
,
size_t
*
size
)
{
static
int
_mmap
(
int
rw
,
const
char
*
filename
,
void
**
buf
,
size_t
*
size
)
{
...
...
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