Skip to content

Restrict handle inheritance in Process convenience APIs - #136648

Open
adamsitnik wants to merge 1 commit into
dotnet:mainfrom
adamsitnik:process-scenarios-restrict-inheritance
Open

adamsitnik wants to merge 1 commit into
dotnet:mainfrom
adamsitnik:process-scenarios-restrict-inheritance

Conversation

@adamsitnik

Copy link
Copy Markdown
Member

Summary

  • Set InheritedHandles = [] in the shared factory for all five Process.Run* and Process.StartAndForget overloads that accept a file name and argument collection. Overloads accepting a caller-provided ProcessStartInfo remain unchanged.
  • Document the new default and add seven regression cases covering every affected API, including synchronous/asynchronous execution and both silent values where applicable.
  • Simplify 14 call sites across 13 runtime-test files touched by Modernize runtime test process orchestration with .NET 11 APIs #136474 to use the file-name/arguments overloads. Preserve command wrapping, diagnostics, timeouts, and captured output; retain ProcessStartInfo where custom settings are needed.

Additional handle inheritance now requires using a ProcessStartInfo overload. Standard-handle behavior is unchanged.

Validation

Tested locally on Windows x64:

  • .\dotnet.cmd build src\libraries\System.Diagnostics.Process\src\System.Diagnostics.Process.csproj -p:Configuration=Release -p:RunAnalyzersInBuild=true passed with no warnings or errors.
  • The seven new regression cases failed without the product change and passed with it.
  • .\dotnet.cmd build /t:Test src\libraries\System.Diagnostics.Process\tests\System.Diagnostics.Process.Tests.csproj -p:Configuration=Release completed with 700 passed, 2 skipped, and 1 failed. The failure was ProcessHandlesTests.ChildProcess_CanBreakAwayFromJob(killOnParentExit: False): Windows returned Win32Exception(5): Access is denied in the WindowsProcessStartArguments callback, outside the convenience overloads changed here.
  • All modified runtime-test sources compiled using the existing checked baseline. The three modified NativeAOT caller projects were also compiled as managed assemblies.
  • .\dotnet.cmd build src\tests\Common\XUnitLogChecker\XUnitLogChecker.csproj -p:Configuration=Release -p:RunAnalyzersInBuild=true passed with no warnings or errors.
  • .\dotnet.cmd build src\tests\run.cs -o artifacts\process-overload-runner -p:RunAnalyzersInBuild=true passed.
  • Binder resolution-flow tests passed: 32 completed cases, including 21 isolated process launches. R2RDump tests passed. These runs used the locally built System.Diagnostics.Process assembly through CORE_LIBRARIES.
  • Twelve additional local checks against the actual runner/checker helpers passed, covering executable exit codes, .cmd wrapping, paths/arguments containing spaces, empty arguments, ComSpec fallback, stdout/stderr capture, diagnostics, and startup failures. The loaded Process assembly was checked against the local build's SHA-256 hash.
  • git diff --check passed.

Linux-specific and NativeAOT-specific scenarios were compiled but not executed. The full runtime test suite was not run.

Local measurements

A short Windows BenchmarkDotNet run compared an unrestricted ProcessStartInfo control with the restricted file-name/arguments overloads, launching cmd.exe /d /c exit 0.

Operation Unrestricted ProcessStartInfo Restricted convenience overload
Run 16.26 ms 15.49 ms
RunAndCaptureText 15.26 ms 15.89 ms

This used the same locally built Process assembly, the in-process emit toolchain, three warmups, eight measured iterations, and 128 invocations per iteration. It is not a historical-binary comparison, and the short run does not establish a performance improvement or regression.

Note

This pull request description and code changes were generated with GitHub Copilot.

Default filename/argument Run and StartAndForget overloads to an empty inherited-handle list. Document and test the defaults, and simplify runtime test callers to use these overloads.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b56f030a-6967-43bf-9b78-2a83168f750c
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@adamsitnik adamsitnik added this to the 12.0.0 milestone Oct 29, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-diagnostics-process
See info in area-owners.md if you want to be subscribed.

@adamsitnik
adamsitnik requested a review from jkotas October 29, 2026 18:19
@jkotas

jkotas commented Oct 29, 2026

Copy link
Copy Markdown
Member

This is breaking change, correct? What will be the justification for the breaking change?

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

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants