Commit Graph
418 Commits
Author SHA1 Message Date
topjohnwu a51dc10f88 native: Simplify and deduplicate package lookup
- Expose MagiskD::get_app_id via CXX bridge and reuse it in denylist
  instead of duplicating user collection and package UID lookup in C++.
- Remove redundant manager package name returns, Status enum, and the
  ManagerInfo wrapper struct now that the package name is fixed.

Assisted-by: Gemini 4 Argon
2026-10-22 14:06:48 -07:00
topjohnwu e8e8c3e3f1 Fix HSUM su policy lookup and manager tracking
Normalize system and shared-UID (< 10000) processes to their app ID
when evaluating su policies and uid_granted_root so policies stored by
PolicyDao.normalizeUid match across non-zero users on HSUM devices.

- Normalize eval_uid in build_su_info and uid in uid_granted_root when
  app_id < AID_APP_START.
- Ensure SECURE_DIR exists before writing settings in boot_complete(),
  seed SuMultiuserMode on HSUM, and check isHeadlessSystemUser in
  Info.showSuperUser.
- Normalize UID comparisons in PackageManager.getPackageInfo(uid, pid).
- Simplify ManagerInfo to track a single TrackedFile instead of a
  per-user BTreeMap.
- Skip negative parse_int results in deny collect_users.

Assisted-by: Gemini 4 Argon
2026-10-22 14:06:48 -07:00
topjohnwu c86a8776ce Remove stub embedding from native and scripts
Remove stub.apk and stub.xz extraction, compression,
ramdisk embedding, and daemon auto-installation from native
components (magiskinit, magiskd, scripting), installation
scripts, MagiskInstaller, and build.py.

Assisted-by: Gemini 4 Argon
2026-10-22 14:06:48 -07:00
topjohnwu 5f2faee618 native: Remove custom package and cert validation
Remove support for custom/repackaged manager package names
(su_manager / repackaged_pkg) and secondary certificate verification
(repackaged_cert) from the native daemon and database.

- Remove SuManager from DbEntryKey in CXX bridge and db.rs.
- Remove unused get_db_string and rm_db_string methods from MagiskD.
- Delete check_dyn and check_stub in package.rs.
- Remove repackaged_* fields from ManagerInfo and derive Default.
- Simplify find_apk_path, get_package_uid, and get_manager to target
  APP_PACKAGE_NAME and verify against TRUSTED_CERT.
- Bump SQLite DB_VERSION to 13, drop strings table on migration, and
  remove create_strings from new database initialization.
- Remove obsolete hidden/stub app sections from FAQ documentation.

Assisted-by: Gemini 4 Argon
2026-10-22 14:06:48 -07:00
topjohnwu ea16c8141e Fix package management and user targeting on HSUM
- Use --user current for pm install, adb install, and appops set across
  install_script, adb_pm_install, and test/setup scripts.
- Skip headless user 0 in get_users() on HSUM devices.
- Use --user current in app_notify for non-app UIDs instead of calling
  content call against all users.
- Clear path buffer on each iteration in setup_magisk_env.
- Use --user current for am instrument in app migration tests.

Assisted-by: Gemini 4 Argon
2026-10-22 14:06:48 -07:00
topjohnwu c275a4ea30 Embed trusted certificate in flags.rs
- Extract the signing certificate from keyStore via keytool in
  dump_flags_native() and emit TRUSTED_CERT in flags.rs (or an empty
  slice when keyStore is not configured).
- Replace dynamic certificate extraction from stub.apk in
  preserve_stub_apk() with the static TRUSTED_CERT constant.
- Move get_package_uid() out of MagiskD into a standalone function.

Assisted-by: Gemini 4 Argon
2026-10-22 14:06:48 -07:00
topjohnwu b43a08fdde Bump minSdk to 24 and drop API 23 workarounds
- Bump minSdk to 24 in Setup.kt, APP_PLATFORM to android-24 in
  Application.mk, and update CI AVD matrices and scripts.
- Unify SePatchStrategy::Legacy with SePatchStrategy::SelinuxFs in
  magiskinit to use MOCK_ENFORCE FIFO blocking and remove MOCK_REQPROT.
- Make APP_DATA_DIR a compile-time "/data/user_de" constant and remove
  pre-API 24 /data/user and /data/adb fallbacks.
- Remove Android 6.0 Samsung forkAndSpecialize JNI hook signature.
- Remove pre-API 24 device-protected storage wrappers, Api23Impl in
  LocaleSetting, AndroidManifest.xml stub resource workaround, and
  ServiceCompat/ProcessCompat/InlinedApi workarounds in the app.

Assisted-by: Gemini 4 Argon
2026-10-22 14:06:48 -07:00
topjohnwu e8915d9db1 su: remove obsolete access and reauth settings
With reactive su request prompts removed and superuser permissions
granted explicitly ahead of time in the app, the legacy 4-way superuser
access mode (Disabled, Apps only, ADB only, Apps & ADB) and pre-O
reauthentication after upgrade settings are no longer applicable.

ADB shell (com.android.shell) is now an explicit policy entry managed
directly in the Superuser tab, making global access filters redundant
and prone to conflicting state. Furthermore, revoking policy on package
upgrade without reactive prompting silently breaks root for upgraded
apps.

- Remove RootAccess enum and root_access checks from magiskd.
- Remove su access mode and reauthenticate settings from Manager app.
- Drop ACTION_PACKAGE_REPLACED from Receiver and manifests.
- Purge obsolete string resources across all translations.

Assisted-by: Gemini 3.8 Flash
2026-10-09 09:37:15 -07:00
topjohnwu a77198ea60 su: do not notify app when UID has no policy
With reactive su prompting removed, root requests from UIDs without
an existing policy in the database are rejected immediately. Previously,
RootSettings defaulted log and notify to true, causing the daemon to
notify the manager app whenever an unconfigured UID attempted to run
su.

Derive Default for RootSettings so that policy defaults to Deny with
log and notify initialized to false, preventing unwanted notifications
to the app when no database policy exists. Also simplify SuInfo::allow
and SuInfo::deny to leverage Default.

Assisted-by: Gemini 3.8 Flash
2026-10-09 07:16:48 +00:00
fhgffy 806ecdf8e8 Handle NULL database strings safely
SQLite returns a null pointer for SQL NULL. Passing it to rust::Str
crashes the daemon when a query result contains a NULL column.

Return an empty Rust string for NULL while leaving the raw C++ getter
unchanged, so callers that distinguish NULL can keep doing so.

Fixes: #10131
Assisted-by: GPT-6
2026-10-05 22:06:05 -07:00
topjohnwu 441ac32623 Handle the situation when connect_daemon returns -1
Fix #10117, close #10141
2026-10-06 03:45:05 +00:00
vvb2060 c155d9f0d1 su: add legacy cmd compatibility check 2026-10-05 20:03:11 -07:00
vvb2060 160fb3e40b su: pass all unknown options 2026-10-05 20:03:11 -07:00
topjohnwu 8f0cc199e7 core: resolve user 0 assumptions for HSUM
On Headless System User Mode (HSUM) devices, user 0 is headless while
human users operate under secondary user IDs. Eliminate residual
assumptions in core native components where user 0 was presumed to be
the sole or active manager user:

- In setup_magisk_env, scan all existing users via get_users() to check
  if the app-local binary install directory exists.
- In ensure_manager, check all users before falling back to stub install
  so an already-installed manager on a secondary user is recognized.
- Pass --user all to pm install, pm uninstall, and appops set in package
  management scripts to handle manager lifecycle device-wide.

Assisted-by: Gemini 3.8 Flash
2026-10-05 18:20:32 -07:00
topjohnwu e097945851 su: unify su usage callback to notify action
Consolidate su notification and logging IPC calls into a single notify
action on the native side, passing all logging parameters along with an
explicit "log" boolean key.

On the application side, retain the existing "log" action entry point
for backwards compatibility with older daemons, and update the "notify"
handler to dispatch to either logging or notification based on the
boolean values.

Assisted-by: Gemini 3.8 Flash
2026-10-05 18:20:32 -07:00
topjohnwu 813f9cb9d4 Support Headless System User Mode (HSUM)
On Headless System User Mode (HSUM) devices (e.g. Android Automotive
OS and shared tablets), user 0 is strictly a non-interactive background
system user while human users operate as secondary users (user 10+).

- Check ro.fw.mu.headless_system_user in daemon_entry and store it on
  MagiskD.
- Enforce MultiuserMode::User on HSUM devices and seed the setting in
  magisk.db during post-fs-data, avoiding duplicate override logic.
- For non-app UIDs (< AID_APP_START), scan all discovered users from
  /data/user_de to resolve the manager package/UID and broadcast su
  usage notifications across all users.
- Include system UIDs (< 10000) in PolicyDao.fetchAll() so ADB shell
  (UID 2000) policies can be loaded on secondary users.
- Hide the Multiuser Mode setting in the app on HSUM devices.

Assisted-by: Gemini 3.8 Flash
2026-10-05 18:20:32 -07:00
topjohnwu a1cf051ac7 su: remove legacy am start fallback
Historically, magiskd fell back to `am start` when notifying the app
if `content call` failed. With interactive su prompts removed and
SuRequestActivity slated for removal, this fallback is obsolete.

Rely exclusively on ContentProvider calls for su logging and notify
events, log content call errors directly, and remove Extra::add_intent.

Assisted-by: Gemini 3.8 Flash
2026-10-05 01:38:20 -07:00
topjohnwu 9a101215f1 su: remove interactive su request prompt
With the ability to explicitly grant superuser access in the app,
reactive su prompting and waiting for user response via an interactive
dialog is no longer needed.

- Remove app_request and the associated FIFO / poll waiting logic.
- Change the default SuPolicy and RootSettings from Query to Deny.
- Make SuInfo immutable by removing the internal Mutex<AccessInfo>,
  flattening settings into SuInfo, and refreshing with an updated
  clone on cache hits.
- Remove SuAppContext and convert notification and logging logic into
  private MagiskD methods.

Assisted-by: Gemini 3.8 Flash
2026-10-05 01:38:20 -07:00
vvb2060 9316445516 su: fix -g/-G 2026-10-04 23:12:01 -07:00
topjohnwu 33d09a2aff Expose xpipe2 as symbol 2026-10-02 17:17:48 -07:00
topjohnwu 8348d6e39c base: eliminate /proc/self/fd path resolution
Remove reliance on /proc/self/fd symlink resolution across base and core
components:
- Add top-level pre_order_walk and post_order_walk that track entry
  paths via an internal buffer, and unify Directory walk methods to
  support path-tracking and pathless traversals without extra overhead.
- Add DirEntry::get_stat using fstatat(AT_SYMLINK_NOFOLLOW) directly on
  directory file descriptors.
- Update Directory::copy_into and link_into to operate directly on file
  descriptors with fd_get_attr/fd_set_attr, passing paths only for
  symlink attribute updates.
- Refactor find_apk_path and restore_tmpcon to use pre_order_walk, and
  update get_app_no_list to use DirEntry::get_stat.
- Remove DirEntry::resolve_path, Directory::path_at,
  Directory::resolve_path, and fd_path.
- Replace remaining consumers of xrealpath and canonical_path (in su
  and magiskinit) with standard realpath or partition matching, allowing
  removal of Utf8CStr::realpath and its C FFI exports.

Assisted-by: Gemini 3.8 Flash
2026-10-02 17:17:48 -07:00
topjohnwu b76d674a60 Move daemon utilities from base to core
Move utilities that are exclusively used by the daemon (core module)
from base to core:
- fork_dont_care, fork_no_orphan, new_daemon_thread, init_argv0,
  set_nice_name, and switch_mnt_ns into utils.cpp
- exec_command* functions and exec_t into scripting.cpp as static
  functions, as scripting is their sole consumer

Also remove the unused exec_command_sync overload.

Assisted-by: Gemini 3.8 Flash
2026-10-02 17:17:48 -07:00
Wang Han a11ef9a4de Fix su daemon exec behavior after rust migration
Use fork_dont_care() to perform async exec and unblock all signals.
2026-09-17 22:20:42 -07:00
Wang Han 6833e56398 Don't kill webview zygote on denylist change
It won't restart and make webview unusable.
2026-08-30 20:52:34 +00:00
Wang Han b2d86c79c2 Add webview zygote as umount target
https://github.com/tiann/KernelSU/commit/4521784328352c54334beb29e05c74360b60d7cb
2026-08-30 02:59:46 -07:00
topjohnwu f38e0c8bc6 su: Enable logging and notify by default
When a UID makes a root request for the first time, no row exists in
the policies table. Previously, RootSettings derived Default, which
initialized log and notify to false. As a result, connect_app() skipped
calling app_log() or app_notify() immediately after user approval on
the initial su request.

Explicitly implement Default for RootSettings with log and notify set
to true by default.

Assisted-by: Gemini 3.7 Flash
2026-08-30 00:03:52 +00:00
xAstroBoy 8903cf7f22 zygisk: make built-in Zygisk work on Meta Quest (lazy per-trust partition zygotes)
Meta Quest (Horizon OS) does not start the zygote the normal way: ro.zygote=
zygote64_stub32 launches /system/bin/stub_zygote, which forks a separate
app_process64 zygote PER security partition (system/trusted vs untrusted-app),
driven by hzos_security_zygote_partitioning_policy. The untrusted-app partition
zygote -- the one that forks 3rd-party apps and the Magisk manager -- is spawned
LAZILY, after boot-complete.

magiskd sets ro.dalvik.vm.native.bridge=libzygisk.so during boot but clears it
again at boot-complete (ZygiskState::reset). On a normal device every zygote has
already started by then, so clearing it is harmless. On Quest the untrusted-app
partition zygote reads the (now cleared) property when it finally execve's
app_process64, never loads libzygisk.so, so 3rd-party apps + the Magisk manager
are never injected -> "Zygisk: N/A".

