microsoft / microsoft/Detours

Stability guarantees of DetourUpdateThread?

Open
#152 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
C++
Stars
6.4k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

As far as I could track from the code, DetourUpdateThread enlists threads to be processed, and committing the transaction adjust the threads' instruction pointer register (let's go with x64, and call it RIP) depending on if we're adding/attaching, or removing/detaching.

I'm wondering about risk of these operations on 2 main points:

  1. Is the integrity of the thread's state preserved? Any chance of an unbalanced stack push/pop for example?
  2. In the case of removal, especially if they happen to be triggered from DllMain, detaching from process: Since the DLL code is to be removed, are there any guarantees from Detours that the removed code will not be read/(tried to be) executed? RIP shifting would take care if the RIP happened to be in our trampoline, but, what would happen if our code was deeper in the call stack (i.e. a return address from our module's address space exists somewhere in the stack)?

My first instinct is that, this guarantee cannot be provided, and the API user/developer should take care of it himself/herself probably by separating detours-detaching, and dll-unloading, and through some mechanism like reference-counting to ensure that no code of the Dll is still "active" in any of the threads.

(Please also take a look at issue #151 which is related to this API)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with DetourUpdateThread and the transaction commit path, focusing on x64 RIP changes, thread state, and detach behavior from DllMain. Review related issue #151 and the documented interaction between detaching and DLL unloading. Done would require a maintainer-backed statement of the guarantees or a clearly scoped documentation change; no files or tests are named.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools, operating-systems
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.