Commit Graph

1102 Commits

Author SHA1 Message Date
topjohnwu
0a28dfe1e2 AVB blobs expect to be 4096-byte aligned 2021-11-28 13:21:05 -08:00
topjohnwu
228570640e Introduce KEEPVBMETAFLAG env variable
Close #4447, close #4906, close #4901, close #4964
2021-11-23 22:14:12 -08:00
topjohnwu
65a79610aa Fix crash and warnings 2021-11-23 18:46:06 -08:00
topjohnwu
24984ea4f2 Optimize stream for full-file writes 2021-11-23 18:08:14 -08:00
topjohnwu
048b2af0fc Improve zopfli encoder
Write in chunks for CLI compression
2021-11-23 16:50:08 -08:00
topjohnwu
449989ddd9 Always use zopfli for zImage compression 2021-11-23 14:24:05 -08:00
topjohnwu
01ebe5724a Cleanup zImage parsing code 2021-11-23 13:39:15 -08:00
topjohnwu
95fb230b8c Update to BusyBox 1.34.1 2021-11-22 19:46:52 -08:00
topjohnwu
632971af15 Properly support v4 image headers 2021-11-21 06:07:21 -08:00
topjohnwu
5787aa1078 Stream should always write all bytes 2021-11-21 06:05:59 -08:00
topjohnwu
d8b9265484 Pull out buffer-chunk logic into separate class 2021-11-21 06:05:55 -08:00
topjohnwu
9ea3169ca9 Do not allow modifying page sizes 2021-11-20 22:51:22 -08:00
topjohnwu
aebf2672cd Fix unpacking vendor boot images 2021-11-20 22:44:38 -08:00
topjohnwu
fef44bd24f Allow boot scripts to know Zygisk status 2021-11-20 13:05:15 -08:00
topjohnwu
4dfb193d10 Always run non disabled module post-fs-data scripts 2021-11-16 21:29:13 -08:00
vvb2060
d4ac458d17 Ignore zygisk modules when zygisk is not enabled 2021-11-16 21:14:35 -08:00
topjohnwu
e1b63d7dec Initialize mt19937 statically in function
This reduces startup time
2021-11-16 03:20:07 -08:00
topjohnwu
4b5651bd6f Revert logging after pre specialize 2021-11-16 03:12:01 -08:00
topjohnwu
50515d9128 Close unclosed fds from modules 2021-11-16 01:59:45 -08:00
topjohnwu
6935033db5 Prevent dangling pointers 2021-11-12 02:02:05 -08:00
topjohnwu
421277d730 Prevent race conditions in connect_companion 2021-11-12 01:55:55 -08:00
topjohnwu
56988944b5 No need to dup fd 2021-11-12 01:54:48 -08:00
topjohnwu
528601d25a Fix integer overflow and workaround seccomp
- Use ftruncate64 instead of ftruncate to workaround seccomp
- Cast uint32_t to off64_t before making it negative

Note: Using ftruncate with a modern NDK libc should actually be
fine as the syscall wrapper in bionic will use ftruncate64 internally.
However, since we are using the libc.a from r10e built for Gingerbread,
seccomp wasn't a thing back then, and also the ftruncate64 symbol is
missing; we have to create our own wrapper and call it instead on
32-bit ABIs.

Props to @jnotuo for discovering the overflow bug and seccomp issue

Fix #3703, close #4915
2021-11-10 03:07:20 -08:00
topjohnwu
b8c1588284 Always unload zygisk after specialize 2021-11-07 13:05:44 -08:00
Chaosmaster
16322ab30c Use full gzip-signature to find gzip-data.
Fall back to raw image if gzip is not found.

Fixes #4849
2021-11-03 22:23:21 -07:00
Chaosmaster
5682917356 Speed up zopfli compression
See #4810 for example
2021-11-03 22:22:29 -07:00
LoveSy
c91ccc8b4e Fix UB on dtb
`operator==` of string_view will create a tmp `string_view`.
It's an UB if the `const char *` is a nullptr.
`fdt_get_name` however will return a nullptr.
2021-11-03 22:21:48 -07:00
topjohnwu
63f670fc36 Move first stage unload before fork 2021-11-02 21:53:33 -07:00
LoveSy
e20b07fa24 Fix #4853 2021-11-02 19:31:17 -07:00
topjohnwu
d232cba02d Fix first stage unload 2021-11-02 04:12:56 -07:00
topjohnwu
48df6b8485 Use memmem instead of strstr
It might not be null terminated
2021-10-31 11:46:56 -07:00
Nullptr
e34e04af04 Make Api functions inline
Make Api functions inline to avoid duplicate symbols when including api.hpp in multiple cpps
2021-10-31 10:55:41 -07:00
topjohnwu
84e19ceef0 Tidy up bootimg.h
Close #4796
2021-10-31 10:52:12 -07:00
Chris Renshaw
59161efd08 Support Samsung 2SI with skip_initramfs in dtb cmdline
Samsung Galaxy A21S and Galaxy M12, probably others, are hdr_v2 boot.img with 2SI judging by the ramdisk contents, but the dtb contains an extra cmdline with skip_initramfs present, even though this shouldn't exist on 2SI and the kernel apparently doesn't even contain a skip_initramfs function

