Fix /data/adb/magisk permissions so Zygisk can initialise #284

Merged
MisterWizzard merged 1 commits from MisterWizzard/fix/magisk-data-adb-permissions into main 2026-10-12 14:00:20 -04:00
MisterWizzard commented 2026-08-29 19:50:13 -04:00 (Migrated from github.com)

Fixes #283

The bug

install magisk gives a working root, but Zygisk can never initialise. The Magisk app shows
Zygisk: No whatever the Zygisk setting is, and nothing anywhere explains why. Every Zygisk
module (LSPosed, Shamiko, PlayIntegrityFix, …) is therefore unusable.

General.install() runs:

self.copy()       # writes the overlay tree; shutil.copyfile carries no exec bit
self.extra1()     # -> Magisk.setup() -> copytree(overlay, <data_dir>/adb/magisk)
...
self.set_perm()   # walks only self.files, i.e. paths under copy_dir (the overlay)

set_perm() fixes the overlay copy to 0755, but never the /data/adb/magisk copy that
setup() made a moment earlier — that path is not in self.files. Those binaries keep the
0644 they inherited from the apk extraction, so magisk_env() cannot execute
/data/adb/magisk/magisk64 and aborts at post-fs-data.

su keeps working because it runs from the overlay copy, which is what makes this so easy to
misdiagnose as "Zygisk is unsupported on Waydroid".

The fix

setup() now applies to its own destination the same 0755 that Magisk.set_path_perm()
already applies to magisk paths. Four functional lines, plus a comment explaining the ordering
so it does not regress.

Verified

On Waydroid 1.6.3 / Android 13 (LineageOS 20 VANILLA, waydroid_x86_64) / Magisk Delta 26301,
with nothing changed but these permissions:

before:  -rw-r--r--  magisk64      Zygisk: No    0 zygisk mappings in zygote64
after:   -rwxr-xr-x  magisk64      Zygisk: Yes   6 zygisk mappings in zygote64

/cache/magisk.log after:
  zygisk64: replaced com/android/internal/os/Zygote#nativeForkAndSpecialize
  zygisk64: replaced com/android/internal/os/Zygote#nativeForkSystemServer
  zygisk64: replaced com/android/internal/os/Zygote#nativeSpecializeAppProcess

Zygisk modules then install and load normally.

Test

tests/test_magisk_setup_perms.py is self-contained — no Waydroid install, no root, no
dependencies beyond the stdlib:

$ python3 tests/test_magisk_setup_perms.py
ok   test_plain_copytree_loses_exec_bit
ok   test_setup_makes_data_copy_executable
ok   test_setup_is_idempotent
ok   test_perm_helper_tolerates_missing_dir

all 4 tests passed

Against the unpatched stuff/magisk.py it fails, so it is a real regression guard:

ok   test_plain_copytree_loses_exec_bit
FAIL test_setup_makes_data_copy_executable: files left non-0755: {'magisk64': '0o644', ...}
FAIL test_setup_is_idempotent:
ERROR test_perm_helper_tolerates_missing_dir: AttributeError(... no attribute 'set_data_magisk_perm')

3 test(s) failed

This adds the first tests/ directory. Happy to drop it, move it, or wire it into CI if you
would rather it lived somewhere else.

Side note for the docs / future debugging

/debug_ramdisk is not a valid way to check whether Zygisk is up on this installer:
magisk --path is /dev/magisk_<random>, so /debug_ramdisk stays empty even when Zygisk is
working. grep -c zygisk /proc/$(pgrep -f zygote64 | head -1)/maps is reliable.

Fixes #283 ### The bug `install magisk` gives a working root, but **Zygisk can never initialise**. The Magisk app shows `Zygisk: No` whatever the Zygisk setting is, and nothing anywhere explains why. Every Zygisk module (LSPosed, Shamiko, PlayIntegrityFix, …) is therefore unusable. `General.install()` runs: ```python self.copy() # writes the overlay tree; shutil.copyfile carries no exec bit self.extra1() # -> Magisk.setup() -> copytree(overlay, <data_dir>/adb/magisk) ... self.set_perm() # walks only self.files, i.e. paths under copy_dir (the overlay) ``` `set_perm()` fixes the **overlay** copy to `0755`, but never the `/data/adb/magisk` copy that `setup()` made a moment earlier — that path is not in `self.files`. Those binaries keep the `0644` they inherited from the apk extraction, so `magisk_env()` cannot execute `/data/adb/magisk/magisk64` and aborts at `post-fs-data`. `su` keeps working because it runs from the overlay copy, which is what makes this so easy to misdiagnose as "Zygisk is unsupported on Waydroid". ### The fix `setup()` now applies to its own destination the same `0755` that `Magisk.set_path_perm()` already applies to magisk paths. Four functional lines, plus a comment explaining the ordering so it does not regress. ### Verified On Waydroid 1.6.3 / Android 13 (LineageOS 20 VANILLA, `waydroid_x86_64`) / Magisk Delta 26301, with nothing changed but these permissions: ``` before: -rw-r--r-- magisk64 Zygisk: No 0 zygisk mappings in zygote64 after: -rwxr-xr-x magisk64 Zygisk: Yes 6 zygisk mappings in zygote64 /cache/magisk.log after: zygisk64: replaced com/android/internal/os/Zygote#nativeForkAndSpecialize zygisk64: replaced com/android/internal/os/Zygote#nativeForkSystemServer zygisk64: replaced com/android/internal/os/Zygote#nativeSpecializeAppProcess ``` Zygisk modules then install and load normally. ### Test `tests/test_magisk_setup_perms.py` is self-contained — no Waydroid install, no root, no dependencies beyond the stdlib: ``` $ python3 tests/test_magisk_setup_perms.py ok test_plain_copytree_loses_exec_bit ok test_setup_makes_data_copy_executable ok test_setup_is_idempotent ok test_perm_helper_tolerates_missing_dir all 4 tests passed ``` Against the unpatched `stuff/magisk.py` it fails, so it is a real regression guard: ``` ok test_plain_copytree_loses_exec_bit FAIL test_setup_makes_data_copy_executable: files left non-0755: {'magisk64': '0o644', ...} FAIL test_setup_is_idempotent: ERROR test_perm_helper_tolerates_missing_dir: AttributeError(... no attribute 'set_data_magisk_perm') 3 test(s) failed ``` This adds the first `tests/` directory. Happy to drop it, move it, or wire it into CI if you would rather it lived somewhere else. ### Side note for the docs / future debugging `/debug_ramdisk` is not a valid way to check whether Zygisk is up on this installer: `magisk --path` is `/dev/magisk_<random>`, so `/debug_ramdisk` stays empty even when Zygisk is working. `grep -c zygisk /proc/$(pgrep -f zygote64 | head -1)/maps` is reliable.
wbruno merged commit b7e1c37e14 into main 2026-10-12 14:00:20 -04:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wbruno/waydroid_script#284