Skip to content

Don't allow chroot-after-fork on Cygwin or QNX - #166378

Open
joshtriplett wants to merge 1 commit into
rust-lang:mainfrom
joshtriplett:chroot-no-qnx-cygwin
Open

joshtriplett wants to merge 1 commit into
rust-lang:mainfrom
joshtriplett:chroot-no-qnx-cygwin

Conversation

@joshtriplett

Copy link
Copy Markdown
Member

On QNX, chroot is explicitly documented as not safe after fork. (It appears safe in practice in the configuration that we use, but it's explicitly documented as not safe.)

Cygwin has gone to some effort to make it safe, but currently appears to have a separate race between fork and chdir that allows the forked child to see a partially modified current directory.

Check for a set chroot when spawning the process, and error on these targets. (Move the check out of do_exec, so that the error happens in the parent rather than the child, and so that exec without fork works.)

Remove stale Fuchsia check; Fuchsia doesn't use this implementation anymore, as it has its own.

On QNX, chroot is explicitly documented as not safe after fork. (It
appears safe in practice in the configuration that we use, but it's
explicitly documented as not safe.)

Cygwin has gone to some effort to make it safe, but currently appears to
have a separate race between fork and chdir that allows the forked child
to see a partially modified current directory.

Check for a set chroot when spawning the process, and error on these
targets. (Move the check out of `do_exec`, so that the error happens in
the parent rather than the child, and so that exec without fork works.)

Remove stale Fuchsia check; Fuchsia doesn't use this implementation
anymore, as it has its own.
@rustbot rustbot added A-process Area: `std::process` (note: `std::env` is A-env) O-unix Operating system: Unix-like S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 23, 2026
@rustbot

rustbot commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 38 candidates
  • Random selection from JohnTitor, Mark-Simulacrum

@RalfJung

Copy link
Copy Markdown
Member

TBH my preferred approach here would be an allowlist rather than a blocklist, pointing for each allowed platform to the evidence we have that chroot after fork is fine. The list doesn't have to cover everything from the start, we can grow it over time.

@joshtriplett

Copy link
Copy Markdown
Member Author

@RalfJung I've checked every Rust target, and these are the only two where it doesn't work. An allowlist would be a complete list of Rust targets, minus these two.

@RalfJung

Copy link
Copy Markdown
Member

The list of OSes we support that have chroot is not that long to make that impractical.

@joshtriplett

Copy link
Copy Markdown
Member Author

The list of OSes we support that have chroot is not that long to make that impractical.

I'm not arguing it would be impractical to list them today. I'm arguing that I'd like to not maintain a list with that polarity, adding one more place that every new not-broken platform has to update.

@RalfJung

Copy link
Copy Markdown
Member

These platforms aren't "broken", they just choose not to deliver more than what POSIX promises.

@RalfJung

RalfJung commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

We rightfully consider it bad practice when people use Rust in ways that aren't documented. Even if it happens to work, we will not necessarily keep that working in the future, and we consider it downstream's responsibility to ensure they are using Rust according to what we document. We should have the same standard for our own behavior towards our upstreams.

If we unilaterally assume things about upstream libraries they don't promise, we morally lose the right to do the same when our downstreams do the same to us. That's not the world I want to live in, that's not how we should interact with the rest of the ecosystem.

So IMO an allowlist is the only appropriate polarity here. That also gives us a natural place to document where the upstream guarantees for this behavior come from.

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

Labels

A-process Area: `std::process` (note: `std::env` is A-env) O-unix Operating system: Unix-like S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants