Skip to content

Deadlock: MemoryReadSafe hangs after a second-chance ACCESS_VIOLATION stop #39

Description

@linsmod

Bug

MemoryReadSafe hangs forever when a debugger pauses in the UE_CH_ACCESSVIOLATION / UE_CH_PAGEGUARD callback (second-chance exception) and then reads the target's memory.

Repro

With aidbg (a TitanEngine-based debugger) debugging a 64-bit program that raises a write-AV:

aidbg --batch -x "file test_exception.exe" -ex "set args av" -ex "run" -ex "dump 0x140000000 16"

The session stops at 0xc0000005, then dump (which calls MemoryReadSafe) never returns and the debugger hangs. bt still works (it does not use MemoryReadSafe). The same happens on a 32-bit (WoW64) target calling through a null function pointer.

Root cause

DebugLoop() holds LockBreakPointBuffer (via breakpointLock) for the whole STATUS_GUARD_PAGE_VIOLATION / STATUS_ACCESS_VIOLATION case. For a debuggee-generated AV (no memory breakpoint) DBGCode stays DBG_EXCEPTION_NOT_HANDLED and chAccessViolation is invoked inside that lock scope. A debugger that blocks in the callback leaves the lock held, so the next MemoryReadSafe (→ BreakPointPostReadFilter, same lock) deadlocks.

Suggested fix

Release breakpointLock before invoking the AV/GUARD_PAGE handler, mirroring the existing unlock() before the memory-breakpoint callback.

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