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

Should not be able to path_open directory with rights::fd_write #4766

Closed
yagehu opened this issue May 30, 2024 · 1 comment · Fixed by #4794
Closed

Should not be able to path_open directory with rights::fd_write #4766

yagehu opened this issue May 30, 2024 · 1 comment · Fixed by #4794
Assignees
Labels
bug Something isn't working 📦 lib-vfs About wasmer-vfs

Comments

@yagehu
Copy link
Contributor

yagehu commented May 30, 2024

Describe the bug

Calling path_open on a directory with the fd_write right should fail with isdir. This behavior is consistent among other runtimes (Wasmtime, WasmEdge, Wazero, WAMR, Node). Wasmer however successfully opens the directory.

wasmer -vV; rustc -vV
wasmer 4.3.1 (b986b4a 2024-05-28)
binary: wasmer-cli
commit-hash: b986b4a0faa56a30daa3554feff29e191849da65
commit-date: 2024-05-28
host: x86_64-apple-darwin
compiler: singlepass,cranelift
rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-apple-darwin
release: 1.78.0
LLVM version: 18.1.2

Steps to reproduce

Compile this minimum example with wasi crate v0.11 (for preview1 API).

fn main() {
    unsafe {
        let fd = wasi::path_open(
            5,
            0,
            ".",
            0,
            wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE,
            0,
            0,
        )
        .unwrap();

        eprintln!("fd: {fd}");
    }
}
@maminrayej maminrayej self-assigned this May 31, 2024
@maminrayej maminrayej added bug Something isn't working 📦 lib-vfs About wasmer-vfs labels May 31, 2024
@maminrayej
Copy link
Contributor

I tried fixing the behavior by adding this condition to path_open_internal:

if let Kind::Dir { .. } = *working_dir.inode.kind.read().unwrap() {
    if adjusted_rights.contains(Rights::FD_WRITE) {
        return Ok(Err(Errno::Isdir));
    }
}

But it breaks other things unfortunately.

cc @syrusakbary

yagehu added a commit to yagehu/wasmer that referenced this issue Jun 4, 2024
This commit changes `path_open` such that opening an existing directory
with the `rights::fd_write` flag set returns an error `isdir`.  This
behavior is consistent with other runtimes.

fixes wasmerio#4766
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 📦 lib-vfs About wasmer-vfs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants