-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
make File::try_clone produce non-inheritable handles on Windows #65316
Conversation
File handles shouldn't be inheritable in general. `std::process::Command` takes care of making them inheritable when child processes are spawned, and the `CREATE_PROCESS_LOCK` protects against races in that section on Windows. But `File::try_clone` has been creating inheritable file descriptors outside of that lock, which could be leaking into other child processes unintentionally. See also rust-lang#31069 (comment).
(rust_highfive has picked a reviewer for you, use r? to override) |
FWIW CI here by default runs on Linux and a Windows run these days is probably not too hard but will require some manual work I believe... I would get feedback on the idea first probably. |
Oh gotcha, my bad. I do have a Windows machine, so I can see about learning how to run libstd tests locally, though so far I've only ever done that on Linux. In the meantime, @alexcrichton if you happen to know that this change is a terrible idea, please let me know :) |
There is a bug (I think it's a bug?) in libstd which makes File::try_clone return inheritable handles. We need to work around that by making the same system calls explictly, but with the inheritable flag set to false. I've filed a fix against libstd (rust-lang/rust#65316), but even if that lands we'll need to retain this workaround for all the past versions of Rust that have the bug.
There is a bug (I think it's a bug?) in libstd which makes File::try_clone return inheritable handles. We need to work around that by making the same system calls explictly, but with the inheritable flag set to false. I've filed a fix against libstd (rust-lang/rust#65316), but even if that lands we'll need to retain this workaround for all the past versions of Rust that have the bug.
There is a bug (I think it's a bug?) in libstd which makes File::try_clone return inheritable handles. We need to work around that by making the same system calls explictly, but with the inheritable flag set to false. I've filed a fix against libstd (rust-lang/rust#65316), but even if that lands we'll need to retain this workaround for all the past versions of Rust that have the bug.
There is a bug (I think it's a bug?) in libstd which makes File::try_clone return inheritable handles. We need to work around that by making the same system calls explictly, but with the inheritable flag set to false. I've filed a fix against libstd (rust-lang/rust#65316), but even if that lands we'll need to retain this workaround for all the past versions of Rust that have the bug.
There is a bug (I think it's a bug?) in libstd which makes File::try_clone return inheritable handles. We need to work around that by making the same system calls explictly, but with the inheritable flag set to false. I've filed a fix against libstd (rust-lang/rust#65316), but even if that lands we'll need to retain this workaround for all the past versions of Rust that have the bug.
There is a bug (I think it's a bug?) in libstd which makes File::try_clone return inheritable handles. We need to work around that by making the same system calls explictly, but with the inheritable flag set to false. I've filed a fix against libstd (rust-lang/rust#65316), but even if that lands we'll need to retain this workaround for all the past versions of Rust that have the bug.
Thanks for the PR here @oconnor663! I believe this was probably just a mistake in the original PR, it's definitely intended that all handles created by the standard library are not inherited to child processes by default. The PR description says that this isn't ready for review, but the change here looks good to me. I think that this is pretty likely to be low-impact enough to land without much more ado. Was there more testing you wanted to perform though? |
Thanks @alexcrichton, I've edited my comment at the top to remove the "please don't review" :) I'll try to run compiler tests on my Windows box, but I don't know if I'll succeed, so I'm fine with landing this without waiting for me, if it looks good to you. |
@bors: r+ Ok, it'll take awhile to merge anyway, so seems fine to me to go ahead and land! |
📌 Commit 93ae692 has been approved by |
…ichton make File::try_clone produce non-inheritable handles on Windows ~**NOT READY FOR REVIEW.** This PR is currently mainly to trigger CI so that I can see what happens. (Is there a better way to trigger CI?) I don't know whether this change makes sense yet.~ (Edit: @Mark-Simulacrum clarified that CI doesn't currently run on Windows.) --- File handles shouldn't be inheritable in general. `std::process::Command` takes care of making them inheritable when child processes are spawned, and the `CREATE_PROCESS_LOCK` protects against races in that section on Windows. But `File::try_clone` has been creating inheritable file descriptors outside of that lock, which could be leaking into other child processes unintentionally. See also rust-lang#31069 (comment).
Rollup of 8 pull requests Successful merges: - #65094 (Prefer statx on linux if available) - #65316 (make File::try_clone produce non-inheritable handles on Windows) - #65319 (InterpCx: make memory field public) - #65461 (Don't recommend ONCE_INIT in std::sync::Once) - #65465 (Move syntax::ext to a syntax_expand and refactor some attribute logic) - #65469 (Update libc to 0.2.64) - #65475 (add example for type_name) - #65478 (fmt::Write is about string slices, not byte slices) Failed merges: r? @ghost
…ichton make File::try_clone produce non-inheritable handles on Windows ~**NOT READY FOR REVIEW.** This PR is currently mainly to trigger CI so that I can see what happens. (Is there a better way to trigger CI?) I don't know whether this change makes sense yet.~ (Edit: @Mark-Simulacrum clarified that CI doesn't currently run on Windows.) --- File handles shouldn't be inheritable in general. `std::process::Command` takes care of making them inheritable when child processes are spawned, and the `CREATE_PROCESS_LOCK` protects against races in that section on Windows. But `File::try_clone` has been creating inheritable file descriptors outside of that lock, which could be leaking into other child processes unintentionally. See also rust-lang#31069 (comment).
Rollup of 8 pull requests Successful merges: - #65237 (Move debug_map assertions after check for err) - #65316 (make File::try_clone produce non-inheritable handles on Windows) - #65319 (InterpCx: make memory field public) - #65461 (Don't recommend ONCE_INIT in std::sync::Once) - #65465 (Move syntax::ext to a syntax_expand and refactor some attribute logic) - #65475 (add example for type_name) - #65478 (fmt::Write is about string slices, not byte slices) - #65486 (doc: fix typo in OsStrExt and OsStringExt) Failed merges: r? @ghost
NOT READY FOR REVIEW. This PR is currently mainly to trigger CI so that I can see what happens. (Is there a better way to trigger CI?) I don't know whether this change makes sense yet.(Edit: @Mark-Simulacrum clarified that CI doesn't currently run on Windows.)File handles shouldn't be inheritable in general.
std::process::Command
takes care of making them inheritable when childprocesses are spawned, and the
CREATE_PROCESS_LOCK
protects againstraces in that section on Windows. But
File::try_clone
has beencreating inheritable file descriptors outside of that lock, which could
be leaking into other child processes unintentionally.
See also #31069 (comment).