Skip to main content
Be Bitwise

Android Security Model & Permissions

Android Internals · Mobile Internals track

6 min read

In this module

UID-Based Isolation

Android's bedrock security mechanism sounds almost too plain to work: every app is a separate Unix user. PackageManager hands out a unique Linux UID at install time, and the boring old Unix file permission system does the heavy lifting. An app's private files are owned by its own UID with modes that lock everyone else out.

bash
# App data directories show UID-based ownership
$ ls -la /data/data/
drwx------ u0_a127 u0_a127 com.example.banking
drwx------ u0_a198 u0_a198 com.example.messaging
drwx------ u0_a215 u0_a215 com.example.weather
# Each app's directory is accessible only to its own UID

The whole thing piggybacks on decades of battle-tested Unix semantics. The kernel's file permission checks are audited to death, broadly understood, and hardware-enforced. Apps don't need to trust a single line of framework code for basic file isolation. The kernel handles it.

SELinux: Mandatory Access Control

UID isolation keeps apps out of each other's files. It says nothing about what an app can do with the rest of the system. A compromised app, running happily as its own UID, can still poke at kernel interfaces, fiddle with system properties, or chat to privileged services.

SELinux is the second wall. Android has required it in enforcing mode since 5.0. The policy carves the system into well over a hundred security domains and hundreds of object types (the count grows with each release) and runs default-deny: nothing is allowed unless a rule says so.

SELinux on Android

SELinux layers mandatory access control (MAC) on top of Unix permissions, completely independent of them. Every process, file, socket, and service gets a security context (label). Policy rules say which contexts can talk to which. Even root (UID 0) plays by these rules — a root process in the wrong context still gets bounced from protected resources.

Every process lives in an SELinux domain. Every file, socket, and service wears a label. The policy spells out which domains can touch which labels and how — read, write, execute, bind, connect, the lot.

bash
# Checking SELinux context of a process
$ ps -Z | grep com.example
u:r:untrusted_app:s0:c127 u0_a127 com.example.myapp
# "untrusted_app" domain - heavily restricted
# System server runs in a privileged domain
$ ps -Z | grep system_server
u:r:system_server:s0 system system_server

The headline is that SELinux is orthogonal to Unix permissions. Hand an attacker UID 0 and SELinux still pins them down. A root process wearing an unprivileged label can't reach MAC-protected resources. That's why modern Android rooting has to tackle SELinux on top of getting UID 0 — UID 0 alone doesn't get you very far any more.

The Permission Model

Android's user-facing permission system gates access to sensitive resources — camera, mic, contacts, location, all the obvious targets. Permissions come in three protection levels (normal, dangerous and signature), and a fourth group of special permissions works differently: most of them are tracked as app-ops and granted from a settings screen rather than by protection level alone.

Normal Permissions

Low-risk stuff: internet access, setting wallpapers, making the phone buzz. Granted automatically at install, no dialog. These guard resources where the privacy or security risk is barely measurable.

Dangerous Permissions (Runtime Permissions)

Since 6.0, dangerous permissions are runtime-only. The app declares them in its manifest, then has to ask the user when it actually needs them. Users grant or deny each one on its own, and they can revoke any of them at any time from Settings.

java
// Requesting camera permission at runtime (Android 6.0+)
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.CAMERA) != PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.CAMERA},
REQUEST_CAMERA);
}

Dangerous permissions cover camera, mic, location, contacts, phone, SMS, storage, sensors. They live in groups, and historically granting one item in a group granted the whole group. Recent Android versions have tightened that behaviour.

Signature Permissions

Signature permissions are gated by signing certificate. Only apps signed with the same cert as the declaring app get them. This lets platform apps (signed with the platform key) share capabilities without leaking those capabilities to anything in Play Store.

Special Permissions

A handful of capabilities — drawing over other apps, editing system settings, device admin — are too sensitive to risk on a dialog tap. Apps have to send the user into a specific settings screen and ask them to flip the toggle by hand. They're worth knowing as an attacker: Android banking trojans routinely talk users into granting overlay and accessibility access, which lets them draw fake login screens and read or drive other apps.

Verified Boot

Verified Boot chains trust from the hardware root all the way to a running system. Each stage verifies the next before handing off:

  1. Hardware root of trust checks the bootloader.
  2. Bootloader checks the boot image (kernel + ramdisk).
  3. Kernel uses dm-verity to check the system and vendor partitions block by block.

dm-verity builds a Merkle hash tree over the whole system partition. Every block read at runtime is hashed and compared against the tree. Mess with a block on disk and the read fails. Persistent malware can't quietly patch system files; the next read tells on it.

Verified Boot and dm-verity

Verified Boot chains cryptographic trust from hardware through each boot stage to the running system. dm-verity does block-level integrity checks of the system partition, verifying every block at read time. Together they keep tampering visible, and they make persistent rootkits on the system partition impractical without unlocking the bootloader first.

UID isolation, SELinux, runtime permissions, and Verified Boot each guard against a different threat model. UID isolation locks apps out of each other's data. SELinux narrows what any one process can attempt. Runtime permissions hand users a kill switch on sensitive resources. Verified Boot keeps the OS itself honest. Pop one layer and the next is still standing.

iOS covers the same ground with different machinery. Open the Secure Boot row below in side-by-side view and the biggest gap is obvious: Android's bootloader can be unlocked on many devices, iOS's can't. The sandbox row sets UID isolation against Apple's container-and-entitlement model.

iOS vs Android Security Model