I've read in another answer that on Android the su
binaries avoid needing to be setuid
by using filesystem capabilities like cap_setuid
. But then I tried to check this, and to my surprise, I found no capabilities set on my Magisk-enabled Android 8.0 system.
Here's how I checked:
- Logged in via SimpleSSHD
scp
'ed the following binaries taken from Debian arm64 packageslibcap2
,libcap2-bin
andlibc6
:getcap
libc.so.6
libcap.so.2.25
libcap.so.2
ld-2.27.so
- Had the following terminal session on the phone:
$ su
# whoami
root
# exit
$ type su
su is /sbin/su
$ ls -lh /sbin/su
lrwxrwxrwx 1 root root 12 2018-08-12 22:40 /sbin/su -> /sbin/magisk
$ ls -lh /sbin/magisk
-rwxr-xr-x 1 root root 94 2018-08-12 22:40 /sbin/magisk
$ sed 's@^@> @' /sbin/magisk
> #!/system/bin/sh
> unset LD_LIBRARY_PATH
> unset LD_PRELOAD
> exec /sbin/magisk.bin "${0##*/}" "$@"
$ ls -lh /sbin/magisk.bin
-rwxr-xr-x 1 root root 71K 2018-08-12 22:40 /sbin/magisk.bin
$ file /sbin/magisk.bin
/sbin/magisk.bin: ELF shared object, 32-bit LSB arm, dynamic (/system/bin/linker), stripped
$ LD_LIBRARY_PATH=. ./ld-2.27.so ./getcap -v /sbin/magisk.bin
/sbin/magisk.bin
As you can see, neither setuid
bit, nor any capabilities are present in the /sbin/magisk.bin
binary. So what's going on? How does it work?