Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fd_fdstat_set_rights does not error when attempting to add rights to stdin/out/err #7051

Closed
yagehu opened this issue Sep 15, 2023 · 1 comment
Labels
bug Incorrect behavior in the current implementation that needs fixing

Comments

@yagehu
Copy link

yagehu commented Sep 15, 2023

Test Case

(module
  (type (;0;) (func (param i32 i64 i64) (result i32)))
  (type (;1;) (func))
  (type (;2;) (func (param i32)))
  (import "wasi_snapshot_preview1" "fd_fdstat_set_rights" (func $fd_fdstat_set_rights (type 0)))
  (import "wasi_snapshot_preview1" "proc_exit" (func $proc_exit (type 2)))
  (func $_start (type 1)
    i32.const 0
    i64.const 3
    i64.const 3
    call $fd_fdstat_set_rights
    call $proc_exit
  )
  (memory (;0;) 1)
  (export "memory" (memory 0))
  (export "_start" (func $_start))
)

Steps to Reproduce

Run the above WAT code with Wasmtime and print the error code. For example:

wasmtime a.wat; echo $?

Expected Results

stdin (fd value 0) starts with a fs_rights_base value of 2 (read). The above WAT snippet attempts to add a right to it by setting it to 3 (read + seek).

According the preview1 spec for fd_fdstat_set_rights:

Adjust the rights associated with a file descriptor. This can only be used to remove rights, and returns errno::notcapable if called in a way that would attempt to add rights

So the expected exit status is 76 (notcapable).

Actual Results

The snippet exits with errno 0.

Versions and Environment

Wasmtime version or commit: v12.0.2

Operating system: Mac OSX Ventura 13.5.2

Architecture: amd64

Extra Info

This is not a security vulnerability because, in my limited testing, the right does not actually get updated.

@yagehu yagehu added the bug Incorrect behavior in the current implementation that needs fixing label Sep 15, 2023
@alexcrichton
Copy link
Member

Thanks for the report! The rights system has been removed from Wasmtime however in preparation of the removal of rights in WASI preview 2. That means that the documentation of preview1 is probably a bit out of date since it theoretically should be updated to mention this, but development work is centered around preview2 at this time instead of preview1.

Since this is intended behavior though I'm going to go ahead and close this, but I can reopen if there are other questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior in the current implementation that needs fixing
Projects
None yet
Development

No branches or pull requests

2 participants