Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce SELinux labels for Xposed files #149

Merged
merged 1 commit into from
Jan 5, 2025
Merged

Introduce SELinux labels for Xposed files #149

merged 1 commit into from
Jan 5, 2025

Conversation

JingMatrix
Copy link
Owner

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 thus introduce two new labels, xposed_file and xposed_module. The first one will be used with strict MAC rules, while the second one is meant to be accessible for all application processes, including Xposed modules. The xposed_module label might be removed in the future since its function remains unclear.

@JingMatrix
Copy link
Owner Author

It is strange to still have AVC denial logs as follows:

<36>[  153.957601][  T516] type=1400 audit(1736011037.808:940): avc:  denied  { write } for  comm="queued-work-loo" name="com.wmods.wppenhacer" dev="dm-53" ino=836004 scontext=u:r:untrusted_app:s0:c16,c257,c522,c768 tcontext=u:object_r:xposed_module:s0 tclass=dir permissive=0

@JingMatrix
Copy link
Owner Author

To reproduce the previous case,

  1. Install Xposed module WaEnhencer
  2. Enable the module and open its setting UI
  3. Toggle settings while printing SELinux logs: adb shell su -c 'cat /proc/kmsg | grep avc:'

@Dev4Mod I notify you about this bug since your module is taken as an example. However, this happens for any modules using XSharedPrefrences.

@@ -1 +1,7 @@
allow dex2oat dex2oat_exec file execute_no_trans

allow zygote appdomain_tmpfs file *
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://cs.android.com/android/platform/superproject/main/+/main:system/sepolicy/private/su.te;l=29;drc=75806ef3c529c019ab002072cca7951b91f245aa

The issue is on userdebug rom, su is appdomain, so tmpfs it creates is appdomain_tmpfs too. So this should be fixed in zygisk, not lsposed.

Copy link
Owner Author

@JingMatrix JingMatrix Jan 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that is reasonable. It is strange that in the users' phone, without LSPosed, NeoZygisk without this rule can still work without problem.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed from logs that you are correct, this rule must be added from the Zygisk side. Thanks for pointing ot out!

@@ -299,7 +299,7 @@ private synchronized void updateConfig() {
try {
var perms = PosixFilePermissions.fromString("rwx--x--x");
Files.createDirectories(miscPath, PosixFilePermissions.asFileAttribute(perms));
walkFileTree(miscPath, f -> SELinux.setFileContext(f.toString(), "u:object_r:magisk_file:s0"));
walkFileTree(miscPath, f -> SELinux.setFileContext(f.toString(), "u:object_r:app_data_file:s0"));
Copy link

@aviraxp aviraxp Jan 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug I described happens for this commit: b2be97b
The one you are commenting on is my fix for the bug.

Currently, on my device, the problem doesn't exist anymore. But the user in #146 still suffers from it.

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.
@JingMatrix
Copy link
Owner Author

It turns out that we should add attribute mlstrustedobject to ignore the Multi-Level and Multi-Category Security enforced on Android.

@JingMatrix JingMatrix merged commit fd25732 into master Jan 5, 2025
1 check passed
@JingMatrix
Copy link
Owner Author

JingMatrix commented Jan 6, 2025

Current rule still causes the problem of WebView crashing:

<38>[  156.734486][  T520] type=1400 audit(1736177141.808:117): avc:  denied  { write } for  comm="Chrome_ChildIOT" path=2F646174612F757365722F302F636F6D2E616E64726F69642E7368656C6C2F63616368652F2E636F6D2E676F6F676C652E4368726F6D652E306763506F42202864656C6574656429 dev="dm-53" ino=950335 scontext=u:r:isolated_app:s0:c512,c768 tcontext=u:object_r:xposed_file:s0 tclass=file permissive=1

We should thus also add

typeattribute xposed_file mlstrustedobject

JingMatrix added a commit that referenced this pull request Jan 6, 2025
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.
4. We add attribute `mlstrustedobject` to ignore the `Multi-Level and Multi-Category Security` enforced on Android.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants