-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to stop child process from Inheriting Handles #264
Comments
This was discussed in the libs-api meeting. It was suggested that perhaps a better API would be to give an array of handles to inherit, with an empty array automatically setting inheritance to false. It was also mentioned that however this bool is set, it does effectively override Note: A motivating use case for this option is in the pseudo console example code: Creating the Hosted Process. The pseudo gets passed differently so inheritance is unnecessary. This works because if any of stdout, stdin or stderror are set to null then a child process will be given new handles derived from the console it's attached to (assuming it's not a gui process). |
Sorry for the late response, I recently had a lot on my hands with the new Semester at University and a new Job. With this plan, it still eludes me how you could both pass some handles to a process while stopping it from inheriting other. |
Windows versions >= Vista support specifying a list of handles to inherit when creating a process by setting the process attribute The setup code is ... not straightforward. Raymond Chen has a brief writeup on it at https://devblogs.microsoft.com/oldnewthing/20111216-00/?p=8873, with sample code. |
If we want to allow specifying a slice of handles to be inherited, we should first merge rust-lang/rust#123604, so the interface can be added there. |
Since the list of handles must be specified in the process thread attributes via the PROC_THREAD_ATTRIBUTE_HANDLE_LIST attribute, it becomes difficult—if not impossible—to determine if the attribute is populated, as there seems to be no way (at least to my knowledge) to inspect the attributes set in a Per the Windows documentation:
This could lead to unexpected behavior when (Sorry for the links, text fragments are not working for some reason) |
Hi, as mentioned in rust-lang/rust#115501 (comment), I believe that @michaelvanstraten's suggestion is relevant independently of what was proposed during the libs-api meeting regarding having an API to inherit specific handles. Indeed, when a program is running as PPL, it can only spawn child processes as non-protected if (and only if) the This means that current Rust programs running as PPL cannot use the standard library to spawn processes. I tested the option proposed in this post and the Note that setting @ChrisDenton would it be possible to re-discuss this issue with the libs-api team? |
Having this re-evaluated somewhat soon would be nice, please. |
API Change Proposal
Problem Statement
Currently, there is no mechanism in the Rust standard library to create a child process on Windows that does not inherit handles from the calling process.
Motivating Examples or Use Cases
Handle inheritance can be problematic in multi-threaded programs, as different command-spawning actions may require passing different files to the child process. In addition, improving security by preventing the child process from acquiring certain handles is essential.
Disabling handle inheritance when unnecessary is important for several reasons:
Solution Sketch
To address this issue, we propose adding a new flag to the
CommandExt
trait in Rust's standard library. This flag will determine whether the child process should inherit handles from the calling process.Additionally, the proposed change will affect the underlying
CreateProcessW
function, as shown below:Alternatives
Links and Related Work
For further reference, please consult the following resources:
The text was updated successfully, but these errors were encountered: