Stream: git-wasmtime

Topic: wasmtime / issue #5568 Large wasi::Rights causes wasmtime...


view this post on Zulip Wasmtime GitHub notifications bot (Jan 13 2023 at 03:12):

zzjas opened issue #5568:

Test Case

Using a large value for wasi::Rights will cause wasmtime to crash when calling wasi::path_open.

main.rs

use wasi::path_open;
fn main() {
    let fd = 3;
    let path = "hello.txt";
    let dirflags: wasi::Lookupflags = 1774447679;
    let oflags: wasi::Oflags = 49784;
    let fs_rights_base: wasi::Rights = 18446744073709551615;
    let fs_rights_inheriting: wasi::Rights = 18446744073709551615;
    let fdflags: wasi::Fdflags = 32796;
    dbg!(fd);
    dbg!(path);
    dbg!(dirflags);
    dbg!(oflags);
    dbg!(fs_rights_base);
    dbg!(fs_rights_inheriting);
    dbg!(fdflags);

    unsafe {
        let result = path_open(fd, dirflags, path, oflags, fs_rights_base, fs_rights_inheriting, fdflags);
        match result {
            Ok(fd) => {
                println!("path_open success: fd={}", fd);
            },
            Err(err) => {
                println!("path_open failed: err={}", err);
            }
        }
    }
}

Cargo.toml

[dependencies]
wasi = "0.11.0"

Steps to Reproduce

cargo wasi run
or
cargo wasi build
wasmtime target/wasm32-wasi/debug/XXX.wasm

Expected Results

An error result should be returned.

Actual Results

Wasmtime will crash

Caused by:
    0: failed to invoke command default
    1: error while executing at wasm backtrace:
           0: 0xc711 - <unknown>!wasi::lib_generated::path_open::hb8ad89a8b9dd6908
           1: 0x2e53 - <unknown>!wasi_debug::main::hfe8a12f5eb42481b
           2: 0x10d7d - <unknown>!core::ops::function::FnOnce::call_once::hd5eb0775b8968135
           3: 0x10d49 - <unknown>!std::sys_common::backtrace::__rust_begin_short_backtrace::h8904312c549ad001
           4: 0xfaa0 - <unknown>!std::rt::lang_start::{{closure}}::h0623c4993ae93fcd
           5: 0x8801 - <unknown>!std::rt::lang_start_internal::hc0c970460a4ce6d4
           6: 0xf2d3 - <unknown>!std::rt::lang_start::h0bf5df21c7abc364
           7: 0x10fb4 - <unknown>!__main_void
           8: 0x10e77 - <unknown>!_start
       note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable to may show more debugging information
    2: In func wasi_snapshot_preview1::path_open at convert Rights: Int conversion error: TryFromIntError(())
    3: Int conversion error: TryFromIntError(())
    4: out of range integral type conversion attempted

Versions and Environment

Wasmtime version or commit: cbeec5ddb929e1c6e77f19731e4e3cf1bc9817d0

Operating system: Arch Linux 6.0.1-arch2-1

Architecture: x86-64

Extra Info

While the large value for wasi::Rights is not useful, we are not sure if the crash is intended or a bug. We ran the same test with some other runtimes (wasmer, wamr, wavm) and they returned an Err in this case.

We appreciate your help in looking into this!

view this post on Zulip Wasmtime GitHub notifications bot (Jan 13 2023 at 03:12):

zzjas labeled issue #5568:

Test Case

Using a large value for wasi::Rights will cause wasmtime to crash when calling wasi::path_open.

main.rs

use wasi::path_open;
fn main() {
    let fd = 3;
    let path = "hello.txt";
    let dirflags: wasi::Lookupflags = 1774447679;
    let oflags: wasi::Oflags = 49784;
    let fs_rights_base: wasi::Rights = 18446744073709551615;
    let fs_rights_inheriting: wasi::Rights = 18446744073709551615;
    let fdflags: wasi::Fdflags = 32796;
    dbg!(fd);
    dbg!(path);
    dbg!(dirflags);
    dbg!(oflags);
    dbg!(fs_rights_base);
    dbg!(fs_rights_inheriting);
    dbg!(fdflags);

    unsafe {
        let result = path_open(fd, dirflags, path, oflags, fs_rights_base, fs_rights_inheriting, fdflags);
        match result {
            Ok(fd) => {
                println!("path_open success: fd={}", fd);
            },
            Err(err) => {
                println!("path_open failed: err={}", err);
            }
        }
    }
}

Cargo.toml

[dependencies]
wasi = "0.11.0"

Steps to Reproduce

cargo wasi run
or
cargo wasi build
wasmtime target/wasm32-wasi/debug/XXX.wasm

Expected Results

An error result should be returned.

Actual Results

Wasmtime will crash