Fix (daemon.rs): on the boot-complete reset(restore=true) path, reset the crash
counter but KEEP native.bridge set (set_prop) instead of clearing it
(restore_prop); only the >3-crash rollback path still clears. The lazily-spawned
partition zygotes then load the loader when they start.

Also (hook.cpp), robustness fixes the loader needs on this device:
 - Wrap hook_zygote_jni()'s JNI locals in PushLocalFrame(64)/PopLocalFrame so
   leaking locals can't trip ART's "non-empty local reference table" abort, and
   bail if GetEnv returns no env.
 - Make the strdup(ZygoteInit) trigger a substring match + add an idempotency
   guard so the zygote hooks install exactly once per process.

Verified on Quest 3 (Android 14): system_server + every app fork is intercepted
and LSPosed loads end-to-end.
2026-08-27 05:38:45 +00:00
topjohnwu 3bdffe695d Generate shorty in comments and reorder jni_hooks 2026-08-12 23:49:37 +00:00
Wang Han 65aa82516f Update jni hook signatures for A17 QPR2 2026-08-11 20:14:03 -07:00
Wang Han 2c98b6ccf2 Update resetprop to support --compact 2026-08-04 12:07:38 -07:00
topjohnwu bffc9108bc Address new clippy warnings 2026-07-31 22:57:41 -07:00
topjohnwu d04635478a Fix clippy warnings across native codebase
Address clippy warnings including collapsible match statements in
bootstages, daemon, su daemon, and db modules, as well as iterator
loops in files.rs.

Assisted-by: Gemini 3.6 Flash
2026-07-31 22:57:41 -07:00
Wang Han ee25db0627 Add jni hooks signature for nubia 2026-02-22 13:20:08 -08:00
topjohnwu 9ee6a6b3d7 Update to ONDK r29.5 2026-02-06 16:32:25 -08:00
Wang Han e872fafd8b Update getModuleDir() API doc 2026-02-05 13:12:34 -08:00
Ephemera42 0d39b10889 Optimize preinit finding and add klogdump partition
* Use major number check to filter out device-mapper devices while preserving virtio-blk compatibility.
* Introduce `klogdump` partition support for Smartisan devices as a valid preinit target.
2026-02-04 21:10:25 -08:00
vvb2060 628b4d4715 Allow reacquiring capabilities if not explicitly cleared
- Old behavior: Switching to a non-zero UID was implicitly interpreted as a request to drop capabilities, thereby preventing subsequent reacquisition  via `su`.
- New behavior: Switching to a non-zero UID now requires the `--drop-cap` argument to explicitly prevent the reacquisition of capabilities.
2026-02-04 11:35:24 -08:00
canyie ac8d4200e1 Add nativeSpecializeAppProcess signature for XR devices running 14
Build fingerprint: google/gms_sdk_xr64_x86_64/emulator64_x86_64:14/UP1A.231005.007.A1/13953962:userdebug/test-keys
2026-01-31 13:51:41 -08:00
topjohnwu 01cb75eaef Code cleanup 2025-12-13 22:12:30 -08:00
topjohnwu ff4ca74cfe Ban all unwrap usage in codebase 2025-12-08 23:31:04 -08:00
topjohnwu 200665c48a Make jni_hooks.hpp a normal C++ header
[skip ci]
2025-12-07 02:44:19 -08:00
topjohnwu dd42aa99ea Refactor gen_jni_hooks.py
[skip ci]
2025-12-07 02:25:50 -08:00
Wang Han 0936cdb192 Update nativeForkAndSpecialize signature for A16 QPR2
https://android.googlesource.com/platform/frameworks/base.git/+/67a4b1b2fee385f798d75ad02d016b80fc79f075
2025-12-07 00:18:50 -08:00
topjohnwu a510554b21 Disable Zygisk upon incomplete JNI hook
Do not enable Zygisk unless ALL replacements are hooked properly.
This allow Zygisk tests to fail when new signature is introduced.
2025-12-07 00:18:50 -08:00
南宫雪珊 9a776c22d9 Revert "Use rootfs for magisktmp if possible" 2025-12-01 11:45:34 -08:00
topjohnwu f7ce9c38e1 Run through clippy and rustfmt 2025-11-29 00:13:41 -08:00
LoveSy bdbfb40383 Use rootfs for magisktmp if possible 2025-11-29 00:13:41 -08:00
topjohnwu 3a60ef2039 Update to ONDK r29.3 2025-11-21 13:28:46 -08:00
Wang Han 52d7eff03f Fix splice direction for ptmx out stream 2025-11-19 15:14:59 -08:00
Wang Han f741a4aeb8 Free regex resources in plt_hook_commit
Free regex resources for registered and ignored hooks before clearing the lists.
2025-11-02 01:59:03 -08:00