Magisk/native/jni
topjohnwu 5f1174de27 Introduce new boot flow to handle SAR 2SI
The existing method for handling legacy SAR is:
1. Mount /sbin tmpfs overlay
2. Dump all patched/new files into /sbin
3. Magic mount root dir and re-exec patched stock init

With Android 11 removing the /sbin folder, it is quite obvious that
things completely break down right in step 1.

To overcome this issue, we have to find a way to swap out the init
binary AFTER we re-exec stock init. This is where 2SI comes to rescue!

2SI normal boot procedure is:
1st stage -> Load sepolicy -> 2nd stage -> boot continue...

2SI Magisk boot procedure is:
MagiskInit 1st stage -> Stock 1st stage -> MagiskInit 2nd Stage ->
-> Stock init load sepolicy -> Stock 2nd stage -> boot continue...

As you can see, the trick is to make stock 1st stage init re-exec back
into MagiskInit so we can do our setup. This is possible by manipulating
some ramdisk files on initramfs based 2SI devices (old ass non SAR
devices AND super modern devices like Pixel 3/4), but not possible
on device that are stuck using legacy SAR (device that are not that
modern but not too old, like Pixel 1/2. Fucking Google logic!!)

This commit introduces a new way to intercept stock init re-exec flow:
ptrace init with forked tracer, monitor PTRACE_EVENT_EXEC, then swap
out the init file with bind mounts right before execv returns!

Going through this flow however will lose some necessary backup files,
so some bookkeeping has to be done by making the tracer hold these
files in memory and act as a daemon. 2nd stage MagiskInit will ack the
daemon to release these files at the correct time.

It just works™  ¯\_(ツ)_/¯
2020-04-01 04:39:28 -07:00
..
core core: clean up /data/adb/magisk.img, etc. as well 2020-03-26 03:39:49 -07:00
external Update busybox 2020-02-07 21:57:26 -08:00
include Make version reporting consistent 2020-03-23 01:17:13 -07:00
init Introduce new boot flow to handle SAR 2SI 2020-04-01 04:39:28 -07:00
magiskboot Make version reporting consistent 2020-03-23 01:17:13 -07:00
magiskhide Make version reporting consistent 2020-03-23 01:17:13 -07:00
magiskpolicy Make version reporting consistent 2020-03-23 01:17:13 -07:00
resetprop Make version reporting consistent 2020-03-23 01:17:13 -07:00
su Make version reporting consistent 2020-03-23 01:17:13 -07:00
systemproperties Small native code reorganization 2020-03-09 01:50:30 -07:00
utils Introduce new boot flow to handle SAR 2SI 2020-04-01 04:39:28 -07:00
.gitignore Add entrypoint to build test 2019-04-01 02:46:09 -04:00
Android.mk Introduce new boot flow to handle SAR 2SI 2020-04-01 04:39:28 -07:00
Application.mk Fix build on Windows 2020-01-26 12:27:07 +08:00