# measured-binder-probe.txt # # Verbatim output of examples/binder-probe.c, captured on a physical device. # Device : Xiaomi M2101K6P (sweetin), arm64-v8a # Android : 11, API 30, security patch 2021-12-01 # Kernel : 4.14.180-perf # Caller : adb shell, uid 2000, SELinux u:r:shell:s0 # Date : captured while writing chapter 25 # # Nothing here is synthetic. Reproduce with the commands shown above each block. ================================================================ $ binder-probe ================================================================ binder-probe -- raw /dev/binder client real uid=2000 euid=2000 pid=3701 Binder device nodes visible to uid 2000: /dev/binder present=yes openable=yes /dev/hwbinder present=yes openable=yes /dev/vndbinder present=yes openable=no reason=Permission denied /dev/binderfs/binder present=yes openable=yes Structure sizes on this ABI: sizeof(binder_write_read) = 48 sizeof(binder_transaction_data) = 64 sizeof(flat_binder_object) = 24 sizeof(binder_uintptr_t) = 8 ioctl numbers as this build computes them: BINDER_WRITE_READ = 0xc0306201 BINDER_SET_MAX_THREADS = 0x40046205 BINDER_SET_CONTEXT_MGR = 0x40046207 BINDER_VERSION = 0xc0046209 Well-known transaction codes (ASCII packed big-endian): INTERFACE_TRANSACTION '_NTF' = 1598968902 (0x5f4e5446) DUMP_TRANSACTION '_DMP' = 1598311760 (0x5f444d50) SHELL_COMMAND_TRANSACTION '_CMD' = 1598246212 (0x5f434d44) PING_TRANSACTION '_PNG' = 1599098439 (0x5f504e47) SYSPROPS_TRANSACTION '_SPR' = 1599295570 (0x5f535052) Opening /dev/binder: protocol_version : 8 (8 = 64-bit driver, 7 = 32-bit) mmap size : 1040384 bytes (1016 KiB) at 0x752024b000 = 1 MiB - 2 pages; page size is 4096 ================================================================ $ binder-probe --getservice activity ================================================================ OUTGOING PARCEL for IServiceManager.checkService("activity") interface token : "android.os.IServiceManager" total data_size : 96 bytes raw bytes: 00000000: 00000000 ffffffff 54535953 1a000000 |........TSYS....| 00000010: 61006e00 64007200 6f006900 64002e00 |a.n.d.r.o.i.d...| 00000020: 6f007300 2e004900 53006500 72007600 |o.s...I.S.e.r.v.| 00000030: 69006300 65004d00 61006e00 61006700 |i.c.e.M.a.n.a.g.| 00000040: 65007200 00000000 08000000 61006300 |e.r.........a.c.| 00000050: 74006900 76006900 74007900 00000000 |t.i.v.i.t.y.....| Field walk: [0x00] int32 strict-mode policy = 0 [0x04] int32 work-source uid = -1 (unset) [0x08] int32 header 'SYST' = 0x53595354 [0x0c] str16 interface descriptor = "android.os.IServiceManager" [....] str16 argument = "activity" SENDING to handle 0, code 2 (checkService) ioctl round 1: write_consumed=68 read_consumed=76 <- BR_NOOP (0x0000720c) <- BR_TRANSACTION_COMPLETE (0x00007206) <- BR_REPLY (0x80407203) REPLY PARCEL data_size : 32 bytes offsets_size : 8 bytes (1 embedded object(s)) buffer : 0x7410502000 (inside our read-only mmap) raw bytes: 00000000: 00000000 852a6873 13010000 01000000 |.....*hs........| 00000010: 00000000 00000000 00000000 0c000000 |................| object[0] at parcel offset 4: type : 0x73682a85 BINDER_TYPE_HANDLE (remote ref) flags : 0x00000113 min-priority=19 ACCEPTS_FDS handle : 1 <-- OUR process's number for that remote object. It is meaningless in any other process. BC_FREE_BUFFER sent -- buffer returned to the driver ================================================================ $ binder-probe --call notification 2 # honest ================================================================ STEP 1 -- resolve "notification" through servicemanager handle = 1 STEP 2 -- ask handle 1 for its own interface descriptor ('_NTF') descriptor = "android.app.INotificationManager" STEP 3 -- send transaction code 2 with a correct interface token outgoing parcel (84 bytes): 00000000: 00000000 ffffffff 54535953 20000000 |........TSYS ...| 00000010: 61006e00 64007200 6f006900 64002e00 |a.n.d.r.o.i.d...| 00000020: 61007000 70002e00 49004e00 6f007400 |a.p.p...I.N.o.t.| 00000030: 69006600 69006300 61007400 69006f00 |i.f.i.c.a.t.i.o.| 00000040: 6e004d00 61006e00 61006700 65007200 |n.M.a.n.a.g.e.r.| 00000050: 00000000 |....| ioctl round 1: write_consumed=68 read_consumed=76 <- BR_NOOP (0x0000720c) <- BR_TRANSACTION_COMPLETE (0x00007206) <- BR_REPLY (0x80407203) REPLY PARCEL data_size : 1064 bytes offsets_size : 0 bytes (0 embedded object(s)) buffer : 0x7628252000 (inside our read-only mmap) raw bytes: 00000000: ffffffff 1c000000 44006900 73006100 |........D.i.s.a.| 00000010: 6c006c00 6f007700 65006400 20006300 |l.l.o.w.e.d. .c.| 00000020: 61006c00 6c002000 66006f00 72002000 |a.l.l. .f.o.r. .| 00000030: 75006900 64002000 32003000 30003000 |u.i.d. .2.0.0.0.| 00000040: 00000000 e4030000 ed010000 09006100 |..............a.| 00000050: 74002000 63006f00 6d002e00 61006e00 |t. .c.o.m...a.n.| 00000060: 64007200 6f006900 64002e00 73006500 |d.r.o.i.d...s.e.| 00000070: 72007600 65007200 2e006e00 6f007400 |r.v.e.r...n.o.t.| 00000080: 69006600 69006300 61007400 69006f00 |i.f.i.c.a.t.i.o.| 00000090: 6e002e00 4e006f00 74006900 66006900 |n...N.o.t.i.f.i.| 000000a0: 63006100 74006900 6f006e00 4d006100 |c.a.t.i.o.n.M.a.| 000000b0: 6e006100 67006500 72005300 65007200 |n.a.g.e.r.S.e.r.| 000000c0: 76006900 63006500 2e006300 68006500 |v.i.c.e...c.h.e.| 000000d0: 63006b00 43006100 6c006c00 65007200 |c.k.C.a.l.l.e.r.| 000000e0: 49007300 53007900 73007400 65006d00 |I.s.S.y.s.t.e.m.| 000000f0: 28004e00 6f007400 69006600 69006300 |(.N.o.t.i.f.i.c.| 00000100: 61007400 69006f00 6e004d00 61006e00 |a.t.i.o.n.M.a.n.| 00000110: 61006700 65007200 53006500 72007600 |a.g.e.r.S.e.r.v.| 00000120: 69006300 65002e00 6a006100 76006100 |i.c.e...j.a.v.a.| 00000130: 3a003800 36003800 33002900 0a000900 |:.8.6.8.3.).....| 00000140: 61007400 20006300 6f006d00 2e006100 |a.t. .c.o.m...a.| 00000150: 6e006400 72006f00 69006400 2e007300 |n.d.r.o.i.d...s.| 00000160: 65007200 76006500 72002e00 6e006f00 |e.r.v.e.r...n.o.| 00000170: 74006900 66006900 63006100 74006900 |t.i.f.i.c.a.t.i.| 00000180: 6f006e00 2e004e00 6f007400 69006600 |o.n...N.o.t.i.f.| 00000190: 69006300 61007400 69006f00 6e004d00 |i.c.a.t.i.o.n.M.| 000001a0: 61006e00 61006700 65007200 53006500 |a.n.a.g.e.r.S.e.| 000001b0: 72007600 69006300 65002e00 61006300 |r.v.i.c.e...a.c.| 000001c0: 63006500 73007300 24003400 35003000 |c.e.s.s.$.4.5.0.| 000001d0: 30002800 4e006f00 74006900 66006900 |0.(.N.o.t.i.f.i.| 000001e0: 63006100 74006900 6f006e00 4d006100 |c.a.t.i.o.n.M.a.| 000001f0: 6e006100 67006500 72005300 65007200 |n.a.g.e.r.S.e.r.| 00000200: 76006900 63006500 2e006a00 61007600 |v.i.c.e...j.a.v.| 00000210: 61003a00 33003100 30002900 0a000900 |a.:.3.1.0.).....| 00000220: 61007400 20006300 6f006d00 2e006100 |a.t. .c.o.m...a.| 00000230: 6e006400 72006f00 69006400 2e007300 |n.d.r.o.i.d...s.| 00000240: 65007200 76006500 72002e00 6e006f00 |e.r.v.e.r...n.o.| 00000250: 74006900 66006900 63006100 74006900 |t.i.f.i.c.a.t.i.| 00000260: 6f006e00 2e004e00 6f007400 69006600 |o.n...N.o.t.i.f.| 00000270: 69006300 61007400 69006f00 6e004d00 |i.c.a.t.i.o.n.M.| 00000280: 61006e00 61006700 65007200 53006500 |a.n.a.g.e.r.S.e.| 00000290: 72007600 69006300 65002400 31003000 |r.v.i.c.e.$.1.0.| 000002a0: 2e006300 6c006500 61007200 44006100 |..c.l.e.a.r.D.a.| 000002b0: 74006100 28004e00 6f007400 69006600 |t.a.(.N.o.t.i.f.| 000002c0: 69006300 61007400 69006f00 6e004d00 |i.c.a.t.i.o.n.M.| 000002d0: 61006e00 61006700 65007200 53006500 |a.n.a.g.e.r.S.e.| 000002e0: 72007600 69006300 65002e00 6a006100 |r.v.i.c.e...j.a.| 000002f0: 76006100 3a003300 37003000 33002900 |v.a.:.3.7.0.3.).| 00000300: 0a000900 61007400 20006100 6e006400 |....a.t. .a.n.d.| 00000310: 72006f00 69006400 2e006100 70007000 |r.o.i.d...a.p.p.| 00000320: 2e004900 4e006f00 74006900 66006900 |..I.N.o.t.i.f.i.| 00000330: 63006100 74006900 6f006e00 4d006100 |c.a.t.i.o.n.M.a.| 00000340: 6e006100 67006500 72002400 53007400 |n.a.g.e.r.$.S.t.| 00000350: 75006200 2e006f00 6e005400 72006100 |u.b...o.n.T.r.a.| 00000360: 6e007300 61006300 74002800 49004e00 |n.s.a.c.t.(.I.N.| 00000370: 6f007400 69006600 69006300 61007400 |o.t.i.f.i.c.a.t.| 00000380: 69006f00 6e004d00 61006e00 61006700 |i.o.n.M.a.n.a.g.| 00000390: 65007200 2e006a00 61007600 61003a00 |e.r...j.a.v.a.:.| 000003a0: 31003100 33003200 29000a00 09006100 |1.1.3.2.).....a.| 000003b0: 74002000 61006e00 64007200 6f006900 |t. .a.n.d.r.o.i.| 000003c0: 64002e00 6f007300 2e004200 69006e00 |d...o.s...B.i.n.| 000003d0: 64006500 72002e00 65007800 65006300 |d.e.r...e.x.e.c.| 000003e0: 54007200 61006e00 73006100 63007400 |T.r.a.n.s.a.c.t.| 000003f0: 49006e00 74006500 72006e00 61006c00 |I.n.t.e.r.n.a.l.| 00000400: 28004200 69006e00 64006500 72002e00 |(.B.i.n.d.e.r...| 00000410: 6a006100 76006100 3a003100 31003600 |j.a.v.a.:.1.1.6.| 00000420: 32002900 0a000000 |2.).....| BC_FREE_BUFFER sent -- buffer returned to the driver STEP 4 -- decode the reply's exception header exception code : -1 (SecurityException) message : "Disallowed call for uid 2000" >>> READ THAT MESSAGE. If it names a uid, that uid came from Binder.getCallingUid() on the SERVICE side, which the kernel filled in. It is what the driver believes, not what we claimed. ================================================================ $ binder-probe --call notification 2 --forge-uid 0 # claiming root ================================================================ STEP 3 -- send transaction code 2 with a correct interface token outgoing parcel (84 bytes): 00000000: 00000000 ffffffff 54535953 20000000 |........TSYS ...| 00000010: 61006e00 64007200 6f006900 64002e00 |a.n.d.r.o.i.d...| 00000020: 61007000 70002e00 49004e00 6f007400 |a.p.p...I.N.o.t.| 00000030: 69006600 69006300 61007400 69006f00 |i.f.i.c.a.t.i.o.| 00000040: 6e004d00 61006e00 61006700 65007200 |n.M.a.n.a.g.e.r.| 00000050: 00000000 |....| [forge] wrote sender_euid=0 sender_pid=1 into the outgoing binder_transaction_data before calling ioctl(). ioctl round 1: write_consumed=68 read_consumed=76 <- BR_NOOP (0x0000720c) <- BR_TRANSACTION_COMPLETE (0x00007206) <- BR_REPLY (0x80407203) REPLY PARCEL data_size : 1064 bytes offsets_size : 0 bytes (0 embedded object(s)) buffer : 0x719a84e000 (inside our read-only mmap) raw bytes: BC_FREE_BUFFER sent -- buffer returned to the driver STEP 4 -- decode the reply's exception header exception code : -1 (SecurityException) message : "Disallowed call for uid 2000" >>> READ THAT MESSAGE. If it names a uid, that uid came from Binder.getCallingUid() on the SERVICE side, which the kernel filled in. It is what the driver believes, not what we claimed. ---------------------------------------------------------- We wrote sender_euid=0 into the outgoing transaction. The receiver did not see it. binder_transaction() in drivers/android/binder.c overwrites both sender fields from the calling task's own kernel-held credentials before the target is ever woken up. The field exists in the struct only because the SAME struct is used for delivery, where the kernel fills it in. Run the same command WITHOUT --forge-uid and diff the output. They are identical. That is the proof. ---------------------------------------------------------- ================================================================ $ binder-probe --call notification 2 --forge-uid 1000 # claiming system ================================================================ [forge] wrote sender_euid=1000 sender_pid=1 into the outgoing exception code : -1 (SecurityException) message : "Disallowed call for uid 2000" ---------------------------------------------------------------- THE RESULT, STATED PLAINLY claimed uid 0 -> service replied "Disallowed call for uid 2000" claimed uid 1000 -> service replied "Disallowed call for uid 2000" claimed nothing -> service replied "Disallowed call for uid 2000" 2000 is the real uid of the adb shell process. The sender_euid field we filled in never reached the receiver. binder_transaction() in drivers/android/binder.c overwrites it from the calling task's own kernel-held credentials. ---------------------------------------------------------------- ================================================================ $ binder-probe --call notification 2 --token android.os.IServiceManager (correct code, correct handle, WRONG interface token) ================================================================ STEP 3 -- send transaction code 2 with a DELIBERATELY WRONG token the object says its interface is : "android.app.INotificationManager" we are claiming : "android.os.IServiceManager" The receiver's enforceInterface() compares the two strings and refuses on mismatch. That refusal is a SECURITY CONTROL, not a formality: it is what stops a parcel built for interface A from being reinterpreted, field by field, by interface B's reader. outgoing parcel (72 bytes): 00000000: 00000000 ffffffff 54535953 1a000000 |........TSYS....| 00000010: 61006e00 64007200 6f006900 64002e00 |a.n.d.r.o.i.d...| 00000020: 6f007300 2e004900 53006500 72007600 |o.s...I.S.e.r.v.| 00000030: 69006300 65004d00 61006e00 61006700 |i.c.e.M.a.n.a.g.| 00000040: 65007200 00000000 |e.r.....| ioctl round 1: write_consumed=68 read_consumed=76 <- BR_NOOP (0x0000720c) <- BR_TRANSACTION_COMPLETE (0x00007206) <- BR_REPLY (0x80407203) REPLY PARCEL data_size : 100 bytes offsets_size : 0 bytes (0 embedded object(s)) buffer : 0x766d58b000 (inside our read-only mmap) raw bytes: BC_FREE_BUFFER sent -- buffer returned to the driver STEP 4 -- decode the reply's exception header exception code : -1 (SecurityException) message : "Binder invocation to an incorrect interface" >>> READ THAT MESSAGE. If it names a uid, that uid came from Binder.getCallingUid() on the SERVICE side, which the kernel filled in. It is what the driver believes, not what we claimed.