# Research notes This file records the checks that shaped the design. All tests ran on the Android emulator images in this workspace unless stated otherwise. ## Target matrix | Android | API | App uid | `no_new_privs` | SlopRoot action | | --- | --- | --- | --- | --- | | 2.2 to 4.4 | 8 to 19 | app | not set by `app_process` | attempt exploit and install when the ROM/kernel is vulnerable | | 5.0 to 5.1 | 21 to 22 | app | 1 | detect, check existing root | | 6.0 | 23 | app | 1 | detect, check existing root | | 7.0 and newer | 24+ | app | 1 | refuse | ## API 23 app sandbox An app process on the API 23 image showed: ``` uid=10055(u0_a55) gid=10055(u0_a55) groups=10055(u0_a55),9997(everybody),50055(all_a55) context=u:r:untrusted_app:s0:c512,c768 CapInh: 0000000000000000 CapPrm: 0000000000000000 CapEff: 0000000000000000 CapBnd: 0000000000000000 no_new_privs=1 ``` `librank` and `procmem` are mode `06755 root:root` and SELinux type `system_file`. The app can execute them, but the process keeps uid 10055. A static helper confirmed `setuid(0)` fails with `EPERM` when `no_new_privs=1`. `/system/xbin/procrank` is mode `06755 root:root` but type `procrank_exec`. The app is denied execute: ``` avc: denied { execute } for pid=2133 comm="Thread-147" name="procrank" scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:procrank_exec:s0 tclass=file permissive=0 ``` `/system/xbin/su` is mode `04750 root:shell`, type `su_exec`. The app cannot execute it. The `run-as` helper is type `runas_exec` and is not usable from an untrusted app. It also inherits `no_new_privs`. ## AOSP `app_process` `frameworks/base/cmds/app_process/app_main.cpp` sets: ```c if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0) { ``` The check was made against tags `android-5.0.2_r3`, `android-5.1.1_r38`, and `android-6.0.1_r81`. The flag is inherited by every child process, including `Runtime.exec` children. ## Dirty COW behavior CVE-2016-5195 lets a process write to a private read-only mapping through `/proc/self/mem` while another thread calls `madvise(MADV_DONTNEED)`. The write lands in the page cache of the target file, even when the filesystem is mounted read-only. The mode, owner, and SELinux label of the target do not change. On the API 23 image, patching `/system/xbin/procrank` and `/system/xbin/librank` succeeded. Executing the patched `librank` from an already-root adb shell produced uid 0 and `context=u:r:su:s0`. This proves the payload and the page cache write. It does not prove app-only root, because the adb shell was already privileged. The exploit must pad the payload to the target file size. A same-size write avoids changing the inode size and keeps the setuid mode. ## `debuggerd` boot injection test The API 23 image has no `/system/bin/install-recovery.sh`. The next candidate was `/system/bin/debuggerd`, a root service started by init. A 2.5 KB static payload was Dirty COW written over `debuggerd`. The service was restarted with `stop debuggerd; start debuggerd`. The payload logged to `/data/tombstones/inject.log`, which the `debuggerd` domain can write. Observed log: ``` INJECT start uid=0 euid=0 ctx=u:r:debuggerd:s0 open_system=-30 open_appdata=-2 remount=-13 open_enforce=4 write_enforce=-13 chmod_log=0 INJECT exec execve=-13 ``` Interpretation: - `-30` is `EROFS`. `/system` was mounted read-only. - `-13` is `EACCES`. The `debuggerd` domain lacks the capability and SELinux permission to remount `/system`. - `open_enforce=4` means the policy file opened, but `write_enforce=-13` means `setenforce` is denied. - `execve=-13` means `/system/bin/sh` cannot be executed from the `debuggerd` domain. - `open_appdata=-2` is `ENOENT` because the probe app was not installed at that moment. It is not evidence of access. The `debuggerd` domain is intentionally confined to crash dumping. It is not a usable root context. Patching a service at boot does not help if the service domain cannot write `/system` or change policy. ## Why KingRoot and Kingo appear to work Public analyses of KingRoot, Kingo, and similar tools show a chain, not a single SELinux trick: 1. A kernel or vendor exploit gives code execution in a privileged process or in the kernel. 2. The tool installs a root daemon. 3. `supolicy` and `libsupol` patch the SELinux policy so the daemon keeps working after the exploit is gone. The SELinux policy manipulation is a post-exploitation step. It does not replace the initial privilege escalation. On Android 5.0 and newer, Dirty COW is a file write primitive. It does not give kernel memory write or a privileged process context, and `no_new_privs` blocks the setuid route. That is why SlopRoot does not claim root on 5.0 and newer without an additional exploit. ## Old device notes - `/system/xbin/su` on the API 10 image is mode `06755 root:root`, 64208 bytes. - `procrank` is 9716 bytes, `procmem` 9644 bytes, `librank` 14856 bytes. - The API 10 emulator crashes in the zygote prelink step on this host (`prelinked library 'libstagefright.so' mapped at ... not at 0xa2f00000`). The API 10 image was inspected with `debugfs`, but the full root flow was not executed there. - The API 23 experiment exercised the Dirty COW page-cache write and payload from an already-rooted adb shell; it did not demonstrate app-only root. - `tests/verify_all_versions.sh` installs and launches the apps on its API 10, 15, and 19 emulator images. It does not run the exploit. The API 10 image separately inspected here could not be used for a full root-flow run because the emulator crashed during zygote prelinking. API 8 is not in that smoke-test matrix, so the declared minimum SDK is not proof of end-to-end Froyo support. ## References - CVE-2016-5195 writeup: https://dirtycow.ninja/ - timwr CVE-2016-5195 Android source: https://github.com/timwr/CVE-2016-5195 - AOSP `app_main.cpp`: https://android.googlesource.com/platform/frameworks/base/+/android-6.0.1_r81/cmds/app_process/app_main.cpp - SuperSU 2.46 package: `eu.chainfire.supersu`, versionCode 246, minSdk 7