SebTardif opened PR #13816 from SebTardif:fix/wasi-stream-not-permitted to bytecodealliance:main:
Summary
read_via_stream,write_via_stream, andappend_via_streamreturnedErrorCode::BadDescriptorwhen the descriptor lacked the required read/write permission. The non-streamread/writepaths in the same module already returnNotPermittedfor the same condition.Why this change is needed
Permission denial should use the permission-denied error code.
BadDescriptormaps to a different condition (invalid/wrong kind of FD). Guests that branch onnot-permittedvsbad-descriptorcurrently get the wrong signal when opening a stream view on a file opened without the needed access.Change
Three sites in
crates/wasi/src/p2/host/filesystem.rs:- Err(types::ErrorCode::BadDescriptor)?; + Err(types::ErrorCode::NotPermitted)?;aligned with:
// async fn read / write if !f.perms.contains(FilePerms::READ/WRITE) { return Err(ErrorCode::NotPermitted.into()); }Testing
cargo check -p wasmtime-wasipasses.
SebTardif requested wasmtime-wasi-reviewers for a review on PR #13816.
SebTardif requested dicej for a review on PR #13816.
github-actions[bot] added the label wasi on PR #13816.
alexcrichton commented on PR #13816:
Thanks! Could you add a test for this as well?
alexcrichton requested alexcrichton for a review on PR #13816.
alexcrichton unassigned dicej from PR #13816 wasi: return NotPermitted for stream open permission failures.
SebTardif updated PR #13816.
SebTardif requested wasmtime-core-reviewers for a review on PR #13816.
SebTardif edited PR #13816:
Summary
read_via_stream,write_via_stream, andappend_via_streamreturnedErrorCode::BadDescriptorwhen the descriptor lacked the required read/write permission. The non-streamread/writepaths in the same module already returnNotPermittedfor the same condition.Why this change is needed
Permission denial should use the permission-denied error code.
BadDescriptormaps to a different condition (invalid/wrong kind of FD). Guests that branch onnot-permittedvsbad-descriptorcurrently get the wrong signal when opening a stream view on a file opened without the needed access.Change
Three sites in
crates/wasi/src/p2/host/filesystem.rs:- Err(types::ErrorCode::BadDescriptor)?; + Err(types::ErrorCode::NotPermitted)?;aligned with:
// async fn read / write if !f.perms.contains(FilePerms::READ/WRITE) { return Err(ErrorCode::NotPermitted.into()); }Testing
cargo test -p wasmtime-wasi --test all --features p2 p2_file_stream_not_permittedpasses (sync + async harness).- Guest program
p2_file_stream_not_permittedcovers:
- read-only preopen (
FilePerms::READ):write_via_stream/append_via_streamreturnErrorCode::NotPermitted;read_via_streamstill works.- write-only preopen (
FilePerms::WRITE):read_via_streamreturnsErrorCode::NotPermitted;write_via_streamstill works.
SebTardif commented on PR #13816:
@alexcrichton Added a focused test in
cbf77768a5:
- Guest:
crates/test-programs/src/bin/p2_file_stream_not_permitted.rs- Harness:
p2_file_stream_not_permittedin bothcrates/wasi/tests/all/p2/sync.rsandasync_.rsIt asserts
ErrorCode::NotPermittedforwrite_via_stream/append_via_streamunder a read-only preopen and forread_via_streamunder a write-only preopen (while the allowed stream path still succeeds).Verified locally with:
cargo test -p wasmtime-wasi --test all --features p2 p2_file_stream_not_permitted # 2 passed (sync + async)
:thumbs_up: alexcrichton submitted PR review.
alexcrichton added PR #13816 wasi: return NotPermitted for stream open permission failures to the merge queue.
:check: alexcrichton merged PR #13816.
alexcrichton removed PR #13816 wasi: return NotPermitted for stream open permission failures from the merge queue.
Last updated: Jul 29 2026 at 05:03 UTC