Commit Graph
50 Commits
Author SHA1 Message Date
topjohnwu c9eac0c438 Introduce new sepolicy strategy for legacy devices
The existing sepolicy patching strategy looks like this:

1. 2SI: use LD_PRELOAD to hijack `security_load_policy`
2. Split policy: devices using split policy implies it also needs to
   do early mount, which means fstab is stored in device tree.
   So we do the following:
   - Hijack the fstab node in the device tree in sysfs
   - Wait for init to mount selinuxfs for us
   - Hijack selinuxfs to intercept sepolicy loading
3. Monolithic policy: directly patch `/sepolicy`

Method #1 and #2 both has the magiskinit pre-init daemon handling
the sepolicy patching and loading process, while method #3 gives us
zero control over sepolicy loading process. Downsides:

a. Pre-init daemon bypasses the need to guess which sepolicy init
   will load, because the original init will literally send the stock
   sepolicy file directly to us with this approach.
b. If we want to add more features/functionalities during the sepolicy
   patching process, we will leave out devices using method #3

In order to solve these issues, we completely redesign the sepolicy
patching strategy for non-2SI devices. Instead of limiting usage of
pre-init daemon to early mount devices, we always intercept the
sepolicy loading process regardless of the Android version and device
setup. This will give us a unified implementation for sepolicy patching,
and will make it easier to develop further new features down the line.
2025-02-28 09:39:10 -08:00
topjohnwu b6b34f7612 Fix overlay.d context preservation 2025-02-27 01:57:25 -08:00
topjohnwu 3c7c46307a Partially cleanup MagiskInit code 2025-02-15 18:27:45 -08:00
LoveSy 823e31a91b Use linker to link vfprintf as tiny_vfprintf 2025-02-14 14:24:13 -08:00
LoveSy 143743d0b0 Refactor init.cpp to init.rs 2025-02-14 14:24:13 -08:00
LoveSy d203a6fff6 Move MagiskInit to rust 2025-02-14 14:24:13 -08:00
LoveSy aae5b466fb Use rust to implement collect/reset overlay context 2024-12-27 12:35:29 -08:00
5ec1cff 2b7be8b949 init: reset overlay.d files context after sepolicy loaded 2024-12-27 12:35:29 -08:00
topjohnwu 3c6889505b Stop using polymorphism in magiskinit 2024-12-03 02:18:22 -08:00
LoveSy 55e78a7b1a BYD XDJA container support 2024-08-19 17:50:16 -07:00
topjohnwu 33aebb5976 Stop embedding executables 2024-07-24 22:49:48 -07:00
topjohnwu fb5ee86615 Install one single ABI in ramdisk 2024-03-31 22:01:22 -07:00
vvb2060 10069215f4 Rename dir name 2024-03-19 23:21:41 -07:00
canyie f00408c793 Fix zygote restart monitor 2024-03-06 01:39:16 -08:00
topjohnwu 625a1d6f44 Remove seek support from streams 2024-02-28 11:07:53 -08:00
topjohnwu be433fa667 Use Rust for formatting
The fprintf implementation included in crt0 is too rudimental
2024-02-26 00:26:23 -08:00
topjohnwu db99caf258 Use execve directly 2024-02-24 01:47:11 -08:00
LoveSy df66458db6 Check full path of init.rc instead of its dir
Some devices has `/system/etc/init/hw` but has no init.rc in it.
2024-01-11 16:18:57 -08:00
topjohnwu 65c18f9c09 Restructure project files 2023-11-08 01:46:02 -08:00
LoveSy 42eb928054 Inject zygisk.rc for sync --zygisk-restart 2023-11-06 15:39:48 -08:00
topjohnwu 66788dc58c Cleanup SELinux support 2023-10-16 17:38:44 -07:00
topjohnwu e774408782 Allow AVD hacks on release builds 2023-10-11 14:17:31 -07:00
topjohnwu 46275b90c2 Generalize unxz 2023-09-21 05:47:21 -07:00
topjohnwu d7d0a44693 Remove randomness from Magisk 2023-06-14 17:05:49 -07:00
topjohnwu 5e2ef1b7f4 Better bytes support in C++ 2023-06-06 17:11:42 -07:00
topjohnwu 2a654e5d7f Improve byte_data const correctness 2023-06-03 03:16:03 -07:00
vvb2060andLoveSy f9d22cf8ee New magisk tmp dir: /debug_ramdisk
Co-authored-by: LoveSy <shana@zju.edu.cn>
2023-05-06 00:04:11 -07:00
vvb2060 ee50da566f Cancel recursive bind 2023-05-06 00:04:11 -07:00
vvb2060 9f7d410959 Use pathname local socket 2023-05-06 00:04:11 -07:00
topjohnwu b136aba1e2 Implement magiskinit logging in Rust 2023-05-02 16:49:43 -07:00
topjohnwu 0cf0d2b821 Move avd_hack boolean out of init class 2023-04-25 23:34:45 -07:00
vvb2060 68c2817d40 Enable avd hack for debug build 2023-04-25 23:00:59 -07:00
topjohnwu cc5ff36165 Revert "Cancel recursive bind"
This reverts commit a18a440236.
2023-04-05 10:47:13 -07:00
vvb2060 5c165c9bb0 Fix avd hack 2023-04-05 04:01:32 -07:00
vvb2060 69529ac59c Fix restorecon 2023-04-04 02:34:16 -07:00
vvb2060 a18a440236 Cancel recursive bind 2023-04-04 02:12:07 -07:00
LoveSy aa7846c1c0 No need to mount ROOTMIR if tmp_dir != /sbin 2023-04-04 02:12:07 -07:00
topjohnwu 2087e47300 Get random separately 2023-04-03 18:32:11 -07:00
vvb2060 46ce765860 Use stable random seed 2023-04-03 18:32:11 -07:00
LoveSy dba5020e4f Refactor magiskrc 2023-03-22 17:53:15 -07:00
LoveSy b9d0a3b3d4 Use partition name or devpath's name 2023-03-21 00:40:11 -07:00
topjohnwu 4e2b88b3d0 Rename rules to preinit
It is possible that we will allow more preinit files for modules.
Rename the partition and folders from rules to preinit.
2023-03-21 00:40:11 -07:00
vvb2060andLoveSy 362eea741f Refactor sepolicy.rules resolve native
Co-authored-by: LoveSy <shana@zju.edu.cn>
2023-03-21 00:40:11 -07:00
LoveSyandtopjohnwu 9e8c68af12 Refactor sepolicy.rules resolve
We resolve available partitions for sepolicy.rules when patching
boot and bind mount the partition by magiskinit.

For older devices, the previous logic won't work because the part name
is never readable.

Co-authored-by: topjohnwu <topjohnwu@gmail.com>
2023-02-12 00:36:38 -08:00
vvb2060 7a9e6d2ad2 Remove unexpected /sbin/overlay.d 2023-02-09 20:08:59 -08:00
topjohnwu 57d83635c6 Check stub.xz existence 2022-12-26 16:07:04 -08:00
vvb2060 ad0e6511e1 Stop embedding stub.apk in magiskinit 2022-12-26 16:07:04 -08:00
LoveSyandtopjohnwu 5763a3d908 Support replacing existing .rc by overlay.d
Co-authored-by: topjohnwu <topjohnwu@gmail.com>
2022-12-26 03:28:10 -08:00
LoveSy 4ed34cd648 Eliminate unnecessarily copy on magiskinit
This patch reuses the abused /data tmpfs for magisktmp
2022-12-23 17:03:16 -08:00
topjohnwu b9e89a1a2d Restructure the native module
Consolidate all code into the src folder
2022-07-23 13:51:56 -07:00