Fix injector: drakvuf_set_vcpu_gprs forgot about RSI and RDI #1800
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi!
This fix is addressing issues related with target process crash/hang caused by injector e.g. #925, #1758
I've spent hours on debugging injector crashes and I found a bit surprising bug: hijacked thread context is incorrectly restored because two registers were missing in
drakvuf_set_vcpu_gprs
function: RSI and RDI.These registers are crucial because according to Microsoft x64 ABI convention, they're non-volatile registers that should be preserved by the callee. Of course the bug leads to the corruption of targeted process, usually followed by a crash.
I found the bug by debugging one of the common places where
explorer.exe
was spotted to crash after injection. In this case, injector traps on the return fromZwWaitForWorkViaWorkerFactory
where hijacked thread wakes up. The clobbered RSI register is then used in various places as it points to some shared structure withPSRWLOCK
pointer inrsi+0x48
. Final result is usually anEXCEPTION_ACCESS_VIOLATION
crash inRtlAcquireSRWLockExclusive
.Other register values are correctly restored excluding RSI and RDI:
RtlAcquireSRWLockExclusive
argument evaluated fromRSI
:The faulting instruction: