Skip to content
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

Merged
merged 1 commit into from
Oct 17, 2019

Conversation

oconnor663
Copy link
Contributor

@oconnor663 oconnor663 commented Oct 11, 2019

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 #31069 (comment).

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
Copy link
Collaborator

r? @Mark-Simulacrum

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 11, 2019
@Mark-Simulacrum
Copy link
Member

r? @alexcrichton

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.

@oconnor663
Copy link
Contributor Author

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 :)

oconnor663 added a commit to oconnor663/os_pipe.rs that referenced this pull request Oct 11, 2019
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.
oconnor663 added a commit to oconnor663/os_pipe.rs that referenced this pull request Oct 11, 2019
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.
oconnor663 added a commit to oconnor663/os_pipe.rs that referenced this pull request Oct 11, 2019
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.
oconnor663 added a commit to oconnor663/os_pipe.rs that referenced this pull request Oct 11, 2019
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.
oconnor663 added a commit to oconnor663/os_pipe.rs that referenced this pull request Oct 11, 2019
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.
oconnor663 added a commit to oconnor663/os_pipe.rs that referenced this pull request Oct 11, 2019
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.
@alexcrichton
Copy link
Member

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?

@oconnor663
Copy link
Contributor Author

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.

@alexcrichton
Copy link
Member

@bors: r+

Ok, it'll take awhile to merge anyway, so seems fine to me to go ahead and land!

@bors
Copy link
Contributor

bors commented Oct 15, 2019

📌 Commit 93ae692 has been approved by alexcrichton

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 15, 2019
Centril added a commit to Centril/rust that referenced this pull request Oct 16, 2019
…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).
bors added a commit that referenced this pull request Oct 17, 2019
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
Centril added a commit to Centril/rust that referenced this pull request Oct 17, 2019
…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).
bors added a commit that referenced this pull request Oct 17, 2019
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
@bors bors merged commit 93ae692 into rust-lang:master Oct 17, 2019
@oconnor663 oconnor663 deleted the noninheritable branch October 28, 2019 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants