8000 [macOS arm64] gum_darwin_query_page_size() returns 16 KB (0x4000) for Rosetta 2 (x86_64) processes, causing gum_darwin_read() to fail with KERN_INVALID_ADDRESS · Issue #1193 · frida/frida-gum · GitHub
[go: up one dir, main page]

Skip to content

[macOS arm64] gum_darwin_query_page_size() returns 16 KB (0x4000) for Rosetta 2 (x86_64) processes, causing gum_darwin_read() to fail with KERN_INVALID_ADDRESS #1193

Open

Description

@bogdan-petru

Environment

  • Frida version: 17.24.3 (arm64 and x86_64)
  • OS: macOS 26.6.2 (25G83, Darwin 25.6.0, xnu-12377.161.14~5/RELEASE_ARM64_T6050)
  • SIP / Boot-args: SIP disabled, boot-args="-arm64e_preview_abi thid_should_crash=0 tss_should_crash=0", target signed with com.apple.security.cs.debugger

Problem 1: gum_darwin_query_page_size() returns 0x4000 instead of 0x1000 for Rosetta (P_TRANSLATED) tasks

When attaching to a Rosetta-translated x86_64 process from arm64 Frida (frida.attach(pid)), frida-helper-arm64 fails in gum_darwin_module_resolver_load_from_dyld_info() with:

frida.NotSupportedError: unable to read from process memory

Tracing mach_vm_read inside frida-helper-arm64 shows:

[frida-helper-arm64] FAIL mach_vm_read(task=0x160f, addr=0x404c4000, size=0x4000) -> 1 ((os/kern) invalid address)

In the target Rosetta process (vmmap), a dylib (fcntl.cpython-310-darwin.so) is mapped on a 4 KB (0x1000) boundary at 0x404c7000, with an unmapped 8 KB hole immediately preceding it (0x404c5000–0x404c7000):

shared memory  404c4000-404c5000 [ 4K] r--/r-- SM=SHM
               404c5000-404c7000 [ 8K] --- UNMAPPED ---
__TEXT         404c7000-404cb000 [16K] r-x/rwx .../fcntl.cpython-310-darwin.so

Root Cause in gum/backend-darwin/gumdarwin.c

  1. gum_darwin_query_page_size() calls gum_darwin_cpu_type_from_pid(pid, &cpu_type) and sets *page_size = 4096 if cpu_type is GUM_CPU_IA32 (1) or GUM_CPU_AMD64 (2), and 16384 (0x4000) if cpu_type is GUM_CPU_ARM64 (4).
  2. However, in arm64 builds (#elif defined (HAVE_ARM) || defined (HAVE_ARM64)), gum_darwin_cpu_type_from_pid() only checks P_LP64 (0x4) in info.kp_proc.p_flag and ignores P_TRANSLATED (0x00020000):
    ldr  w8, [sp, #0x30]   ; info.kp_proc.p_flag
    tst  w8, #0x4          ; P_LP64
    mov  w8, #0x3          ; GUM_CPU_ARM (3)
    cinc w8, w8, ne        ; GUM_CPU_ARM64 (4)
    str  w8, [x19]
    
  3. Because gum_darwin_cpu_type_from_pid() never returns GUM_CPU_IA32 or GUM_CPU_AMD64 on arm64 builds, the 4096 page size branch in gum_darwin_query_page_size() is dead code.
  4. gum_darwin_read() then rounds 0x404c7000 down by ~0x3fff to 0x404c4000 and attempts a 0x4000-byte mach_vm_read, which spans the unmapped hole at 0x404c5000–0x404c7000 and fails with KERN_INVALID_ADDRESS.

Problem 2: Rosetta 2 injection on modern macOS (x86_64 vs arm64 fruitjector)

  • Attempting to attach using x86_64 Frida under Rosetta fails at remote thread creation/state setup with thread_create returned '(os/kern) invalid argument', even with thid_should_crash=0 tss_should_crash=0 and com.apple.security.cs.debugger.
  • Meanwhile, calling thread_create() from a native arm64 process succeeds (KERN_SUCCESS), but creates an arm64 Mach thread whereas TASK_DYLD_INFO in the Rosetta process points to x86_64 dylibs.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0