Skip to content

Commit fd25732

Browse files
authored
Refine SELinux rules for Xposed files (#149)
1. The SELinux context label `magisk_file` is widely used by Zygisk implementation modules. It is improper for LSPosed to abuse this label for its own files. We replace it by `xposed_file`. 2. A new rule added according to the SELinux logs, which is needed to write to the mangaer's SharedPreference. 3. `xposed_data` is a new SELinux context label for XSharedPreference files, it is not meant to provide MAC restricted access but to conform with Android's rule: https://developer.android.com/about/versions/pie/android-9.0-changes-28#per-app-selinux. We add attribute `mlstrustedobject` to ignore the `Multi-Level and Multi-Category Security` enforced on Android.
1 parent fba56a9 commit fd25732

File tree

6 files changed

+16
-7
lines changed

6 files changed

+16
-7
lines changed

daemon/src/main/java/org/lsposed/lspd/service/ConfigFileManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ static Path resolveModuleDir(String packageName, String dir, int userId, int uid
457457
if (uid != -1) {
458458
if (path.toFile().mkdirs()) {
459459
try {
460-
SELinux.setFileContext(path.toString(), "u:object_r:magisk_file:s0");
460+
SELinux.setFileContext(path.toString(), "u:object_r:xposed_file:s0");
461461
Os.chown(path.toString(), uid, uid);
462462
Os.chmod(path.toString(), 0755);
463463
} catch (ErrnoException e) {

daemon/src/main/java/org/lsposed/lspd/service/ConfigManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ private synchronized void updateConfig() {
299299
try {
300300
var perms = PosixFilePermissions.fromString("rwx--x--x");
301301
Files.createDirectories(miscPath, PosixFilePermissions.asFileAttribute(perms));
302-
walkFileTree(miscPath, f -> SELinux.setFileContext(f.toString(), "u:object_r:magisk_file:s0"));
302+
walkFileTree(miscPath, f -> SELinux.setFileContext(f.toString(), "u:object_r:xposed_data:s0"));
303303
} catch (IOException e) {
304304
Log.e(TAG, Log.getStackTraceString(e));
305305
}

daemon/src/main/java/org/lsposed/lspd/service/Dex2OatService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,16 @@ public void run() {
171171
Log.i(TAG, "Dex2oat wrapper daemon start");
172172
var sockPath = getSockPath();
173173
Log.d(TAG, "wrapper path: " + sockPath);
174-
var magisk_file = "u:object_r:magisk_file:s0";
174+
var xposed_file = "u:object_r:xposed_file:s0";
175175
var dex2oat_exec = "u:object_r:dex2oat_exec:s0";
176176
if (SELinux.checkSELinuxAccess("u:r:dex2oat:s0", dex2oat_exec,
177177
"file", "execute_no_trans")) {
178178
SELinux.setFileContext(WRAPPER32, dex2oat_exec);
179179
SELinux.setFileContext(WRAPPER64, dex2oat_exec);
180180
setSockCreateContext("u:r:dex2oat:s0");
181181
} else {
182-
SELinux.setFileContext(WRAPPER32, magisk_file);
183-
SELinux.setFileContext(WRAPPER64, magisk_file);
182+
SELinux.setFileContext(WRAPPER32, xposed_file);
183+
SELinux.setFileContext(WRAPPER64, xposed_file);
184184
setSockCreateContext("u:r:installd:s0");
185185
}
186186
try (var server = new LocalServerSocket(sockPath)) {

daemon/src/main/java/org/lsposed/lspd/service/LSPManagerService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public static void broadcastIntent(Intent inIntent) {
191191

192192
private void ensureWebViewPermission(File f) {
193193
if (!f.exists()) return;
194-
SELinux.setFileContext(f.getAbsolutePath(), "u:object_r:magisk_file:s0");
194+
SELinux.setFileContext(f.getAbsolutePath(), "u:object_r:xposed_file:s0");
195195
try {
196196
Os.chown(f.getAbsolutePath(), BuildConfig.MANAGER_INJECTED_UID, BuildConfig.MANAGER_INJECTED_UID);
197197
} catch (ErrnoException e) {

magisk-loader/magisk_module/customize.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ else
149149
fi
150150

151151
set_perm_recursive "$MODPATH" 0 0 0755 0644
152-
set_perm_recursive "$MODPATH/bin" 0 2000 0755 0755 u:object_r:magisk_file:s0
152+
set_perm_recursive "$MODPATH/bin" 0 2000 0755 0755 u:object_r:xposed_file:s0
153153
chmod 0744 "$MODPATH/daemon"
154154

155155
if [ "$(grep_prop ro.maple.enable)" == "1" ] && [ "$FLAVOR" == "zygisk" ]; then
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
11
allow dex2oat dex2oat_exec file execute_no_trans
2+
3+
allow shell shell dir write
4+
5+
type xposed_file file_type
6+
allow {installd isolated_app shell} xposed_file {file dir} *
7+
8+
type xposed_data file_type
9+
typeattribute xposed_data mlstrustedobject
10+
allow * xposed_data {file dir} *

0 commit comments

Comments
 (0)