Binder IPC & System Services
Android Internals · Mobile Internals track
6 min read
In this module
Why Binder Exists
Android is service-oriented to the bone. Take a photo? You're calling the Camera Service. Check a permission? PackageManager. Pop a notification? NotificationManager. Each of these is a process hop — your app sits in one process and the system service lives in another (almost always system_server).
Plain Unix IPC — pipes, sockets, shared memory — was never going to cut it. Android wanted object-oriented remote calls, identity-based access control, and IPC fast enough for hundreds of round-trips a second. Binder is the answer. It's a kernel driver hanging off /dev/binder, designed end-to-end for Android's particular needs. Since Android 8.0 there are actually three Binder device nodes, each a separate domain with its own context manager: /dev/binder for the framework and apps, /dev/hwbinder for HIDL HALs, and /dev/vndbinder for vendor processes talking among themselves.
How Binder Works
Binder is a client-server model with the kernel driver sitting in the middle. The atomic operation is a transaction: client posts a request to the driver, driver hands it to the server, server replies back through the driver.
The UID stamp is the part that makes Binder a security boundary. The client never supplies its own identity: the driver reads it from the kernel's record of the calling process, which is why a service can trust getCallingUid() and can't trust a UID passed as an argument.
Step by step:
- The client builds a Parcel — a flat serialisation buffer with the method name, arguments, and any object references.
- The client fires an
ioctl()on/dev/bindercarrying the transaction data. - The driver copies the data into the server's address space, using memory-mapped pages so the copy happens once instead of twice.
- A server thread wakes up and reads the transaction off its queue.
- The server runs the method and writes its reply into a response Parcel.
- The driver hands the reply back to the original client.
// High-level Binder transaction (Java layer)// Behind the scenes, this becomes an ioctl to /dev/binderIBinder service = ServiceManager.getService("clipboard");Parcel data = Parcel.obtain();Parcel reply = Parcel.obtain();data.writeInterfaceToken("android.content.IClipboard");data.writeString("text to copy");service.transact(SET_PRIMARY_CLIP, data, reply, 0);reply.readException();Parcel Serialisation
Parcels are how Binder serialises everything. A Parcel is a flat buffer you can stuff with primitives and Binder object references. The shopping list:
- Primitives: ints, longs, floats, strings, byte arrays.
- Binder references: pointers to other Binder objects. The kernel rewrites them as it crosses address spaces.
- File descriptors: the kernel
dups these across the process boundary. - Parcelables: bigger objects that implement the
Parcelableinterface and serialise themselves.
Parcels are Binder's serialisation format, and they're a hall of fame for Android bugs. Whenever a system service deserialises attacker-controlled Parcel data, every type confusion, buffer overflow, or logic flaw in the parsing code is a privilege-escalation candidate. Several critical Android CVEs come down to a writer and a reader disagreeing about a Parcel's layout.
The ServiceManager
Android's ServiceManager is Binder's name server. System services register themselves with it at boot, and clients look services up by name later. ServiceManager is itself a Binder service. It's the one whose Binder handle (handle 0) every process already knows.
# Listing registered Binder services$ service list0 ServiceManager1 activity: [android.app.IActivityManager]2 package: [android.content.pm.IPackageManager]3 window: [android.view.IWindowManager]4 clipboard: [android.content.IClipboard]...When an app calls getSystemService(Context.CLIPBOARD_SERVICE), the framework:
- Asks ServiceManager for the "clipboard" service.
- Gets back a Binder proxy — a local object that forwards calls through the driver.
- Calls methods on the proxy, which become Binder transactions aimed at the real ClipboardService inside system_server.
Binder Security: Unforgeable Identity
Binder's flagship security property is unforgeable caller identity. The kernel driver stamps every transaction with the caller's UID and PID. On the server side, you get them via Binder.getCallingUid() and Binder.getCallingPid().
The kernel sets these. Userspace can't lie about them. System services lean on this guarantee to decide who's allowed to call what:
// Server-side permission check using Binder caller identity@Overridepublic void setPrimaryClip(ClipData clip) { int callingUid = Binder.getCallingUid(); // Check if the caller has the required permission if (mContext.checkPermission( WRITE_CLIPBOARD, Binder.getCallingPid(), callingUid) != PERMISSION_GRANTED) { throw new SecurityException("Permission denied"); } // ... proceed with operation}Network IPC has no such guarantee — a peer can claim any identity it likes. Binder permission enforcement leans entirely on the kernel's promise that UID/PID stamps are authentic.
Binder as Attack Surface
Even with the security design, Binder is a meaty attack surface:
- Parcel deserialisation: system services routinely parse Parcel data they didn't write. Type confusion, out-of-bounds reads and writes, and mismatched read/write logic between a Parcelable's writer and reader have all turned into privilege escalation here.
- Transaction handling: the driver itself parses complex transaction data inside the kernel. A bug in the driver hits every process on the device.
- Interface complexity: hundreds of Binder interfaces, each with its own methods and argument shapes. Auditing every code path end-to-end is wishful thinking.
A Binder bug inside a system service is gold to an attacker. system_server runs hot, with serious privileges, so a Parcel deserialisation bug in the right place takes you from an unprivileged app to system-level execution in one hop, leaving UID isolation and most SELinux policy in the dust.