Skip to the content ForoHackers
Log inJoin

Android's app sandbox is just Linux users (and I think that is neat)

AndroidLinuxMobile security
#1199 · dual_boot_dani · · Report

Something that clicked for me while poking at my own test phone: on Android every installed app gets its own Linux user ID. The sandbox between apps is mostly the plain old Unix permission model, plus SELinux on top.

On a device you own with debugging enabled:

adb shell ls -ld /data/data/com.example.notes
# drwx------ 4 u0_a142 u0_a142 4096 ... /data/data/com.example.notes

u0_a142 is a user, created for that app. The directory is mode 700, so no other app (a different UID) can read it, and the kernel enforces that exactly like it does for two users on a desktop Linux.

This explains a lot: why apps need declared permissions to touch shared stuff, why an app cannot read another app's files without help, and why root on a phone is such a big deal (UID 0 ignores all of it).

Linux on the desktop, one human, many users in theory. Android: one human, many users in practice, each one an app.

Comparing notes with the iOS people: how does the other side do it?

#2100 · k3rn3l_k1tt3n · · Report

Kernel view: it is just uid/gid on each process and inode, and every app process is forked from a common parent (zygote) and then its UID is set. Fun to check with adb shell ps -A and look at the first column. Same kernel, same syscalls, different identity.

#2101 · ssh_tunnel_vision · · Report

Keep in mind what the sandbox does and does not do. It protects apps from each other. It does not protect you from the permissions you grant an app. "Allow access to contacts" is a decision, and the sandbox will faithfully enforce what you decided.

#2102 · spanglish_stacktrace · · Report

iOS did it differently pero con la misma idea: cada app vive en su propio container directory, y el kernel aplica un perfil de sandbox (MAC framework) que dice qué puede tocar. En lugar de usuarios Unix distintos por app, es una política más fina por proceso, firmada con entitlements. Same goal, different plumbing.

#2103 · dual_boot_dani · · Report

That is a great summary. So both end up at "a process gets an identity, and the OS decides what that identity can touch". Just one reuses an old Unix idea and the other adds a policy layer.

#2104 · hexdump_hermit · · Report

Check adb shell id on a stock device: you are shell, not root. Inspecting the sandbox is a good exercise precisely because you can see it hold.

Log in or join to reply.