Add ProcessStartInfo.InheritedHandles to restrict child process handle inheritance#126318
Conversation
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/9d1807f7-d4f3-4d70-bf98-1a9cdca1ea2f Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…sAddRef ordering, test robustness Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/9d1807f7-d4f3-4d70-bf98-1a9cdca1ea2f Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot please address my feedback
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessStartInfo.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessStartInfo.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/Common/src/Interop/Unix/System.Native/Interop.ForkAndExecProcess.cs
Outdated
Show resolved
Hide resolved
src/libraries/Common/src/Interop/Unix/System.Native/Interop.ForkAndExecProcess.cs
Outdated
Show resolved
Hide resolved
src/libraries/Common/src/Interop/Unix/System.Native/Interop.ForkAndExecProcess.cs
Outdated
Show resolved
Hide resolved
...ries/System.Diagnostics.Process/src/Microsoft/Win32/SafeHandles/SafeProcessHandle.Windows.cs
Outdated
Show resolved
Hide resolved
...ries/System.Diagnostics.Process/src/Microsoft/Win32/SafeHandles/SafeProcessHandle.Windows.cs
Outdated
Show resolved
Hide resolved
…OEX refactoring, auto-property, RemoteExecutor tests Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/8ed756c4-f9e3-4311-902b-2e2b283c2682 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot please address my feedback
src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CreateProcessWithLogon.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
...ries/System.Diagnostics.Process/src/Microsoft/Win32/SafeHandles/SafeProcessHandle.Windows.cs
Show resolved
Hide resolved
...ries/System.Diagnostics.Process/src/Microsoft/Win32/SafeHandles/SafeProcessHandle.Windows.cs
Outdated
Show resolved
Hide resolved
...ries/System.Diagnostics.Process/src/Microsoft/Win32/SafeHandles/SafeProcessHandle.Windows.cs
Outdated
Show resolved
Hide resolved
...ries/System.Diagnostics.Process/src/Microsoft/Win32/SafeHandles/SafeProcessHandle.Windows.cs
Outdated
Show resolved
Hide resolved
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ProcThreadAttributeList.cs
Outdated
Show resolved
Hide resolved
… improve tests Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/cbca9e9f-f00e-4bc2-86ee-96f18d939d95 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
… where it is used Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/8109f39a-053e-4c14-840d-2d6c4e6cd104 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot please address my feedback
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ProcThreadAttributeList.cs
Outdated
Show resolved
Hide resolved
...ries/System.Diagnostics.Process/src/Microsoft/Win32/SafeHandles/SafeProcessHandle.Windows.cs
Outdated
Show resolved
Hide resolved
...ries/System.Diagnostics.Process/src/Microsoft/Win32/SafeHandles/SafeProcessHandle.Windows.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
…ts, fdwalk support Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/87042cef-4c5c-4a21-971b-4c746ab48ee8 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
All addressed in 6d4cbac. Summary of changes:
|
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot address my feedback
...ries/System.Diagnostics.Process/src/Microsoft/Win32/SafeHandles/SafeProcessHandle.Windows.cs
Outdated
Show resolved
Hide resolved
...ries/System.Diagnostics.Process/src/Microsoft/Win32/SafeHandles/SafeProcessHandle.Windows.cs
Outdated
Show resolved
Hide resolved
...ries/System.Diagnostics.Process/src/Microsoft/Win32/SafeHandles/SafeProcessHandle.Windows.cs
Outdated
Show resolved
Hide resolved
...ries/System.Diagnostics.Process/src/Microsoft/Win32/SafeHandles/SafeProcessHandle.Windows.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessStartInfo.cs
Outdated
Show resolved
Hide resolved
…or messages Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/291e4ac4-3f92-47ff-b73a-f47d7ce83920 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
This comment has been minimized.
This comment has been minimized.
We already have such a test ( runtime/src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs Lines 118 to 121 in 36fac4d |
...ries/System.Diagnostics.Process/src/Microsoft/Win32/SafeHandles/SafeProcessHandle.Windows.cs
Outdated
Show resolved
Hide resolved
…ck in pal_process.c Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/29c24dd2-ff38-42fd-9771-4449db8d3a96 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
...ries/System.Diagnostics.Process/src/Microsoft/Win32/SafeHandles/SafeProcessHandle.Windows.cs
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
...ries/System.Diagnostics.Process/src/Microsoft/Win32/SafeHandles/SafeProcessHandle.Windows.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessStartInfo.cs
Outdated
Show resolved
Hide resolved
- use indexed argument names in ArgumentExceptions, add local helper, remove resource - introduce helper for checking if given handle is valid on Windows Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This API is documented as not safe for such scenarios. We are NOT going to try to prevent all possible misuses. This is by design.
This is not true.
This is a new API, that user has to explicitly enable. It's introduced for the sake of correctness, at a cost of potential performance degradation. This is documented and by design.
This is by design. We have two options:
We can't use any general purpose logger because it's base class library. We could emit some kind of event, but it's pointless because users would need to know about it's existence and sign up for it. And the only way to get to the point where we need to throw here is invalid usage of the API, where user has provided us with a handle that some other part of the application has closed. |
- remove the test case that could potentially fail when OS uses same handle/descriptor value for a different pipe - use NUL device for testing the "not inherited" scenario as runtime does not use CharacterDevice files for internal purposes
This comment has been minimized.
This comment has been minimized.
...ries/System.Diagnostics.Process/src/Microsoft/Win32/SafeHandles/SafeProcessHandle.Windows.cs
Outdated
Show resolved
Hide resolved
...ries/System.Diagnostics.Process/src/Microsoft/Win32/SafeHandles/SafeProcessHandle.Windows.cs
Outdated
Show resolved
Hide resolved
...ries/System.Diagnostics.Process/src/Microsoft/Win32/SafeHandles/SafeProcessHandle.Windows.cs
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
🤖 Copilot Code Review — PR #126318Note This review was generated by GitHub Copilot. Holistic AssessmentMotivation: Well-justified. This implements Approach: Sound. The implementation uses platform-appropriate mechanisms: Summary: Detailed Findings✅ API Approval Verification — Matches approved shapeThe public sealed partial class ProcessStartInfo
{
public IList<SafeHandle>? InheritedHandles { get; set; }
}The ref assembly ( ✅ Windows Implementation — PROC_THREAD_ATTRIBUTE_HANDLE_LISTThe Windows path correctly:
✅ Unix Implementation — Graceful fallback chainThe native C implementation provides a well-layered fallback:
Critically, the code uses The per-architecture ✅ Handle Lifecycle Management
✅ Test CoverageComprehensive tests covering:
|
|
/ba-g the failures and foremost timeouts are unrelated ( |
fixes #13943