Repository navigation
Stabilize std::os::unix::process::CommandExt::chroot (process_chroot) - #163067
joshtriplett wants to merge 1 commit into
Conversation
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
This has been around since May 2025, without issue. I think it's more than ready to stabilize. Shall we stabilize it? @rfcbot merge libs |
|
@joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/libs-ping: FCP proposed for libs, please feel free to register concerns. |
|
Are there any test cases for this? I don't think I see any in the original PR (#137759) or in grep for chroot in our code. I guess we'd need to condition such a test case on being able to run privileged, but I think in CI we can, so it seems valuable. Absent those, have we confirmed this actually works at least manually? The os::unix::fs::chroot API is documented as:
I assume the same applies here? Can we amend the documentation to note that? That API is also cfg'd away on fuchsia, instead of returning Unsupported like the process one. I assume we want to go with Unsupported as implemented here (and on slightly more targets - fuchsia, vxworks, wasi)? |
|
If you use the unshare syscall you can use chroot without needing to run as root (on Linux). |
|
In addition to the missing tests, there are no examples. They'll have to be |
|
I want to point out that |
|
fwiw, the docs should probably also mention that - strictly speaking - this function is not documented to be async-signal-safe, and we should link to the docs of chroot. otherwise seems good per today's meeting ^^ |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
We have requests for tests (if possible), examples, and improved documentation. I think that's all worth a blocking concern, if anybody is willing to raise one on my behalf. |
|
@rfcbot concern tests, examples and improved documentation |
|
I've posted #163180 to update the documentation. That PR adds an example, adds a manpage link, adds a mention that it requires privileges, and adds an explanation that POSIX doesn't require it to be async-signal-safe but it's safe in practice on our targets. I don't think a runnable test is feasible; our testsuite shouldn't be run as root. On Linux specifically, we could theoretically provide a test that runs via |
I think if we're going to add root-only APIs to std, we should have a test suite that does require root and runs as such. It seems easy to do that in CI. Infra work for that should be pretty trivial. |
|
At the end of the day it is a fairly trivial wrapper around |
Note that this is an issue 8 doc, but However, as far as I can tell, no popular platform's manpages say this is safe to do, e.g. https://man7.org/linux/man-pages/man2/chroot.2.html makes no mention and https://man7.org/linux/man-pages/man7/signal-safety.7.html only describes POSIX. Are we actually comfortable enabling this code unconditionally if it might be completely broken? I'm hesitant to take pervasiveness of a pattern in C on some platforms as truth that this will be sound on all platforms that have a It seems safer to start with Linux and a few other popular platforms that we can confirm are sound, error on spawn otherwise. And leave it up to target maintainers to enable other platforms if they can confirm soundness. Ideally by updating their documentation...
We could also totally forget to actually call |
|
To be clear, I see no reason why we can't sudo in CI specifically (though probably best not to do that locally) but if we just want to make sure that |
|
There is also the I would advise using that, at least on targets where we do definitely call out to libc for all relevant file operations. |
|
Also for docs, I think this was brought up in the meeting but worth restating publicly here that the docs should specify that it's not actually a security boundary and it's possible to e.g. access directories outside of the chroot ^^ |
|
^ agreed, requested at #163180 (comment) |
|
#163180 should address the documentation and example concern. |
Add more documentation for `chroot`, including an example and a manpage link As requested in rust-lang#163067 . This adds an example, adds a manpage link, adds a mention that it requires privileges, and adds an explanation that POSIX doesn't *require* it to be async-signal-safe but it's safe in practice on our targets.
Add more documentation for `chroot`, including an example and a manpage link As requested in rust-lang#163067 . This adds an example, adds a manpage link, adds a mention that it requires privileges, and adds an explanation that POSIX doesn't *require* it to be async-signal-safe but it's safe in practice on our targets.
Rollup merge of #163180 - joshtriplett:chroot-docs, r=tgross35 Add more documentation for `chroot`, including an example and a manpage link As requested in #163067 . This adds an example, adds a manpage link, adds a mention that it requires privileges, and adds an explanation that POSIX doesn't *require* it to be async-signal-safe but it's safe in practice on our targets.
|
☔ The latest upstream changes (presumably #164673) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
|
I'm happy for the concern to be resolved, assuming @tgross35 is also happy |
We should at least attempt to communicate with upstream about this. Unilaterally assuming a non-guaranteed behavior is not nice. We don't want others to do that with Rust. We should hence not do it to others. |
Add more documentation for `chroot`, including an example and a manpage link As requested in rust-lang/rust#163067 . This adds an example, adds a manpage link, adds a mention that it requires privileges, and adds an explanation that POSIX doesn't *require* it to be async-signal-safe but it's safe in practice on our targets.
Add more documentation for `chroot`, including an example and a manpage link As requested in rust-lang/rust#163067 . This adds an example, adds a manpage link, adds a mention that it requires privileges, and adds an explanation that POSIX doesn't *require* it to be async-signal-safe but it's safe in practice on our targets.
Add more documentation for `chroot`, including an example and a manpage link As requested in rust-lang/rust#163067 . This adds an example, adds a manpage link, adds a mention that it requires privileges, and adds an explanation that POSIX doesn't *require* it to be async-signal-safe but it's safe in practice on our targets.
That doesn't make it less unilateral (as in, without involving the other side that is party to this behavior contract).
We should reference those receipts. (My understanding is that musl allows pretty much the entire libc to be used after fork so that does not point towards |
|
Maybe we should return an unsupported error on platforms where it's not async-signal-safe? Then the docs can more strongly assert safety. |
|
glibc, musl, macos libc, and bionic all seem to implement |
|
Based on some (LLM-assisted) review, chroot-after-fork is safe on every target except cygwin and QNX. For QNX, it's explicitly documented as not safe. In QNX 7.1 it appears to be safe regardless, in the default configuration; however, it's not safe in a non-default configuration that allows allocating on the heap when there isn't enough stack. For Cygwin, chroot itself seems to be safe, but there may be a bug in the interaction between chdir and fork, where fork can pick up a partially updated chdir in progress. (That should be fixable, though.) I'll make it unconditionally error on those two platforms; we can stop erroring on cygwin if that bug gets fixed, and we can stop erroring on QNX if they'd like to update their documentation to allow chroot-after-fork. |
|
There's still a difference between "the current implementation is async-signal-safe" and "it'll remain async-signal-safe in the future". For macOS it's probably hopeless, but for the other libc we could reach out to maintainers to ask them if it's reasonable to rely on chroot being async-signal-safe. |
|
Solaris and Illumos explicitly document it as safe. We could poke *BSD folks and bionic folks. Note that on all of these targets (except Cygwin, which I've excluded here), it's just a direct syscall, and there's no good reason for it to be anything other than a direct syscall in the future. If it stopped working, that would be an OS bug affecting far more than just us. That said: Android: @chriswailes @jfgoog @maurer @pirama-arumuga-nainar Any concerns that |
|
I've posted #166378 to fail process spawn if chroot is set on QNX or Cygwin. |
|
Could we flip the logic so we error by default on all unconfirmed platforms, rather than allow by default? Then target maintainers can update as needed and we can move this forward without trying to check every target off a list. |
View all comments
Tracking issue: #141298