Repository navigation
mingw: guard process tree traversal against PID reuse - #6474
Closed
huong8373tt-beep wants to merge 1 commit into
Closed
huong8373tt-beep wants to merge 1 commit into
huong8373tt-beep wants to merge 1 commit into
Conversation
Signed-off-by: wangluoye <[email protected]>
dscho
added a commit
that referenced
this pull request
Nov 25, 2026
Windows can reuse the PID of an orphan's dead parent for a process Git is cleaning up. Our process-tree traversal currently matches only the parent PID, so it can mistake that unrelated orphan and its descendants for processes Git should terminate. Let's exclude reused PIDs by ensuring that the process creation time matches the one obtained together with the PID when the process tree was enumerated, by switching to `NtQuerySystemInformation()` to obtain creation times alongside parent PIDs. Candidates must not predate their claimed parents, and their recorded creation times must precede the snapshot-start cutoff. When opening a descendant for termination, its creation time must match the captured value, so a reused PID does not select a different process. This should also fix a frequent flake in VFS for Git's Functional Tests. This supersedes the process-tree cleanup proposal in the following PR: #6474. That approach opens candidates during discovery and retains a handle for every accepted descendant. Here, discovery opens no process handles, and each descendant is opened only once, at termination. Handle usage stays bounded by the root plus one temporary handle rather than growing with the tree. The independent growable-storage change is a separate commit. This fixes #6435.
Member
|
Closing, as it is superseded by #6493. |
gitforwindowshelper Bot
pushed a commit
that referenced
this pull request
Nov 26, 2026
Windows can reuse the PID of an orphan's dead parent for a process Git is cleaning up. Our process-tree traversal currently matches only the parent PID, so it can mistake that unrelated orphan and its descendants for processes Git should terminate. Let's exclude reused PIDs by ensuring that the process creation time matches the one obtained together with the PID when the process tree was enumerated, by switching to `NtQuerySystemInformation()` to obtain creation times alongside parent PIDs. Candidates must not predate their claimed parents, and their recorded creation times must precede the snapshot-start cutoff. When opening a descendant for termination, its creation time must match the captured value, so a reused PID does not select a different process. This should also fix a frequent flake in VFS for Git's Functional Tests. This supersedes the process-tree cleanup proposal in the following PR: #6474. That approach opens candidates during discovery and retains a handle for every accepted descendant. Here, discovery opens no process handles, and each descendant is opened only once, at termination. Handle usage stays bounded by the root plus one temporary handle rather than growing with the tree. The independent growable-storage change is a separate commit. This fixes #6435.
gitforwindowshelper Bot
pushed a commit
that referenced
this pull request
Nov 26, 2026
Windows can reuse the PID of an orphan's dead parent for a process Git is cleaning up. Our process-tree traversal currently matches only the parent PID, so it can mistake that unrelated orphan and its descendants for processes Git should terminate. Let's exclude reused PIDs by ensuring that the process creation time matches the one obtained together with the PID when the process tree was enumerated, by switching to `NtQuerySystemInformation()` to obtain creation times alongside parent PIDs. Candidates must not predate their claimed parents, and their recorded creation times must precede the snapshot-start cutoff. When opening a descendant for termination, its creation time must match the captured value, so a reused PID does not select a different process. This should also fix a frequent flake in VFS for Git's Functional Tests. This supersedes the process-tree cleanup proposal in the following PR: #6474. That approach opens candidates during discovery and retains a handle for every accepted descendant. Here, discovery opens no process handles, and each descendant is opened only once, at termination. Handle usage stays bounded by the root plus one temporary handle rather than growing with the tree. The independent growable-storage change is a separate commit. This fixes #6435.
gitforwindowshelper Bot
pushed a commit
that referenced
this pull request
Nov 26, 2026
Windows can reuse the PID of an orphan's dead parent for a process Git is cleaning up. Our process-tree traversal currently matches only the parent PID, so it can mistake that unrelated orphan and its descendants for processes Git should terminate. Let's exclude reused PIDs by ensuring that the process creation time matches the one obtained together with the PID when the process tree was enumerated, by switching to `NtQuerySystemInformation()` to obtain creation times alongside parent PIDs. Candidates must not predate their claimed parents, and their recorded creation times must precede the snapshot-start cutoff. When opening a descendant for termination, its creation time must match the captured value, so a reused PID does not select a different process. This should also fix a frequent flake in VFS for Git's Functional Tests. This supersedes the process-tree cleanup proposal in the following PR: #6474. That approach opens candidates during discovery and retains a handle for every accepted descendant. Here, discovery opens no process handles, and each descendant is opened only once, at termination. Handle usage stays bounded by the root plus one temporary handle rather than growing with the tree. The independent growable-storage change is a separate commit. This fixes #6435.
gitforwindowshelper Bot
pushed a commit
that referenced
this pull request
Nov 27, 2026
Windows can reuse the PID of an orphan's dead parent for a process Git is cleaning up. Our process-tree traversal currently matches only the parent PID, so it can mistake that unrelated orphan and its descendants for processes Git should terminate. Let's exclude reused PIDs by ensuring that the process creation time matches the one obtained together with the PID when the process tree was enumerated, by switching to `NtQuerySystemInformation()` to obtain creation times alongside parent PIDs. Candidates must not predate their claimed parents, and their recorded creation times must precede the snapshot-start cutoff. When opening a descendant for termination, its creation time must match the captured value, so a reused PID does not select a different process. This should also fix a frequent flake in VFS for Git's Functional Tests. This supersedes the process-tree cleanup proposal in the following PR: #6474. That approach opens candidates during discovery and retains a handle for every accepted descendant. Here, discovery opens no process handles, and each descendant is opened only once, at termination. Handle usage stays bounded by the root plus one temporary handle rather than growing with the tree. The independent growable-storage change is a separate commit. This fixes #6435.
gitforwindowshelper Bot
pushed a commit
that referenced
this pull request
Nov 29, 2026
Windows can reuse the PID of an orphan's dead parent for a process Git is cleaning up. Our process-tree traversal currently matches only the parent PID, so it can mistake that unrelated orphan and its descendants for processes Git should terminate. Let's exclude reused PIDs by ensuring that the process creation time matches the one obtained together with the PID when the process tree was enumerated, by switching to `NtQuerySystemInformation()` to obtain creation times alongside parent PIDs. Candidates must not predate their claimed parents, and their recorded creation times must precede the snapshot-start cutoff. When opening a descendant for termination, its creation time must match the captured value, so a reused PID does not select a different process. This should also fix a frequent flake in VFS for Git's Functional Tests. This supersedes the process-tree cleanup proposal in the following PR: #6474. That approach opens candidates during discovery and retains a handle for every accepted descendant. Here, discovery opens no process handles, and each descendant is opened only once, at termination. Handle usage stays bounded by the root plus one temporary handle rather than growing with the tree. The independent growable-storage change is a separate commit. This fixes #6435.
gitforwindowshelper Bot
pushed a commit
that referenced
this pull request
Nov 30, 2026
Windows can reuse the PID of an orphan's dead parent for a process Git is cleaning up. Our process-tree traversal currently matches only the parent PID, so it can mistake that unrelated orphan and its descendants for processes Git should terminate. Let's exclude reused PIDs by ensuring that the process creation time matches the one obtained together with the PID when the process tree was enumerated, by switching to `NtQuerySystemInformation()` to obtain creation times alongside parent PIDs. Candidates must not predate their claimed parents, and their recorded creation times must precede the snapshot-start cutoff. When opening a descendant for termination, its creation time must match the captured value, so a reused PID does not select a different process. This should also fix a frequent flake in VFS for Git's Functional Tests. This supersedes the process-tree cleanup proposal in the following PR: #6474. That approach opens candidates during discovery and retains a handle for every accepted descendant. Here, discovery opens no process handles, and each descendant is opened only once, at termination. Handle usage stays bounded by the root plus one temporary handle rather than growing with the tree. The independent growable-storage change is a separate commit. This fixes #6435.
gitforwindowshelper Bot
pushed a commit
that referenced
this pull request
Nov 30, 2026
Windows can reuse the PID of an orphan's dead parent for a process Git is cleaning up. Our process-tree traversal currently matches only the parent PID, so it can mistake that unrelated orphan and its descendants for processes Git should terminate. Let's exclude reused PIDs by ensuring that the process creation time matches the one obtained together with the PID when the process tree was enumerated, by switching to `NtQuerySystemInformation()` to obtain creation times alongside parent PIDs. Candidates must not predate their claimed parents, and their recorded creation times must precede the snapshot-start cutoff. When opening a descendant for termination, its creation time must match the captured value, so a reused PID does not select a different process. This should also fix a frequent flake in VFS for Git's Functional Tests. This supersedes the process-tree cleanup proposal in the following PR: #6474. That approach opens candidates during discovery and retains a handle for every accepted descendant. Here, discovery opens no process handles, and each descendant is opened only once, at termination. Handle usage stays bounded by the root plus one temporary handle rather than growing with the tree. The independent growable-storage change is a separate commit. This fixes #6435.
gitforwindowshelper Bot
pushed a commit
that referenced
this pull request
Nov 30, 2026
Windows can reuse the PID of an orphan's dead parent for a process Git is cleaning up. Our process-tree traversal currently matches only the parent PID, so it can mistake that unrelated orphan and its descendants for processes Git should terminate. Let's exclude reused PIDs by ensuring that the process creation time matches the one obtained together with the PID when the process tree was enumerated, by switching to `NtQuerySystemInformation()` to obtain creation times alongside parent PIDs. Candidates must not predate their claimed parents, and their recorded creation times must precede the snapshot-start cutoff. When opening a descendant for termination, its creation time must match the captured value, so a reused PID does not select a different process. This should also fix a frequent flake in VFS for Git's Functional Tests. This supersedes the process-tree cleanup proposal in the following PR: #6474. That approach opens candidates during discovery and retains a handle for every accepted descendant. Here, discovery opens no process handles, and each descendant is opened only once, at termination. Handle usage stays bounded by the root plus one temporary handle rather than growing with the tree. The independent growable-storage change is a separate commit. This fixes #6435.
gitforwindowshelper Bot
pushed a commit
that referenced
this pull request
Nov 30, 2026
Windows can reuse the PID of an orphan's dead parent for a process Git is cleaning up. Our process-tree traversal currently matches only the parent PID, so it can mistake that unrelated orphan and its descendants for processes Git should terminate. Let's exclude reused PIDs by ensuring that the process creation time matches the one obtained together with the PID when the process tree was enumerated, by switching to `NtQuerySystemInformation()` to obtain creation times alongside parent PIDs. Candidates must not predate their claimed parents, and their recorded creation times must precede the snapshot-start cutoff. When opening a descendant for termination, its creation time must match the captured value, so a reused PID does not select a different process. This should also fix a frequent flake in VFS for Git's Functional Tests. This supersedes the process-tree cleanup proposal in the following PR: #6474. That approach opens candidates during discovery and retains a handle for every accepted descendant. Here, discovery opens no process handles, and each descendant is opened only once, at termination. Handle usage stays bounded by the root plus one temporary handle rather than growing with the tree. The independent growable-storage change is a separate commit. This fixes #6435.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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:
NtQueryInformationProcess(ProcessBasicInformation);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.exeon Windows/MINGW64t/unit-tests/bin/unit-tests.exe -r mingwgit diff --checkThe 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.