Skip to content

wasi: return NotPermitted for stream open permission failures#13816

Open
SebTardif wants to merge 1 commit into
bytecodealliance:mainfrom
SebTardif:fix/wasi-stream-not-permitted
Open

wasi: return NotPermitted for stream open permission failures#13816
SebTardif wants to merge 1 commit into
bytecodealliance:mainfrom
SebTardif:fix/wasi-stream-not-permitted

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

Summary

read_via_stream, write_via_stream, and append_via_stream returned ErrorCode::BadDescriptor when the descriptor lacked the required read/write permission. The non-stream read / write paths in the same module already return NotPermitted for the same condition.

Why this change is needed

Permission denial should use the permission-denied error code. BadDescriptor maps to a different condition (invalid/wrong kind of FD). Guests that branch on not-permitted vs bad-descriptor currently 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-wasi passes.

read_via_stream, write_via_stream, and append_via_stream returned
BadDescriptor when the descriptor lacked read/write perms. The non-stream
read/write paths already return NotPermitted for the same condition.

Use NotPermitted for consistency with those siblings and the WASI
permission-denied mapping used elsewhere in this module.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
@SebTardif SebTardif requested a review from a team as a code owner July 4, 2026 13:10
@SebTardif SebTardif requested review from dicej and removed request for a team July 4, 2026 13:10
@github-actions github-actions Bot added the wasi Issues pertaining to WASI label Jul 4, 2026
@alexcrichton

Copy link
Copy Markdown
Member

Thanks! Could you add a test for this as well?

@alexcrichton alexcrichton requested review from alexcrichton and removed request for dicej July 6, 2026 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasi Issues pertaining to WASI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants