8000 linux: Fix attach when /proc/<pid>/maps has non-UTF-8 bytes by washedbeast · Pull Request #1284 · frida/frida-core · GitHub
[go: up one dir, main page]

Skip to content

linux: Fix attach when /proc/<pid>/maps has non-UTF-8 bytes - #1284

Merged
oleavr merged 2 commits into
frida:mainfrom
washedbeast:linux-maps-raw-and-memfd
Nov 5, 2026
Merged

oleavr merged 2 commits into
frida:mainfrom
washedbeast:linux-maps-raw-and-memfd

Conversation

@washedbeast
Copy link
Copy Markdown
Contributor

On a rooted Galaxy S10+ running LineageOS 23.2 (Android 16, kernel 4.14), attach failed with unable to perform ptrace pokedata: I/O error whenever a line of the target's /proc/<pid>/maps was not valid UTF-8. Two bugs chain here:

  • ProcMapsIter matches with a GRegex that isn't RAW, and GRegex rejects the whole subject over one invalid byte. So no mappings were seen at all, no libc was found in the target, and attach fell back to the code swap. Such lines do occur: file paths can hold any bytes, and on Android kernels before 5.17 an anonymous mapping's name is read from a user pointer on every read, so a name whose string went away reads as garbage. This showed up in apps while Magisk's built-in Zygisk was enabled: their [anon:System property context nodes] mapping showed random bytes. The zymbiote heap scan had the same regex issue.
  • The code swap's memfd skip from Fix code swap region permissions #1134 checks for memfd:, but Gum reports paths like /memfd:jit-zygote-cache (deleted). So it never matched, and the code swap wrote into ART's read-only JIT cache. That's the failure analysed in how to resolve error message unable to perform ptrace pokedata frida#2782.

Tested with deskclock and calculator2, after naming an anonymous page in the app with prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, addr, len, name) from a script and then overwriting the name's bytes with \xff\xfe\x80:

  • Official 17.25.2 server: attach fails in both apps. strace shows a single POKEDATA, at the end of the JIT zygote cache, returning EIO.
  • 17.25.2 with only the second commit: the code swap goes through, and attach then fails with "unable to find libm.so in the target process".
  • 17.25.2 with both commits: attach works in both apps, and so does spawn. main with both commits behaves the same.

The new Linux test injects into a labrat started from a path ending in a 0xff byte. On main it fails with "Unable to find libc.so.6 in the target process" (linux-arm64), and it passes with the fix, along with the other injector tests.

Mapping names are not always valid UTF-8: file paths may hold any
bytes, and on Android kernels before 5.17 an anonymous mapping's name
is read from a user pointer whenever the maps are read, so a name whose
string got unmapped shows up as random bytes. We hit this with Magisk's
Zygisk, where apps inherit [anon:System property context nodes] from
zygote with a garbage name.

GRegex rejects a subject that is not valid UTF-8 unless the pattern is
raw, so one such line made ProcMapsIter yield no mappings at all. The
injector then could not find libc in the target, and attach failed.
Gum.Linux.enumerate_ranges() gives paths as they appear in the maps,
like "/memfd:jit-zygote-cache (deleted)", so the "memfd:" prefix check
from 72a9622 never matched. When libc could not be found in the
target, the code swap then picked ART's read-only JIT zygote cache and
the first write failed with "unable to perform ptrace pokedata: I/O
error".
@washedbeast
Copy link
Copy Markdown
Contributor Author

With the raw-bytes parse, a /proc/<pid>/maps line whose path is not valid UTF-8 now yields a mapping, and its path reaches new Variant.tuple ({ path }) in the resolve-symbols handler of the syscall-trace service, where g_variant_new_string() returns NULL and frida-server segfaults. On 9fd003d9, a traced process started from /data/t/yes\xff kills the server on resolve-symbols; on main the same input returns an empty module list. #1285 fixes this, along with the same crash that main and 17.25.2 already hit through eBPF map events, openat() strings and AF_UNIX socket paths.

@oleavr
oleavr merged commit 40ce660 into frida:main Nov 5, 2026
@oleavr
oleavr commented Nov 5, 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

0