Commit Graph

79 Commits

Author SHA1 Message Date
2468f5a6c4 Fix custom sepolicy patches 2020-04-22 23:01:11 -07:00
486b2c82a7 Disable kmsg rate limiting 2020-04-22 05:07:50 -07:00
c94f9e1cc9 Use a binary that exists on all devices for hijacking 2020-04-20 04:41:11 -07:00
e219867cdf Hijack another binary for 2nd stage
Instead of using ptrace hacks, use another hack instead :D
2020-04-19 22:15:12 -07:00
765d5d9729 Small magiskinit cleanup 2020-04-19 04:57:18 -07:00
dfbd1305b3 Android 11 support 🎉 2020-04-19 02:47:22 -07:00
4c959cd983 Support cases when /sbin does not exist 2020-04-18 23:19:19 -07:00
d959c35723 Make cleaner mount info 2020-04-18 18:50:25 -07:00
69a9d7485b Support injecting magisk bins 2020-04-18 05:15:59 -07:00
dcf07ad8c7 Directly filter '.' and '..' in xreaddir 2020-04-18 04:20:21 -07:00
e0a281583d Preparation for dynamic tmpfs path 2020-04-12 05:34:56 -07:00
2f1f68f12f Prepare compilation for NDK r21 2020-04-03 02:58:39 -07:00
834561a5de Content in dt_fstab is not null terminated in emulator
Value of <dt>/fstab/<partition>/dev and <dt>/fstab/<partition>/type in official Android emulator ends with newline instead of \0, Magisk won’t be able to patch sepolicy and crash the system.

Signed-off-by: Shaka Huang <shakalaca@gmail.com>
2020-04-02 20:54:41 -07:00
9820296e92 Update files.cpp in libutils 2020-04-02 02:17:45 -07:00
dbfde74c1e Clean rootfs in switch_root 2020-04-01 23:37:11 -07:00
b28668e18d Prevent possible race condition 2020-04-01 22:40:59 -07:00
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
543ce937ec Don't need to find system_dev 2020-03-31 22:41:25 -07:00
a0998009c1 Small native code reorganization 2020-03-09 01:50:30 -07:00
696ab677be New pre-init magic mount implementation 2020-02-21 00:49:58 -08:00
3b8ea599f0 Fix switch_root implementation 2020-02-20 21:08:59 -08:00
84e4bd3d41 Move readlinkat fix into xwrap 2020-02-03 13:24:02 +08:00
0ecfb63cd6 Fix crash during boot in x86 platform
readlinkat() may return random value instead of the number of bytes placed in buf and crashing the system in two ways:
1. segmentation fault (buf[-7633350] = ‘\0’)
2. wrong link of watchdogd, resulting dog timeout

Confirmed working in ZenFone 2 x86 series, may fix #2247 and #2356

Signed-off-by: Shaka Huang <shakalaca@gmail.com>
2020-02-03 13:02:30 +08:00
793f0b605c init: fix Tegra "APP" /system partition mounting
- thanks rootfan in https://github.com/topjohnwu/Magisk/issues/2063#issuecomment-573232567

Closes #2243
2020-02-01 01:09:12 +08:00
ba55e2bc32 Backup proper magiskinit in A-only 2SI 2020-01-22 05:12:04 +08:00
b39f407596 Load libsqlite dynamically 2020-01-11 03:20:59 +08:00
3a0e3c98f7 Minor adjustments to prevent crashes 2020-01-09 23:42:27 +08:00
fafa92d44b Simplify rootfs persist mount 2020-01-08 22:42:54 +08:00
b2cb2b8b75 Reduce socket name length
Some detectors simply ban long abstract sockets
2019-12-28 21:27:55 +08:00
4f4f54a059 Remove unused code 2019-12-13 08:31:24 -05:00
12fda29280 Add support for pre-init custom sepolicy patches
Close #1685
2019-12-13 06:05:12 -05:00
af060b3132 General QoL changes 2019-12-13 00:37:06 -05:00
8c500709e4 Remove SAR compatibility mode 2019-12-12 03:25:48 -05:00
08177c3dd8 Mount persist partition mirror pre-init 2019-12-09 04:09:23 -05:00
d22b9c26b6 Pull out common logic 2019-12-06 15:31:49 -05:00
4bb8ad19cf Small init refactoring 2019-12-06 12:02:34 -05:00
476b61c4c9 Support system_root with NVIDIA partition names
Fix #2063
2019-12-05 17:20:32 -05:00
8cc5f096a2 Some minor changes 2019-12-05 17:20:32 -05:00
276535dad6 Fix incorrect kmsg path
/proc/kmsg -> /dev/kmsg
2019-11-25 19:09:02 -05:00
7681fde4d0 Record mounts to be cleaned up in a vector 2019-11-19 00:16:20 -05:00
d3b7b41927 Fix kmsg logging in magiskinit 2019-11-18 17:18:56 -05:00
3c1db7d2f7 Fix some A/B devices unable to boot into recovery
Some newer recovery ramdisk no longer have /sbin/recovery.
Add /system/bin/recovery as an additional indication for recovery.

Close #1920
2019-10-26 17:12:35 -04:00
75306f658f Revert "Drop API 17 (Android 4.2) support"
Turns out that we cannot use AndroidKeystore anyways, so we don't
actually need to drop API 17. Revert this change.
2019-10-20 07:13:03 -04:00
9c27d691dd Drop API 17 (Android 4.2) support 2019-10-19 03:11:54 -04:00
947dae4900 Rename classes and small adjustments 2019-09-25 23:55:39 -04:00
748a35774f Support patching fstab in ramdisk for A-only 2SI 2019-09-22 05:30:04 -04:00
a52a3e38ed Change some class names 2019-09-22 05:20:51 -04:00
ee0cef06a6 Add support for A-only 2SI 2019-09-22 05:15:31 -04:00
17981730a4 Remove load_persist_props in post-fs-data
Close #1607
2019-09-17 13:50:53 -04:00
736729f5ef Maintain a list of pre-init mounts
Keep track of everything to unmount
2019-07-16 23:54:52 -07:00