Caused by:
    0: failed to invoke command default
    1: error while executing at wasm backtrace:
           0: 0xc711 - <unknown>!wasi::lib_generated::path_open::hb8ad89a8b9dd6908
           1: 0x2e53 - <unknown>!wasi_debug::main::hfe8a12f5eb42481b
           2: 0x10d7d - <unknown>!core::ops::function::FnOnce::call_once::hd5eb0775b8968135
           3: 0x10d49 - <unknown>!std::sys_common::backtrace::__rust_begin_short_backtrace::h8904312c549ad001
           4: 0xfaa0 - <unknown>!std::rt::lang_start::{{closure}}::h0623c4993ae93fcd
           5: 0x8801 - <unknown>!std::rt::lang_start_internal::hc0c970460a4ce6d4
           6: 0xf2d3 - <unknown>!std::rt::lang_start::h0bf5df21c7abc364
           7: 0x10fb4 - <unknown>!__main_void
           8: 0x10e77 - <unknown>!_start
       note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable to may show more debugging information
    2: In func wasi_snapshot_preview1::path_open at convert Rights: Int conversion error: TryFromIntError(())
    3: Int conversion error: TryFromIntError(())
    4: out of range integral type conversion attempted

Versions and Environment

Wasmtime version or commit: cbeec5ddb929e1c6e77f19731e4e3cf1bc9817d0

Operating system: Arch Linux 6.0.1-arch2-1

Architecture: x86-64

Extra Info

While the large value for wasi::Rights is not useful, we are not sure if the crash is intended or a bug. We ran the same test with some other runtimes (wasmer, wamr, wavm) and they returned an Err in this case.

We appreciate your help in looking into this!

view this post on Zulip Wasmtime GitHub notifications bot (Jan 13 2023 at 15:20):

alexcrichton commented on issue #5568:

Thanks for the report, but this is expected. The WASI spec does not strictly say what should happen on invalid rights/etc and in the future with the component model this will be a trap, so Wasmtime implements this as a trap. Note that this isn't Wasmtime crashing, it's just a normal trap being raised from a host call.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 13 2023 at 15:20):

alexcrichton closed issue #5568:

Test Case

Using a large value for wasi::Rights will cause wasmtime to crash when calling wasi::path_open.

main.rs

use wasi::path_open;
fn main() {
    let fd = 3;
    let path = "hello.txt";
    let dirflags: wasi::Lookupflags = 1774447679;
    let oflags: wasi::Oflags = 49784;
    let fs_rights_base: wasi::Rights = 18446744073709551615;
    let fs_rights_inheriting: wasi::Rights = 18446744073709551615;
    let fdflags: wasi::Fdflags = 32796;
    dbg!(fd);
    dbg!(path);
    dbg!(dirflags);
    dbg!(oflags);
    dbg!(fs_rights_base);
    dbg!(fs_rights_inheriting);
    dbg!(fdflags);

    unsafe {
        let result = path_open(fd, dirflags, path, oflags, fs_rights_base, fs_rights_inheriting, fdflags);
        match result {
            Ok(fd) => {
                println!("path_open success: fd={}", fd);
            },
            Err(err) => {
                println!("path_open failed: err={}", err);
            }
        }
    }
}

Cargo.toml

[dependencies]
wasi = "0.11.0"

Steps to Reproduce

cargo wasi run
or
cargo wasi build
wasmtime target/wasm32-wasi/debug/XXX.wasm

Expected Results

An error result should be returned.

Actual Results

Wasmtime will crash

Caused by:
    0: failed to invoke command default
    1: error while executing at wasm backtrace:
           0: 0xc711 - <unknown>!wasi::lib_generated::path_open::hb8ad89a8b9dd6908
           1: 0x2e53 - <unknown>!wasi_debug::main::hfe8a12f5eb42481b
           2: 0x10d7d - <unknown>!core::ops::function::FnOnce::call_once::hd5eb0775b8968135
           3: 0x10d49 - <unknown>!std::sys_common::backtrace::__rust_begin_short_backtrace::h8904312c549ad001
           4: 0xfaa0 - <unknown>!std::rt::lang_start::{{closure}}::h0623c4993ae93fcd
           5: 0x8801 - <unknown>!std::rt::lang_start_internal::hc0c970460a4ce6d4
           6: 0xf2d3 - <unknown>!std::rt::lang_start::h0bf5df21c7abc364
           7: 0x10fb4 - <unknown>!__main_void
           8: 0x10e77 - <unknown>!_start
       note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable to may show more debugging information
    2: In func wasi_snapshot_preview1::path_open at convert Rights: Int conversion error: TryFromIntError(())
    3: Int conversion error: TryFromIntError(())
    4: out of range integral type conversion attempted

Versions and Environment

Wasmtime version or commit: cbeec5ddb929e1c6e77f19731e4e3cf1bc9817d0

Operating system: Arch Linux 6.0.1-arch2-1

Architecture: x86-64

Extra Info

While the large value for wasi::Rights is not useful, we are not sure if the crash is intended or a bug. We ran the same test with some other runtimes (wasmer, wamr, wavm) and they returned an Err in this case.

We appreciate your help in looking into this!


Last updated: Oct 23 2024 at 20:03 UTC