I can't find examples of other devices where skip_initramfs is present in the dtb other than these so patch it out like we do the kernel

Co-authored-by: topjohnwu <topjohnwu@gmail.com>
2021-10-30 21:20:10 -07:00
Chris Renshaw
6663fd3526
Support custom legacy Sony devices with init.real setup
Custom ROM bring-ups of legacy Sony devices contain the following:
/init (symlink to /bin/init_sony)
/init.real (the "real" Android init)
/bin/init_sony (this was /sbin/init_sony on Android <11)

Kernel loads the ramdisk and starts /init -> /bin/init_sony
/bin/init_sony does low-level device setup (see: https://github.com/LineageOS/android_device_sony_common/blob/lineage-18.1/init/init_main.cpp)
/bin/init_sony unlinks /init and renames /init.real to /init
/bin/init_sony starts /init

Since init_sony needs to run first magiskinit needs to replace init.real instead, so add workarounds based on detection of init.real to boot patcher and uninstaller

Thanks @115ek and @bleckdeth

Fixes #3636

Co-authored-by: topjohnwu <topjohnwu@gmail.com>
2021-10-30 18:59:20 -07:00
topjohnwu
2c44e1bb93 Update rules again 2021-10-29 03:37:14 -07:00
残页
e3f6399473 Don't use xwrite() when patching legacy rootfs init
Fix topjohnwu#4810
> [    2.927463]  [1:           init:    1] magiskinit: Replace [/system/etc/selinux/plat_sepolicy.cil] -> [xxx]
[    2.936801]  [1:           init:    1] magiskinit: write failed with 14: Bad address

Since topjohnwu#4596, magisk fails to patch `/init`, xwrite() fails with EFAULT, break the original `/init` file and make the device unbootable. Reverting this commit for legacy rootfs devices fixes the problem. I think this is a Samsung kernel magic since currently I can't reproduce this on other devices or find something special in the log currently we have.
2021-10-29 03:23:34 -07:00
残页
89c2c21774
Fix init.rc path detection
Fix #4319
Some devices store init.rc into the new path but still have the legacy /init.rc file
2021-10-29 03:21:20 -07:00
残页
a170acb9d7 Fix compilation when init debug toggle enabled 2021-10-29 03:15:16 -07:00
vvb2060
6a086bb222 Load *_compat_cil_file from system_ext
https://android-review.googlesource.com/c/platform/system/core/+/1650271
2021-10-29 03:14:26 -07:00
vvb2060
b2f152e641 realpath /proc/pid/cwd
prevent cross mount namespace
2021-10-29 03:13:20 -07:00
topjohnwu
6c5b261804 Update spolicy rules 2021-10-29 03:12:48 -07:00
topjohnwu
8bd0c44e83 Replace module fd with memfd if possible 2021-10-28 00:26:18 -07:00
topjohnwu
34c36984e9 Stop extreme verbose logging 2021-10-27 04:00:40 -07:00
topjohnwu
8bd6aca0dd DenyList unmount without magiskd 2021-10-27 04:00:40 -07:00
topjohnwu
983b74be77 Pass MAGISKTMP over to zygote 2021-10-27 03:25:54 -07:00
topjohnwu
ea75a09f95 Make zygisk survive zygote restarts
Close #4777
2021-10-27 01:53:16 -07:00
LoveSy
4c747c4148 Add rule: allow * magisk_file lnk_file { * } 2021-10-26 00:41:04 -07:00
LoveSy
49abfcafed Fix nullptr dereference when env abnormal 2021-10-26 00:40:00 -07:00
topjohnwu
50710c72ad Cleanup magiskinit code 2021-10-26 00:35:55 -07:00