release-45.0.0: Fix wasmtime-wasi path_open(TRUNCATE) bypass of FilePerms::WRITE check#13430
Merged
pchickey merged 4 commits intoMay 21, 2026
Conversation
In wasmtime-wasi, when a filesystem preopen is given DirPerms::all() and FilePerms::READ without FilePerms::WRITE, this wasmtime-wasi enforced access control mechanism can be bypassed by using the wasip2 descriptor.open-at or wasip1 path_open interfaces by opening a file with OpenFlags::TRUNCATE oflag only, for example:
```rust
dir_descriptor.open_at(
PathFlags::empty(),
FILENAME,
OpenFlags::TRUNCATE,
DescriptorFlags::READ,
)
```
or
```rust
wasip1::path_open(
dir_fd,
0,
FILENAME,
wasip1::OFLAGS_TRUNC,
wasip1::RIGHTS_FD_READ,
0,
0
)
```
The root cause is that the clause that considered OpenFlags::TRUNCATE did not set open_mode |= OpenMode::WRITE;, used later in that function for the access control check against FilePerms for whether opening that file is permitted. With the bug corrected, these calls to open-at and path_open fail with error-code.not-permitted and ERRNO_PERM respectively.
This commit contains the fix for the above bug, and tests for the fix.
dicej
approved these changes
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a backport of #13429 to the 45.0.0 release branch.
Details
In
wasmtime-wasi, when a filesystem preopen is givenDirPerms::all()andFilePerms::READwithoutFilePerms::WRITE, this wasmtime-wasi enforced access control mechanism can be bypassed by using the wasip2descriptor.open-ator wasip1path_openinterfaces by opening a file withOpenFlags::TRUNCATEoflag only, for example:The root cause is that the clause that considered
OpenFlags::TRUNCATEdid not setopen_mode |= OpenMode::WRITE;, used later in that function for the access control check againstFilePermsfor whether opening that file is permitted. With the bug corrected, these calls toopen-atandpath_openfail witherror-code.not-permittedandERRNO_PERMrespectively.The bug in
crates/wasi/src/filesystem.rs,Dir::open_at, lines 967–969:and the single line fix is:
Only wasmtime-wasi embeddings that use a combination of DirPerms::MUTATE with FilePerms::READ are affected by this bug, e.g. those that use in the
WasiCtxBuilder:In particular, the Wasmtime project's
wasmtime-cli's use of wasmtime-wasi is not affected, because it always setsFilePerms::all()for all preopens.