Skip to content

Change authentication mechanism in order to support KernelSU SELinux Hide - #129

Closed
HiFiPhile wants to merge 1 commit into
chenxiaolong:masterfrom
HiFiPhile:pr/selinux-hide-auth
Closed

HiFiPhile wants to merge 1 commit into
chenxiaolong:masterfrom
HiFiPhile:pr/selinux-hide-auth

Conversation

@HiFiPhile

Copy link
Copy Markdown
Contributor

Issue

On the tested KernelSU Next setup, enabling SELinux Hide prevents MSD from launching because Android rejects its injected msd_app context.

Fix

Referenced the authentication mechanism used by KernelSU to ensure that the MSD daemon can authenticate clients securely even when SELinux Hide is enabled, use the existing untrusted_app domain for the UI.

The daemon obtains the peer UID with SO_PEERCRED. A root app_process supervisor checks that UID against Package Manager and requires the exact MSD package, matching full UID and Android user, no shared UID, and one current signer matching a certificate pin generated from the module's signing configuration. Queries use private inherited pipes; the client cannot supply its own identity or verification result.

Authenticate before the protocol handshake and worker creation, then revalidate before each request. Pipe errors, malformed responses, and timeouts fail closed, including protection against accepting a late response for another request. Keep the daemon's restricted SELinux domain, system UID, CAP_CHOWN, and existing SELinux checks.

This changes the access-control boundary: other apps in untrusted_app can reach the socket, but must pass authentication. It also adds a root supervisor and a Package Manager dependency. UID 0 retains CLI access; shell and UID 1000 do not bypass authentication, including when --allow-adb grants SELinux connectivity. Certificate rotation requires an updated pin.

Test environment

  • Device model: OnePlus CPH2747
  • Android version: 16
  • KernelSU Next userspace version: 3.4.0
  • MSD version: 2.5, with local compatibility changes and the upstream-signed UI APK retained
  • SELinux: enforcing
  • SELinux Hide: enabled

Validation

  • Reboot and two cold launches succeeded with SELinux Hide enabled and SELinux enforcing.
  • The valid MSD UID/certificate was accepted. A wrong pin, another installed app's UID, and an unrelated app in untrusted_app were rejected.
  • All five native authentication tests passed on the phone.
  • The native daemon and standalone Java/DEX supervisor compiled; Rust formatting and patch whitespace checks passed.

CI

  • Android build and module packaging: passed (./gradlew --no-daemon build zipDebug -x assembleRelease).
  • Native builds: arm64-v8a, armeabi-v7a, and x86_64 passed.
  • Android lint: passed. The Gradle unit-test task reported NO-SOURCE; CI did not execute device tests or the native authentication tests.
  • cargo-deny: passed.

CI ran on ci/selinux-hide-auth at a1726d3. Its source matches pr/selinux-hide-auth at 7a40ce1; only the two workflow push triggers differ. Release builds are excluded by the existing workflow.

@chenxiaolong

Copy link
Copy Markdown
Owner

Thanks for the PR! This is a neat idea.

However, it's pretty unlikely that I'll change how the daemon authentication works. I generally don't play the cat and mouse game to try to accommodate root (or root-related) hiding mechanisms in any of my projects.

The daemon was originally set up to use SELinux for access control since the implementation is simple and is how many other AOSP daemons, like update_engine, work. One of the use cases for MSD I have is allowing it to work on unrooted devices where it is bundled as part of the OS so matching what AOSP does and ease of integrating with the OS is something I value highly over other things (this is also how I personally use MSD).

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