Repository navigation
Don't allow chroot-after-fork on Cygwin or QNX - #166378
joshtriplett wants to merge 1 commit into
Conversation
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.
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
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. |
|
@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. |
|
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. |
|
These platforms aren't "broken", they just choose not to deliver more than what POSIX promises. |
|
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. |
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.