Skip to content

Overhaul SELinux DirtySepolicy Probes and Strengthen Root Detection#7

Closed
juanma0511 wants to merge 5 commits into
mainfrom
improve-selinux-detection-604517642015077392
Closed

Overhaul SELinux DirtySepolicy Probes and Strengthen Root Detection#7
juanma0511 wants to merge 5 commits into
mainfrom
improve-selinux-detection-604517642015077392

Conversation

@juanma0511

Copy link
Copy Markdown
Owner

This PR significantly improves the SELinux and root detection capabilities of the project by adopting a more robust, dual-track validation approach.

Key changes include:

  1. Isolated SELinux Probing: Introduced AppZygotePreload and SelinuxCarrierService, allowing the app to query SELinux policy from the highly restricted app_zygote context. This minimizes false positives caused by the main process's own context or runtime hooks.
  2. Expanded Rule Set: Ported advanced DirtySepolicy rules (e.g., fsck_untrusted sys_admin, shell -> su transition, and MSD daemon checks) based on recent developments in the security community (Duck-Detector-Refactoring).
  3. Active Attr-Current Probes: Implemented active probing by writing candidate root labels to /proc/self/attr/current to detect the materialization of privileged contexts in the live policy.
  4. Hardened Root Detection: Added specific markers for KernelSU Next and APatch, and improved SUSFS detection coverage.
  5. Stability & Bug Fixes: Performed a thorough audit of the native C++ codebase, fixing several issues related to unchecked system call returns, potential buffer overflows, and redundant process group scanning. Fixed a compilation error in RootDetector.kt.

Verified the changes with a full project build and unit tests.


PR created automatically by Jules for task 604517642015077392 started by @juanma0511

…detection

- Implemented AppZygote-based SELinux Carrier Service to reduce false positives by querying policy from a restricted context.
- Ported expanded DirtySepolicy rules and active `/proc/self/attr/current` write probes from Duck-Detector-Refactoring.
- Introduced dual-track validation (Native + Java) for SELinux access checks.
- Strengthened KernelSU Next and APatch detections with new paths and magic probes.
- Audited and fixed multiple memory/file-handle safety bugs in `native_root_checks.cpp`.
- Fixed a conflicting declaration bug in `RootDetector.kt`.

Co-authored-by: juanma0511 <121111348+juanma0511@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

google-labs-jules Bot and others added 4 commits May 17, 2026 13:56
…ives

- Refined SELinux context existence checks in native code using /sys/fs/selinux/context and /proc/self/attr/current writes, following the LSPosed/DirtySepolicy methodology.
- Implemented comprehensive dual-track (Native + Java) policy checks within the isolated AppZygote process to minimize false positives and bypass attempts.
- Added sanity checks for 'setcurrent' and 'check_context' to ensure the oracle is reliable before reporting detections.
- Ported the full suite of DirtySepolicy rules (Magisk, KernelSU, LSPosed, Xposed, adb_root, ZygiskNext).
- Implemented FD leak prevention for Android 11 and below during AppZygote preload.
- Audited native C++ code for safety, ensuring all 'read' system call returns are checked and file descriptors are closed correctly.
- Enhanced RootDetector to separately surface high-severity DirtySepolicy warnings retrieved from the carrier service.

Co-authored-by: juanma0511 <121111348+juanma0511@users.noreply.github.com>
- Fixed `contextExists` logic in `AppZygotePreload` to correctly identify privileged contexts when the kernel returns access-denied errors (non-EINVAL or EPERM).
- Removed overly strict sanity checks that were causing early exits on some devices.
- Improved AppZygote payload parsing in `RootDetector` to ensure granular native detections are always captured, even if the high-level status is OK.
- Verified the build and internal logic consistency.

Co-authored-by: juanma0511 <121111348+juanma0511@users.noreply.github.com>
…boration

- Refined `contextExists` logic to be highly sensitive to root contexts by interpreting any non-EINVAL response (including EACCES and EPERM) as proof of existence.
- Implemented KernelSU BitPair logic (Domain + File) for more granular detection reporting.
- Added `checkDangerousAppsCorroboration` using `createPackageContext` and direct `ZipFile` inspection to find hidden root managers.
- Expanded DirtySepolicy rule suite to include Magisk filesystem association and Kernel FIFO checks.
- Loosened AppZygote sanity checks to ensure detections are not blocked on restrictive OEM builds.
- Improved result parsing to ensure both high-level warnings and granular native signals are surfaced.
- Added "Glow" kernel to custom kernel detection.
- Increased AppZygote service timeout for better reliability on slow devices.

Co-authored-by: juanma0511 <121111348+juanma0511@users.noreply.github.com>
- Fixed critical bug in context probing by removing null terminators from raw SELinux filesystem writes, ensuring correct kernel interpretation of privileged contexts.
- Stabilized AppZygote by using full class names for preload registration and implementing a robust FD leak workaround for legacy Android versions.
- Expanded detection suite with SUSFS context existence checks and additional Magisk/KSU interaction rules.
- Improved diagnostic reporting by surfacing the SELinux oracle status and granular native detections in the main process.
- Conducted C++ safety audit, fixing multiple resource management and string handling issues.

Co-authored-by: juanma0511 <121111348+juanma0511@users.noreply.github.com>
@juanma0511 juanma0511 closed this May 17, 2026
@juanma0511
juanma0511 deleted the improve-selinux-detection-604517642015077392 branch May 17, 2026 20:27
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.

1 participant