Skip to content

Hold the manager APK at a label its receiver can read - #949

Open
JingMatrix wants to merge 1 commit into
masterfrom
manager-apk-selinux-label
Open

Hold the manager APK at a label its receiver can read#949
JingMatrix wants to merge 1 commit into
masterfrom
manager-apk-selinux-label

Conversation

@JingMatrix

Copy link
Copy Markdown
Owner

manager.apk is the only file in the module directory that leaves it as a descriptor: the daemon passes it over binder to the parasitic host, and to an installed manager updating itself. The kernel judges that transfer by the receiver — selinux_binder_transfer_file checks the file against cred_sid(to), so the read is asked of u:r:shell:s0.

The installer labels the module tree system_file, which every appdomain and coredomain may read. Nothing holds it there: /data/adb is adb_data_file by default, and init's restorecon --recursive --skip-ce /data rewalks the tree whenever a directory's stored digest stops matching — a system image flashed over a kept /data. Every launch then fails the transfer, and the host dies on an intent it was never given (#948).

So the daemon reasserts the label at startup, beside /data/adb/lspd and the dex2oat wrappers, and only when it has drifted.

The manager APK is the one file in the module directory that leaves it
as a descriptor rather than as bytes: the framework service hands it to
the host process to inject, and the manager service hands it to an
installed manager to update itself. The kernel judges that hand-off by
the receiver -- selinux_binder_transfer_file checks the file against
cred_sid(to) -- so the read is asked of u:r:shell:s0 for the parasitic
host, and of the app's own domain for an installed one, never of the
daemon's root context. Opening the file as root proves nothing about
whether it can be passed on.

What makes the hand-off work is the label the installer leaves: Magisk's
set_perm_recursive writes system_file over the module tree, and the
platform lets every appdomain and coredomain read one. Nothing holds it
there. /data/adb is adb_data_file in the platform's file_contexts, and
init runs restorecon --recursive --skip-ce /data at post-fs-data
whenever the file_contexts digest stored on a directory no longer
matches -- which is what a system image flashed over a kept /data does.
The default comes back, adb_data_file is readable by adbd alone, and
every launch from then on fails the transfer. Magisk's own boot
restorecon does not repair it either, relabelling only what is
unlabeled.

The daemon is already the thing that reasserts labels at startup -- its
directory under /data/adb/lspd, the dex2oat wrappers and the oat hook
beside this APK -- so it reasserts this one too, and only when the label
has drifted. system_file rather than xposed_file: the shipped rule
grants xposed_file to shell but not to untrusted_app, which would leave
an installed manager unable to update itself.

The failure this leaves behind names nothing. The host is handed no
descriptor, the parse of it fails, and what the user sees is the host's
own activity dying on the intent it was never given.

Reported in #948.
@JingMatrix JingMatrix linked an issue Aug 29, 2026 that may be closed by this pull request
1 task
@Milor123

Copy link
Copy Markdown

thanks this solve my problem in #948 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A11 GSI App crashes immediately on open with 'shell keeps stopping' – fail

2 participants