Skip to content

Generalize emutls corruption fix beyond v1.26.0.2 - #141

Open
trasnake87 wants to merge 1 commit into
minecraft-linux:masterfrom
trasnake87:emutls-hook-runtime
Open

trasnake87 wants to merge 1 commit into
minecraft-linux:masterfrom
trasnake87:emutls-hook-runtime

Conversation

@trasnake87

Copy link
Copy Markdown
Contributor

Background

PR #132 fixed one specific __emutls_control corruption offset for v1.26.0.2 where __emutls_v.* symbols collided with rand_meth data due to an LLD linker bug. The same bug class hits later Bedrock releases (1.26.10.x, 1.26.20.x, 1.26.30.x, …) but at different release-specific offsets, and the bad controls vary per point release. Hand-finding each one by disassembly hasn't scaled — every new build crashes again with SIGABRT 600+ frames deep in static init via MinecraftGame::init.

What this PR does

Adds a runtime function hook on __emutls_get_address in libc++_shared.so (the only implementation libminecraftpe.so imports). The wrapper sanitizes any control whose first two fields (size, align) are both pointer-sized (≥ 256MB) — that's the collision pattern; real controls have size < 1MB and align ≤ 4096 — and resets to {size=8, align=8, index=0, templ=NULL} before tail-calling the original. Catches every version of the bug at runtime, no per-build offset hunting.

The hook patches the function entry with a 13-byte absolute jump (movabs \$wrapper, %r11; jmp *%r11) and trampolines the original 16 bytes. libc++_shared's __emutls_get_address prologue is 6× push, mov %rdi,%rbx, mov 0x10(%rdi),%r13 — exactly 16 bytes ending on an instruction boundary. A 13-byte trampoline copy would cut the trailing 4-byte mov in half and break the trampoline.

Also stubs Java_com_mojang_minecraftpe_PlayIntegrity_nativePlayIntegrityComplete in the JNI symbol resolver — 1.26.20.4 declares the native but no shipped library exports the C side. Google Play Integrity has no Linux desktop equivalent, the underlying MainActivity::startPlayIntegrityCheck is already a no-op, and a no-op stub here silences the missing-symbol log without changing behavior.

Tested

  • 1.26.20.4 (versioncode 982602004): boots through static init past the previous abort, reaches main menu, signs into Microsoft account via the Qt WebView, gets to Friends list. Game runs on NVIDIA RTX 4070, OpenGL ES 3.2.
  • 1.26.0.2: existing direct-offset patch path still fires for backward compat.

Notes

  • x86_64 only (matches existing #ifdef __x86_64__).
  • Heuristic size ≥ 256MB && align ≥ 256MB is intentionally strict — false positives would catch any pair of pointers, but no real __emutls_get_address call would ever pass through such a control (real ones have small-integer size/align).
  • The 16-byte prologue length is libc++_shared-NDK-specific. If a future Bedrock ships a libc++_shared with a different prologue, the trampoline copy needs adjusting; the patched 13 bytes don't change.

🤖 Generated with Claude Code

PR minecraft-linux#132 fixed one specific __emutls_control corruption offset for
v1.26.0.2 where __emutls_v.* symbols collided with rand_meth data due
to an LLD linker bug. Newer Bedrock releases (1.26.10.x, 1.26.20.x,
1.26.30.x and onward) all hit the same bug class but at different,
release-specific offsets — hand-finding each one by disassembly has not
scaled.

Add a runtime function hook on __emutls_get_address in libc++_shared.so
(the only implementation libminecraftpe.so imports) that sanitizes the
incoming control struct when it detects the collision pattern (size and
align both pointer-sized — > 256MB) and resets to the safe defaults
{size=8, align=8, index=0, templ=NULL} before tail-calling the original.

The hook patches the function entry with a 13-byte absolute jump
(`movabs $wrapper, %r11; jmp *%r11`) and trampolines the original 16
bytes (libc++_shared's prologue: 6× push, mov %rdi,%rbx, mov 0x10(%rdi),
%r13 — falls exactly on instruction boundaries). 13-byte trampolines
break here because they cut the trailing 4-byte mov in half.

Also stub Java_com_mojang_minecraftpe_PlayIntegrity_nativePlayIntegrityComplete
in the JNI symbol resolver — 1.26.20.4 expects the native to exist but
no shipped library exports it, and Google Play Integrity has no Linux
desktop equivalent. A no-op stub silences the missing-symbol log; the
underlying integrity check is launcher-stubbed already
(MainActivity::startPlayIntegrityCheck is empty).

Tested on 1.26.20.4 — game boots through static init past the previous
SIGABRT in MinecraftGame::init and reaches the main menu. Existing v1.26.0.2
direct-offset patch is left in place for backward compat.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@trasnake87

Copy link
Copy Markdown
Contributor Author

The three failing Linux jobs (linux / build, linux / build32, linux / buildbusterappimage) are blocked by a pre-existing infrastructure issue, not this change — the Xenial Docker image's glibc is too old for Node.js 20 (/__e/node20/bin/node: /lib/x86_64-linux-gnu/libm.so.6: version 'GLIBC_2.27' not found), so the runner dies before any compile step. The same three jobs are red on every open PR (#133, #137, #138) and on master itself. The macOS build-protobuf failure is similarly pre-existing.

The Bookworm jobs that actually exercise this change build cleanly across all four architectures (linux / bookworm ( x86 | armhf | x86_64 | arm64 ) all green). Locally also tested on Bedrock 1.26.20.4 — game boots through static init past the previous SIGABRT and reaches the main menu with Microsoft sign-in working through the Qt WebView.

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.

1 participant