Commit Graph

136 Commits

Author SHA1 Message Date
topjohnwu d4a0286e13 Migrate magiskinit selinux.cpp to Rust 2025-04-08 02:33:52 -07:00
topjohnwu 50af14f2a3 Move all MagiskInit entrypoints into init.rs 2025-03-24 17:26:03 -07:00
topjohnwu e0a356b319 Introduce mount helper methods 2025-03-24 17:26:03 -07:00
topjohnwu c09a792958 Reorganize magiskinit code 2025-03-24 17:26:03 -07:00
topjohnwu 0bbfe7f44d Fix 2SI on legacy SAR devices 2025-03-24 17:26:03 -07:00
topjohnwu 6ff82c4e86 Introduce FsPathFollow
Make sure all operations of FsPath do not follow symlinks, and provide
a way to explicitly switch over to a set of operations that DO follow
symlinks by FsPath::follow_link.
2025-03-07 15:51:51 -08:00
LoveSy c64de35375 Move magiskpolicy cli to argh 2025-03-07 14:29:30 -08:00
topjohnwu c90e73ccec Migration to Edition 2024 2025-03-07 02:35:25 -08:00
topjohnwu a43c1267d8 Update Cargo.toml 2025-03-07 02:35:25 -08:00
topjohnwu c6c1a17ae6 Address several clippy warnings 2025-03-03 02:15:14 -08:00
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 363410e1c0 Introduce cstr_buf helper functions 2025-02-17 11:32:21 -08:00
topjohnwu fc2ef21660 Introduce path! macro for FsPath 2025-02-17 01:46:19 -08:00
topjohnwu 3c7c46307a Partially cleanup MagiskInit code 2025-02-15 18:27:45 -08:00
LoveSy 9a74e19117 Add log_ok() for log().ok() 2025-02-14 14:24:13 -08:00
LoveSy b1e17706a4 Format code 2025-02-14 14:24:13 -08:00
LoveSy caad129d69 Move MagiskInit::patch_sepolicy to rust 2025-02-14 14:24:13 -08:00
LoveSy da58571ce5 Remove redundant rust export 2025-02-14 14:24:13 -08:00
LoveSy 2aa7f1c094 Move MagiskInit::check_two_stage to rust 2025-02-14 14:24:13 -08:00
LoveSy 823e31a91b Use linker to link vfprintf as tiny_vfprintf 2025-02-14 14:24:13 -08:00
LoveSy fb926ae302 Move MagiskInit::redirect_second_stage to rust 2025-02-14 14:24:13 -08:00
LoveSy e0489eeffd Move MagiskInit::first_stage to rust 2025-02-14 14:24:13 -08:00
LoveSy dc9d5a4cac Move MagiskInit::second_stage to rust 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 563f0d5ad5 Move BootConfig::print to rust 2025-02-14 14:24:13 -08:00
LoveSy c99f4a591b Move MagiskInit::exec_init to rust 2025-02-14 14:24:13 -08:00
LoveSy 449204e380 Move MagiskInit::prepare_data to rust 2025-02-14 14:24:13 -08:00
LoveSy a85c4c6528 Move MagiskInit::MagiskInit to rust 2025-02-14 14:24:13 -08:00
LoveSy d203a6fff6 Move MagiskInit to rust 2025-02-14 14:24:13 -08:00
LoveSy 6c612d66d7 Move BootConfig to rust 2025-02-14 14:24:13 -08:00
topjohnwu b7ca73f431 Remove an additional unique_ptr indirection 2025-02-05 14:18:16 +08:00
LoveSy 3981c9665e Replace rust inner functions to try blocks 2025-02-02 22:09:55 +08:00
topjohnwu ee6810f417 Rewrite magisk logging implementation 2025-01-11 00:11:48 +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 2654382c43 Address clippy warnings 2024-12-09 18:26:39 -08:00
vvb2060 4fb539c110 core: use a new tmpfs as worker 2024-12-06 02:19:43 -08:00
topjohnwu 3c6889505b Stop using polymorphism in magiskinit 2024-12-03 02:18:22 -08:00
topjohnwu c8e9ce7627 Cleanup mount code in magiskinit 2024-12-03 02:18:22 -08:00
vvb2060 830fc758b9 init: Use apex dir to determine whether 2SI 2024-11-30 23:03:29 -08:00
vvb2060 0f3cfef278 Revert "init: support 2SI devices with skip_initramfs"
This reverts commit b38fd1ca5f.
2024-11-30 23:03:29 -08:00
topjohnwu 8086b5933c Update crt0
Fix #8424
2024-10-02 16:37:07 -07:00
Wang Han 7af273e047 Don't append "start logd" in post-fs-data
This was first done in b13eb3f because magiskd was started in
post-fs stage that time. Among all android versions, logd was all
started before post-fs-data.
2024-09-16 00:30:36 -07:00
vvb2060 b38fd1ca5f init: support 2SI devices with skip_initramfs 2024-09-03 16:33:57 -07:00
LoveSy 55e78a7b1a BYD XDJA container support 2024-08-19 17:50:16 -07:00
LoveSy e9e2ecf2dd load partition_map only once 2024-08-15 10:10:18 -07:00
LoveSy 9a9e617c35 Use find_if 2024-08-15 10:10:18 -07:00
LoveSy 3a0becc783 Use parse_impl for partition_map 2024-08-15 10:10:18 -07:00
ChsBuffer 1f974cb220 Use androidboot.partition_map as a fallback for matching partition names in the preinit finding. 2024-08-15 10:10:18 -07:00