NokiaTube | New address | Mode Desktop | On high quality
Skip to content

windows: Fix attach hang when mapping fails - #1301

Merged
oleavr merged 2 commits into
frida:mainfrom
kkuehl:fix/windows-attach-hang-on-map-failure
Nov 23, 2026
Merged

oleavr merged 2 commits into
frida:mainfrom
kkuehl:fix/windows-attach-hang-on-map-failure

Conversation

@kkuehl

@kkuehl kkuehl commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

On Windows, attach() to a process that has exited but can still be opened never returns. The process stays openable for as long as anything holds a handle to it, which on the machine where I hit this was 10 seconds or more after it exited. frida-core logs an uncaught error and the call never completes.

Cause

_frida_windows_helper_backend_inject_library_section() passes the GError from gum_windows_bytes_new_from_section(), gum_mapper_new_take_blob() and gum_mapper_map() straight through. Those are in GUM_ERROR. The Vala side is declared throws Error, so the generated code only propagates FRIDA_ERROR; for any other domain it logs the error as uncaught and unrefs the task without returning from it. The caller is never resumed.

An exited target is one way to get there: gum_mapper_map() cannot allocate in it. Any other mapping failure takes the same path, for example an import that cannot be resolved.

Fix

Two commits:

  1. windows: Fix attach hang when mapping fails: frida_map_library_section() now reports Gum's errors as Frida.Error.NOT_SUPPORTED with Gum's message, the way the Darwin backend's gum_failure path does. This is what stops the hang.
  2. windows: Report exited processes as not found: once the target is open, check whether it has exited and fail with PROCESS_NOT_FOUND ("Unable to find process with pid N"), the same as for a PID that no longer exists. Without this the caller is told "Unable to allocate target memory". It comes with a test, /HostSession/Windows/attach-to-exited-process, which keeps a handle to a killed process and attaches to it.

Only the section (mapper) path is changed. inject_library_file() already reports its failures as Frida.Error.

Verification

Windows Server 2025 x86_64, MSVC, --enable-tests --with-compat=disabled, new test run on its own:

Build Result
main fails: Frida-FATAL-CRITICAL: file ../src/windows/frida-helper-backend.vala: line 88: uncaught error: Unable to allocate target memory (gum-error-quark, 0). The test runner makes criticals fatal; outside it the call hangs.
first commit only attach() returns an error; the test fails only on the error not being PROCESS_NOT_FOUND
both commits passes, 25 runs out of 25

The whole frida-tests suite passes with both commits (187 ok, 0 not ok).

Not tested: x86 and arm64 targets, MinGW builds, and builds with the mapper disabled.

When Gum.Mapper could not map the agent, its error reached
inject_library_section() in its own domain. Vala only propagates
Frida.Error from there, so it logged the error as uncaught and dropped
the task without completing it, and attach() never returned.

Report mapping failures as Frida.Error, as the Darwin backend does.
A process that has exited can still be opened by PID for as long as
anyone holds a handle to it. Attaching to one went on to map the agent
and failed with "Unable to allocate target memory".

Check for it once the process is open, and fail the same way as for a
PID that no longer exists.
@oleavr
oleavr merged commit 5dc3cd1 into frida:main Nov 23, 2026
32 of 36 checks passed
@oleavr

oleavr commented Nov 23, 2026

Copy link
Copy Markdown
Member

Thanks! 🙌

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.

2 participants