Skip to content

[36.0.x] Vendor cap-std/cap-primitives into wasmtime-wasi - #14224

Open
alexcrichton wants to merge 3 commits into
bytecodealliance:release-36.0.0from
alexcrichton:primitives36
Open

[36.0.x] Vendor cap-std/cap-primitives into wasmtime-wasi#14224
alexcrichton wants to merge 3 commits into
bytecodealliance:release-36.0.0from
alexcrichton:primitives36

Conversation

@alexcrichton

Copy link
Copy Markdown
Member

This is the equivalent of #14219 for the 36.0.x release branch which we'll be supporting for another year. The goal here is to ensure that fixing security issues in the filesystem sandbox is in theory a purely local change within Wasmtime like it would be on main to avoid having to both change main and additionally change published cap-std crates.

The backport here is much more involved than just cherry-picking #14219 to this branch. As described in the second commit this historical version of Wasmtime is missing major refactorings such as moving away from cap-std and the refactoring of filesystem internals across wasip2 and wasip3. This means that while the primitives directory is directly cherry-picked from #14219 the rest of this is basically hand-written. This hand-vendors more platform-specific modules from main and wires everything up.

To add another wrinkle to all of this the cap-std crate is visible in the public API of wasmtime-wasi to a greater degree than it is on main. For example the Descriptor type has file and dir methods which expose the underlying File and Dir structures of wasmtime-wasi which have pub fields which are cap_std::fs::{File,Dir} types. It would be a semver-breaking change, technically, to change these to std::fs::File as is present on main. To handle this those parts are left as-is but all operations are done internally as std::fs::File. The intention is that all sandboxing logic lives within the local primitives module.

Copy the entire contents of this crate into
`crates/wasi/src/filesystem/primitives` for future modifications to get
it building.
This commit adjust the wasmtime 36.0.0 state of the `wasmtime-wasi`
crate to use the vendored primitives in the prior commit. This is much
more involved than just a cherry-pick because the internals of
`wasmtime-wasi` have greatly changed since the 36.0.0 release, namely:

* WASIp3 support was added and shared code between p2/p3 was refactored
  to its own module.
* The `cap-std` dependency was largely removed which vendored some
  fringe platform-specific code from that and surrounding crates.

These major changes aren't present on the 36.0.0 branch, and
additionally the public types of `wasmtime-wasi` contain more `cap_std`
types than before. To handle all of this the commit here leaves the
public type definitions as-is but helpers internally all switch to using
the previously-vendored primitives. This involved vendoring more code
from the `main` branch and is a bit invasive, but this is all necessary
to sever dependencies with the `cap-std` crates.
@github-actions github-actions Bot added wasi Issues pertaining to WASI wasmtime:docs Issues related to Wasmtime's documentation labels Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasi Issues pertaining to WASI wasmtime:docs Issues related to Wasmtime's documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants