Skip to content

mingw: guard process tree traversal against PID reuse - #6474

Open
huong8373tt-beep wants to merge 1 commit into
git-for-windows:mainfrom
huong8373tt-beep:slai/guard-windows-process-tree-pid-reuse
Open

huong8373tt-beep wants to merge 1 commit into
git-for-windows:mainfrom
huong8373tt-beep:slai/guard-windows-process-tree-pid-reuse

Conversation

@huong8373tt-beep

Copy link
Copy Markdown

Summary

Fixes #6435.

terminate_process_tree() previously expanded the cleanup tree using only the parent PID recorded in a Toolhelp snapshot. A PID can be reused after its original process exits, so an unrelated long-running orphan could retain a dead parent PID that is later assigned to a Git child. The fallback cleanup path could then terminate that unrelated process.

Validate every candidate before adding it to the cleanup tree:

  • re-check its live parent PID from its process handle using NtQueryInformationProcess(ProcessBasicInformation);
  • require the candidate creation time to be no earlier than its accepted parent;
  • retain a handle for each accepted node until termination completes, so accepted PIDs cannot be reused while the tree is being walked.

If a candidate cannot be opened with the query and terminate rights needed for this validation, it is not added to the descendant tree. The explicitly targeted root process still follows the existing termination fallback.

Validation

  • make -j2 DEVELOPER=1 NO_RUST=1 git.exe t/unit-tests/bin/unit-tests.exe on Windows/MINGW64
  • t/unit-tests/bin/unit-tests.exe -r mingw
    • 4 passed, 1 expected UCRT skip
  • git diff --check

The new Windows unit coverage verifies creation-time ordering and live parent identity for a real child process, including rejection when the claimed parent timestamp is later than the child.

Artificial intelligence assistance disclosure

Slai Agent Runtime assisted with reproduction, implementation, and test execution; the account owner is responsible for this submission.

Signed-off-by: wangluoye <294879785+huong8373tt-beep@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

terminate_process_tree() kills unrelated processes when a PID has been reused (no creation-time check)

1 participant