Skip to content

fix(file-locksmith): isolate handle enumeration - #50217

Open
Clint Rutkas (crutkas) wants to merge 2 commits into
mainfrom
crutkas-file-locksmith-enumeration
Open

fix(file-locksmith): isolate handle enumeration#50217
Clint Rutkas (crutkas) wants to merge 2 commits into
mainfrom
crutkas-file-locksmith-enumeration

Conversation

@crutkas

Copy link
Copy Markdown
Member

Summary of the Pull Request

Fixes File Locksmith UI access violations and hangs by moving blockable native handle enumeration into a disposable FileLocksmithCLI.exe worker process. The UI communicates through BOM-free UTF-8 JSON over redirected stdin/stdout, enforces a 30-second timeout, and surfaces timeout or worker failures explicitly instead of showing “No results.”

This supersedes the incomplete mitigation in draft PR #49502 and addresses the crash scenarios reported in #45158 and #47200. It is intentionally separate from the File Locksmith context-menu HANG_QUIESCE lifecycle work and does not modify that code.

PR Checklist

Detailed Description of the Pull Request / Additional comments

  • Removes the detached enumeration thread and unsafe TerminateThread recovery from src/modules/FileLocksmith/FileLocksmithLibInterop/NtdllExtensions.cpp.
  • Adds hidden FileLocksmithCLI.exe --worker-json mode. Selected paths are sent in UTF-8 JSON over stdin, never command-line arguments or logs; results return as JSON over stdout.
  • Assigns each worker to a JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE job, terminates the worker process tree on timeout/cancellation, and waits for cleanup. Elevation restart cancels and awaits the active query before exiting.
  • Preserves elevated/non-elevated visibility because the worker inherits the UI token and debug privilege state. Reload and End Task behavior remain unchanged.
  • Adds localized timeout/failure InfoBar states in src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/Views/MainPage.xaml and Strings/en-us/Resources.resw.
  • Retains PR [File Locksmith] Fix Interop access-violation crashes from TerminateThread hang recovery #49502's independently correct UNICODE_STRING and OpenProcess null guards. It does not use the four GrantedAccess heuristics from [File Locksmith] Fix Interop access-violation crashes from TerminateThread hang recovery #49502 because those masks are incomplete and would introduce false-negative lock detection.
  • Logs only stage, duration, status/exit code, input count, and result count; selected file paths are not logged.
  • Documents the 30-second finite timeout in doc/devdocs/modules/filelocksmith.md.

Known risk: A legitimate full-system scan taking longer than 30 seconds now fails explicitly and can be retried rather than hanging indefinitely. The exact kernel-level NtQueryObject hang is not deterministic in automation, so timeout cleanup is validated with a real blocked child process.

Validation Steps Performed

  • Release x64 src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithUI.csproj build: passed; this also builds the FileLocksmithCLI dependency.
  • Release x64 src/modules/FileLocksmith/Tests/FileLocksmithUI.UnitTests/FileLocksmithUI.UnitTests.csproj: 6/6 passed, covering success, timeout, malformed output, failed worker exit, no-orphan timeout cleanup, BOM-free Unicode-path communication with the real CLI worker, and kill-on-close job cleanup.
  • Release x64 src/modules/FileLocksmith/FileLocksmithCLI/tests/FileLocksmithCLIUnitTests.vcxproj via vstest.console.exe: 6/6 passed.
  • Real FileLocksmithCLI.exe --worker-json stdin/stdout smoke query: exit code 0 with valid JSON; malformed worker request: exit code 2.
  • Local native/UI builds used /p:SpectreMitigation=false only because this host lacks the Spectre-mitigated MSVC libraries. No production build setting was changed.

Clint Rutkas (crutkas) and others added 2 commits August 28, 2026 13:21
Run blockable native handle enumeration in a disposable CLI worker with a finite timeout, explicit UI errors, and cleanup coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use BOM-free UTF-8 for the worker protocol and bind workers to a kill-on-close job so parent exit cannot orphan a blocked enumeration.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Thank you for contributing to PowerToys. We've detected that this PR might include a new or modified telemetry event. Please ensure the following before merging:

@github-actions github-actions Bot added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something Product-File Locksmith Refers to the File Locksmith utility labels Aug 28, 2026
@github-actions

Copy link
Copy Markdown

🧭 PR intake

Visual evidence: Required — The pull request changes product UI files, so reviewers need to see the visible result. Visual evidence is currently missing.

Author action

Clint Rutkas (@crutkas), please update the following before review:

  • Add a screenshot, GIF, or video to the PR description so reviewers can validate the visible change.

See the contribution guide for the full checklist.

If there is no author response within 7 days, this PR will be automatically closed.

Automated PR intake; PowerToys maintainers make final decisions.

@crutkas Clint Rutkas (crutkas) added Needs-Review This Pull Request awaits the review of a maintainer. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs-Review This Pull Request awaits the review of a maintainer. Product-File Locksmith Refers to the File Locksmith utility Ready for review

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

FileLocksmith runs for 5 sec and then crashes File Locksmith Crash

2 participants