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_advise on invalid file descriptors report ok #4554

Closed
yagehu opened this issue Apr 11, 2024 · 0 comments · Fixed by #4555
Closed

fd_advise on invalid file descriptors report ok #4554

yagehu opened this issue Apr 11, 2024 · 0 comments · Fixed by #4555

Comments

@yagehu
Copy link
Contributor

yagehu commented Apr 11, 2024

Describe the bug

Calling fd_advise on a clearly invalid file descriptor returns 0 in all conditions.

Minimal Rust repro:

use wasi::ADVICE_WILLNEED;

fn main() {
    unsafe {
        let result = wasi::fd_advise(6, 0, 0, ADVICE_WILLNEED);

        match result {
            Ok(()) => eprintln!("fd_advise ok"),
            Err(errno) => eprintln!("fd_advise failed with {errno}"),
        }
    }
}
$ cargo build --target wasm32-wasi
$ wasmer -vV; rustc -vV
wasmer 4.2.5 (0460050 2024-03-05)
binary: wasmer-cli
commit-hash: 04600507844bae978239531c8e6265d410aefe6d
commit-date: 2024-03-05
host: x86_64-unknown-linux-gnu
compiler: singlepass,cranelift
rustc 1.77.1 (7cf61ebde 2024-03-27)
binary: rustc
commit-hash: 7cf61ebde7b22796c69757901dd346d0fe70bd97
commit-date: 2024-03-27
host: x86_64-unknown-linux-gnu
release: 1.77.1
LLVM version: 17.0.6

Steps to reproduce

Run the above Rust snippet compiled to wasm32-wasi. It should output fd_advise failed with <errno>, but it reports fd_advise ok.

Expected behavior

When the fd is invalid, like a random or very large number, fd_advise should report something like ebadf.

Actual behavior

fd_advise returns ok (0) in all cases.

Additional context

This was uncovered in differential fuzzing between Wasmer and other Wasm/WASI runtimes. I have a simple PR to fix this behavior.

yagehu added a commit to yagehu/wasmer that referenced this issue Apr 11, 2024
This commit fixes `fd_advise` unconditionally returning ok (0) on all
inputs.  The details are discussed in issue wasmerio#4554.
yagehu added a commit to yagehu/wasmer that referenced this issue Apr 12, 2024
This commit fixes `fd_advise` unconditionally returning ok (0) on all
inputs.  The details are discussed in issue wasmerio#4554.
theduke pushed a commit to yagehu/wasmer that referenced this issue Apr 15, 2024
This commit fixes `fd_advise` unconditionally returning ok (0) on all
inputs.  The details are discussed in issue wasmerio#4554.
theduke pushed a commit that referenced this issue Apr 15, 2024
This commit fixes `fd_advise` unconditionally returning ok (0) on all
inputs.  The details are discussed in issue #4554.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant