Post

Android Security Internals: Chapter 13 - System Updates and Root Access

A comprehensive technical conclusion analyzing Chapter 13 of Nikolay Elenkov's 'Android Security Internals', covering Recovery OS mechanics, OTA update verification, privilege escalation exploits, su daemons, Magisk systemless root, and KernelSU.

Hello everyone,

Welcome to the grand finale of our comprehensive book summary series covering “Android Security Internals: An In-Depth Guide to Android’s Security Architecture” by Nikolay Elenkov (No Starch Press), expanded with cutting-edge root architectures, Magisk internals, KernelSU, and Google Play Integrity attestation bypass research.

Over the preceding twelve chapters, we have analyzed Android from its deepest Linux kernel roots to its high-level application sandboxes. In this final installment, we explore Chapter 13: System Updates and Root Access, examining how the operating system patches itself over the air (OTA) and dissecting the engineering behind root access—the ultimate privilege escalation where an administrator or researcher reclaims total sovereignty over their physical hardware.

We will trace the boot sequence into the standalone Recovery OS, unpack the format and cryptographic verification of OTA update packages, review historical privilege escalation exploits, examine the four distinct eras of su binary architecture, and analyze the cat-and-mouse game between hardware attestation and modern root-hiding frameworks.

Android Security Internals Chapter 13


Series Navigation

Previous ChapterCurrent ChapterNext Chapter
Chapter 12: SELinux in AndroidChapter 13: System Updates and Root AccessEnd of Series

Key Takeaways

  • The Recovery OS: Android devices host two independent operating systems: the primary Android OS (in /boot) and a lightweight, UI-less maintenance environment (in /recovery).
  • Cryptographic OTA Verification: Over-The-Air (OTA) update packages are encrypted/signed ZIP archives. The recovery kernel validates the cryptographic signature against trusted public keys embedded in its ramdisk (/res/keys) before executing update scripts.
  • The Evolution of Rooting: Root access transitioned across four distinct technological eras: traditional SUID binaries (Android 1-4.2), daemonized su (Android 4.3-7.0), systemless root via Magisk (Android 8-13), and kernel-space rooting via KernelSU/APatch (Android 13+).
  • Magisk & Mount Namespaces: To bypass Verified Boot (dm-verity), Magisk leaves the physical /system partition untouched on flash, using Linux mount namespaces (CLONE_NEWNS) to dynamically overlay root binaries and modules into RAM.
  • Hardware Attestation & Play Integrity: Modern banking and enterprise applications evaluate device trust via Google’s Play Integrity API and hardware-backed key attestation, verifying bootloader locks directly with the Titan M/TEE enclave.

1. Android Boot Flow & The Recovery OS

When an Android device powers on, execution transitions through a verified hardware chain:

1
2
3
4
5
6
7
8
9
10
11
12
13
Application Processor Reset
          |
          v
Boot ROM (PBL - Primary Bootloader in silicon)
          |
          v
Secondary Bootloader (SBL / ABOOT / UEFI)
          |
          +---> Standard Boot: Loads /boot (Kernel + ramdisk) -> Starts /init
          |
          +---> Fastboot Mode: Hardware flash programmer interface
          |
          +---> Recovery Mode: Loads /recovery -> Starts /sbin/recovery

The Recovery Environment

The /recovery partition contains an entirely autonomous minimal Linux distribution:

  • A standalone Linux kernel.
  • A minimal root filesystem (ramdisk) containing standard toolbox binaries and the /sbin/recovery executable.
  • It does not launch Zygote, Dalvik/ART, or system_server.
  • Operates when the main /system or /data partitions are unmounted or corrupt, allowing factory wipes, emergency maintenance, and system firmware updates.

2. Anatomy of an Over-The-Air (OTA) Update Package

An Android OTA update is distributed as a signed ZIP archive containing:

1
2
3
4
5
6
7
8
9
ota_update.zip
├── boot.img                               (Updated kernel and ramdisk)
├── system/                                (Updated system binaries/frameworks)
├── META-INF/
│   ├── CERT.SF                            (Signature manifest)
│   ├── CERT.RSA                           (PKCS#7 signature block)
│   └── com/google/android/
│       ├── update-binary                  (Native C executable interpreter)
│       └── updater-script                 (Edify script containing installation instructions)

A/B Seamless Updates

In modern Android releases (Android 7.0+), Google introduced A/B Seamless Updates:

  • Two identical sets of partitions exist on disk: boot_a / boot_b, system_a / system_b.
  • The update is streamed in the background by update_engine directly into the inactive partition slot while the user uses the phone normally!
  • Upon reboot, the bootloader switches active slots. If the updated slot fails to boot, the bootloader rolls back to the previous slot automatically, eliminating device bricking!

3. The Four Eras of Android Root Access

The mechanics of obtaining administrative superuser privileges (UID 0) evolved dramatically in response to Android’s defense-in-depth mitigations:

The Evolution of Android Root Access

Era 1: The SUID Binary (Android 1.0 - 4.2)

  • A traditional setuid binary was installed at /system/xbin/su with permissions 04755 (-rwsr-xr-x).
  • Any app could spawn a root shell by executing Runtime.getRuntime().exec("su").
  • Broken By: Android 4.3 mounting /system with the nosuid mount flag!

Era 2: Daemonized su & SuperSU (Android 4.3 - 7.0)

  • With setuid binaries neutralized, developers created daemonSU.
  • A standing root daemon ran continuously in the background, launched during early boot by patching /init.rc.
  • A lightweight client /system/xbin/su communicated with the daemon over a local UNIX domain socket.
  • The daemon performed live in-memory patching of the kernel SELinux policy, injecting rules to grant the su domain unrestricted permissions.
  • Broken By: Android Verified Boot (dm-verity), which detected any byte modified on /system and prevented boot!

Era 3: Systemless Root & Magisk (Android 8.0 - 13.0)

  • Engineered by John Wu (topjohnwu), Magisk introduced Systemless Root:
  • Leaves /system completely untouched on physical flash to pass dm-verity hash tree checks.
  • Modifies only the /boot partition ramdisk to launch magiskd.
  • Utilizes Linux Mount Namespaces to transparently overlay root binaries, busybox tools, and custom modules into the root filesystem dynamically in RAM.
  • Zygisk: Injects code into the Zygote process, allowing modules to modify app behavior before sandbox privileges are dropped.

Era 4: Kernel-Space Root: KernelSU & APatch (Modern Android 13+)

  • Traditional userspace root frameworks are vulnerable to detection heuristics (inspecting /proc/mounts, checking for known package names, scanning /system/bin).
  • KernelSU: Integrates directly into custom Linux kernels.
  • Operates in Ring 0 (kernel space), intercepting the sys_execve() system call.
  • When an authorized application executes su, the kernel directly swaps the process credentials (uid = 0, gid = 0) inside task_struct and switches SELinux domains silently.
  • Zero files are placed on the Android filesystem, rendering the root access completely invisible to userspace security scans!

4. Root Detection & Hardware Attestation Bypasses

Enterprise banking and DRM applications deploy layered checks:

1
2
3
4
5
6
7
8
9
// Common Root Detection Heuristics
public static boolean isDeviceRooted() {
    return checkBuildTags() || checkSuBinaryPaths() || checkWhichSu() || checkMounts();
}

private static boolean checkBuildTags() {
    String buildTags = android.os.Build.TAGS;
    return buildTags != null && buildTags.contains("test-keys");
}

The Ultimate Frontier: Hardware-Backed Play Integrity

Google’s modern Play Integrity API evaluates device health against three tiers:

  1. MEETS_BASIC_INTEGRITY: Passes basic software-level checks.
  2. MEETS_DEVICE_INTEGRITY: Verifies bootloader locks and factory firmware.
  3. MEETS_STRONG_INTEGRITY: Evaluates a hardware cryptographic challenge signed directly by the Titan M / ARM TrustZone hardware key.

Bypassing MEETS_STRONG_INTEGRITY on an unlocked device requires hardware key extraction or exploiting the cryptographic attestation chain—a testament to how formidable Android’s modern hardware-anchored defense-in-depth architecture has become.


Series Retrospective: The Android Security Blueprint

Across this 13-chapter journey through Nikolay Elenkov’s “Android Security Internals”, we have analyzed the comprehensive architecture of the world’s most popular operating system:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
================================================================================
                       THE ANDROID SECURITY ARCHITECTURE
================================================================================
[Apps & Services]   Isolated UIDs (>=10000) | Runtime Permissions | URI Grants
--------------------------------------------------------------------------------
[Application Layer] system_server | AccountManager | DevicePolicyManager
--------------------------------------------------------------------------------
[Framework & IPC]   Binder Driver (/dev/binder) | Service Manager | Parcels
--------------------------------------------------------------------------------
[Security Enclaves] Android KeyStore | Keymaster HAL | StrongBox | ARM TrustZone
--------------------------------------------------------------------------------
[Mandatory Access]  SELinux (SEAndroid) | Type Enforcement | Treble Split Policy
--------------------------------------------------------------------------------
[Cryptographic Core]AndroidOpenSSL / BoringSSL | System CA Store | PKI Validation
--------------------------------------------------------------------------------
[Storage Integrity] File-Based Encryption (fscrypt) | Verified Boot (AVB 2.0)
--------------------------------------------------------------------------------
[Hardware Base]     Linux Kernel | Hardware TRNG | Chipset Security Fuses (eFuse)
================================================================================

Android’s architecture proves that mobile security cannot rely on a single defensive layer. True resilience requires Defense in Depth: sandboxing every app, authenticating every IPC call, cryptographically verifying every block on flash, and isolating private keys inside hardware enclaves.


References & Authoritative Reading

  1. Elenkov, Nikolay. Android Security Internals: An In-Depth Guide to Android’s Security Architecture. No Starch Press, 2015. Chapter 13: “System Updates and Root Access,” pp. 349–376.
  2. AOSP Documentation - OTA Update Architecture & System Updates
  3. Wu, John (topjohnwu). Magisk: The Magic Mask for Android - Architecture & Design. GitHub, 2016–2026.
  4. KernelSU Documentation - Kernel-based Root Solution for Android
  5. Google Play Integrity API Specification
  6. Drake, Joshua J., et al. Android Hacker’s Handbook. Wiley, 2014.

Complete Series Index


Let’s Connect

Thank you for following along with this exhaustive 13-part series on Android Security Internals! What was your favorite chapter, and what mobile security topic should we explore next?

Sadaqah Jariyah & Knowledge Sharing | صدقة جارية وعلم يُنتفع به

This technical content and everything shared across this blog is dedicated with sincere intention to serve as enduring, beneficial knowledge (علم يُنتفع به) and an ongoing charity (صدقة جارية). If you find value in this research, please remember me and my family in your sincere prayers.

This post is licensed under CC BY 4.0 by the author.