Stream: git-wasmtime

Topic: wasmtime / issue #3321 wasmtime crashed on wasi_config_in...


view this post on Zulip Wasmtime GitHub notifications bot (Sep 09 2021 at 08:13):

spacewander opened issue #3321:

Test Case

Steps to Reproduce

When I try to integrate wasmtime to my host program written in C, the program crashed during executing

    vm_wasi_config = wasi_config_new();
    if (vm_wasi_config == NULL) {
        goto ...;
    }

    wasi_config_inherit_argv(vm_wasi_config); /* <- this line! */

The bt is:

#0  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:65
#1  0x00007ff7c2b4ee69 in std::ffi::c_str::CStr::from_ptr () at library/std/src/ffi/c_str.rs:1174
#2  std::sys::unix::args::imp::clone::{{closure}} () at library/std/src/sys/unix/args.rs:147
#3  core::iter::adapters::map::map_fold::{{closure}} () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/adapters/map.rs:82
#4  core::iter::traits::iterator::Iterator::fold () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:2112
#5  <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/adapters/map.rs:122
#6  core::iter::traits::iterator::Iterator::for_each () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:736
#7  <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_extend.rs:40
#8  <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_from_iter_nested.rs:56
#9  <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_from_iter.rs:33
#10 <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/mod.rs:2449
#11 core::iter::traits::iterator::Iterator::collect () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:1748
#12 std::sys::unix::args::imp::clone () at library/std/src/sys/unix/args.rs:145
#13 std::sys::unix::args::imp::args () at library/std/src/sys/unix/args.rs:137
#14 std::sys::unix::args::args () at library/std/src/sys/unix/args.rs:24
#15 std::env::args_os () at library/std/src/env.rs:780
#16 0x00007ff7c2b4ecf1 in std::env::args () at library/std/src/env.rs:745
#17 0x00007ff7c2578112 in wasi_cap_std_sync::WasiCtxBuilder::inherit_args () at library/std/src/panicking.rs:541
#18 0x00007ff7c24cff55 in wasmtime::wasi::wasi_config_t::into_wasi_ctx () at library/std/src/panicking.rs:541
#19 0x00007ff7c241a92a in wasmtime_context_set_wasi () at library/std/src/panicking.rs:541
#20 0x000000000068c766 in ...

My CPU has avx2 support:

grep avx2 /proc/cpuinfo
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves flush_l1d arch_capabilities
...

It only happened when the argv of the program is not empty.

Expected Results

Run successfully

Actual Results

Segfault on wasi_config_inherit_argv

Versions and Environment

Wasmtime version or commit: v0.29.0

Operating system: Linux run on WSL

Architecture: x64

Extra Info

view this post on Zulip Wasmtime GitHub notifications bot (Sep 09 2021 at 08:13):

spacewander labeled issue #3321:

Test Case

Steps to Reproduce

When I try to integrate wasmtime to my host program written in C, the program crashed during executing

    vm_wasi_config = wasi_config_new();
    if (vm_wasi_config == NULL) {
        goto ...;
    }

    wasi_config_inherit_argv(vm_wasi_config); /* <- this line! */

The bt is:

#0  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:65
#1  0x00007ff7c2b4ee69 in std::ffi::c_str::CStr::from_ptr () at library/std/src/ffi/c_str.rs:1174
#2  std::sys::unix::args::imp::clone::{{closure}} () at library/std/src/sys/unix/args.rs:147
#3  core::iter::adapters::map::map_fold::{{closure}} () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/adapters/map.rs:82
#4  core::iter::traits::iterator::Iterator::fold () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:2112
#5  <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/adapters/map.rs:122
#6  core::iter::traits::iterator::Iterator::for_each () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:736
#7  <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_extend.rs:40
#8  <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_from_iter_nested.rs:56
#9  <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_from_iter.rs:33
#10 <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/mod.rs:2449
#11 core::iter::traits::iterator::Iterator::collect () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:1748
#12 std::sys::unix::args::imp::clone () at library/std/src/sys/unix/args.rs:145
#13 std::sys::unix::args::imp::args () at library/std/src/sys/unix/args.rs:137
#14 std::sys::unix::args::args () at library/std/src/sys/unix/args.rs:24
#15 std::env::args_os () at library/std/src/env.rs:780
#16 0x00007ff7c2b4ecf1 in std::env::args () at library/std/src/env.rs:745
#17 0x00007ff7c2578112 in wasi_cap_std_sync::WasiCtxBuilder::inherit_args () at library/std/src/panicking.rs:541
#18 0x00007ff7c24cff55 in wasmtime::wasi::wasi_config_t::into_wasi_ctx () at library/std/src/panicking.rs:541
#19 0x00007ff7c241a92a in wasmtime_context_set_wasi () at library/std/src/panicking.rs:541
#20 0x000000000068c766 in ...

My CPU has avx2 support:

grep avx2 /proc/cpuinfo
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves flush_l1d arch_capabilities
...

It only happened when the argv of the program is not empty.

Expected Results

Run successfully

Actual Results

Segfault on wasi_config_inherit_argv

Versions and Environment

Wasmtime version or commit: v0.29.0

Operating system: Linux run on WSL

Architecture: x64

Extra Info

view this post on Zulip Wasmtime GitHub notifications bot (Sep 09 2021 at 08:21):

spacewander commented on issue #3321:

I also notice a crash without wasi_config_inherit_argv:

#0  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:65
#1  0x00007fbc04ec1e69 in std::ffi::c_str::CStr::from_ptr () at library/std/src/ffi/c_str.rs:1174
#2  std::sys::unix::args::imp::clone::{{closure}} () at library/std/src/sys/unix/args.rs:147
#3  core::iter::adapters::map::map_fold::{{closure}} () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/adapters/map.rs:82
#4  core::iter::traits::iterator::Iterator::fold () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:2112
#5  <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/adapters/map.rs:122
#6  core::iter::traits::iterator::Iterator::for_each () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:736
#7  <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_extend.rs:40
#8  <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_from_iter_nested.rs:56
#9  <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_from_iter.rs:33
#10 <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/mod.rs:2449
#11 core::iter::traits::iterator::Iterator::collect () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:1748
#12 std::sys::unix::args::imp::clone () at library/std/src/sys/unix/args.rs:145
#13 std::sys::unix::args::imp::args () at library/std/src/sys/unix/args.rs:137
#14 std::sys::unix::args::args () at library/std/src/sys/unix/args.rs:24
#15 std::env::args_os () at library/std/src/env.rs:780
#16 0x00007fbc04ec1cf1 in std::env::args () at library/std/src/env.rs:745
#17 0x00007fbc048eb112 in wasi_cap_std_sync::WasiCtxBuilder::inherit_args () at library/std/src/panicking.rs:541
#18 0x00007fbc04842f55 in wasmtime::wasi::wasi_config_t::into_wasi_ctx () at library/std/src/panicking.rs:541
#19 0x00007fbc0478d92a in wasmtime_context_set_wasi () at library/std/src/panicking.rs:541
#20 0x000000000068c706 in

Same bt but starts from error = wasmtime_context_set_wasi(context, vm_wasi_config);, happened only with argv is given.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 09 2021 at 08:26):

spacewander deleted a comment on issue #3321:

I also notice a crash without wasi_config_inherit_argv:

#0  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:65
#1  0x00007fbc04ec1e69 in std::ffi::c_str::CStr::from_ptr () at library/std/src/ffi/c_str.rs:1174
#2  std::sys::unix::args::imp::clone::{{closure}} () at library/std/src/sys/unix/args.rs:147
#3  core::iter::adapters::map::map_fold::{{closure}} () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/adapters/map.rs:82
#4  core::iter::traits::iterator::Iterator::fold () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:2112
#5  <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/adapters/map.rs:122
#6  core::iter::traits::iterator::Iterator::for_each () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:736
#7  <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_extend.rs:40
#8  <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_from_iter_nested.rs:56
#9  <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_from_iter.rs:33
#10 <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/mod.rs:2449
#11 core::iter::traits::iterator::Iterator::collect () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:1748
#12 std::sys::unix::args::imp::clone () at library/std/src/sys/unix/args.rs:145
#13 std::sys::unix::args::imp::args () at library/std/src/sys/unix/args.rs:137
#14 std::sys::unix::args::args () at library/std/src/sys/unix/args.rs:24
#15 std::env::args_os () at library/std/src/env.rs:780
#16 0x00007fbc04ec1cf1 in std::env::args () at library/std/src/env.rs:745
#17 0x00007fbc048eb112 in wasi_cap_std_sync::WasiCtxBuilder::inherit_args () at library/std/src/panicking.rs:541
#18 0x00007fbc04842f55 in wasmtime::wasi::wasi_config_t::into_wasi_ctx () at library/std/src/panicking.rs:541
#19 0x00007fbc0478d92a in wasmtime_context_set_wasi () at library/std/src/panicking.rs:541
#20 0x000000000068c706 in

Same bt but starts from error = wasmtime_context_set_wasi(context, vm_wasi_config);, happened only with argv is given.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 09 2021 at 08:48):

spacewander commented on issue #3321:

Look like it is because I called wasmtime_context_set_wasi twice on the same wasi_config.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 09 2021 at 08:48):

spacewander closed issue #3321:

Test Case

Steps to Reproduce

When I try to integrate wasmtime to my host program written in C, the program crashed during executing

    vm_wasi_config = wasi_config_new();
    if (vm_wasi_config == NULL) {
        goto ...;
    }

    wasi_config_inherit_argv(vm_wasi_config); /* <- this line! */

The bt is:

#0  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:65
#1  0x00007ff7c2b4ee69 in std::ffi::c_str::CStr::from_ptr () at library/std/src/ffi/c_str.rs:1174
#2  std::sys::unix::args::imp::clone::{{closure}} () at library/std/src/sys/unix/args.rs:147
#3  core::iter::adapters::map::map_fold::{{closure}} () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/adapters/map.rs:82
#4  core::iter::traits::iterator::Iterator::fold () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:2112
#5  <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/adapters/map.rs:122
#6  core::iter::traits::iterator::Iterator::for_each () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:736
#7  <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_extend.rs:40
#8  <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_from_iter_nested.rs:56
#9  <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_from_iter.rs:33
#10 <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/mod.rs:2449
#11 core::iter::traits::iterator::Iterator::collect () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:1748
#12 std::sys::unix::args::imp::clone () at library/std/src/sys/unix/args.rs:145
#13 std::sys::unix::args::imp::args () at library/std/src/sys/unix/args.rs:137
#14 std::sys::unix::args::args () at library/std/src/sys/unix/args.rs:24
#15 std::env::args_os () at library/std/src/env.rs:780
#16 0x00007ff7c2b4ecf1 in std::env::args () at library/std/src/env.rs:745
#17 0x00007ff7c2578112 in wasi_cap_std_sync::WasiCtxBuilder::inherit_args () at library/std/src/panicking.rs:541
#18 0x00007ff7c24cff55 in wasmtime::wasi::wasi_config_t::into_wasi_ctx () at library/std/src/panicking.rs:541
#19 0x00007ff7c241a92a in wasmtime_context_set_wasi () at library/std/src/panicking.rs:541
#20 0x000000000068c766 in ...

My CPU has avx2 support:

grep avx2 /proc/cpuinfo
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves flush_l1d arch_capabilities
...

It only happened when the argv of the program is not empty.

Expected Results

Run successfully

Actual Results

Segfault on wasi_config_inherit_argv

Versions and Environment

Wasmtime version or commit: v0.29.0

Operating system: Linux run on WSL

Architecture: x64

Extra Info

view this post on Zulip Wasmtime GitHub notifications bot (Sep 09 2021 at 09:11):

bjorn3 commented on issue #3321:

I think doing so shouldn't cause a SIGSEGV. At most it should case a panic or abort IMHO.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 09 2021 at 09:43):

spacewander commented on issue #3321:

It is quite weird. Even I can confirm the wasmtime_context_set_wasi is called once, the same thing can happen again. Remove wasi_config_inherit_argv so far make a segfault disappear.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 09 2021 at 09:43):

spacewander reopened issue #3321:

Test Case

Steps to Reproduce

When I try to integrate wasmtime to my host program written in C, the program crashed during executing

    vm_wasi_config = wasi_config_new();
    if (vm_wasi_config == NULL) {
        goto ...;
    }

    wasi_config_inherit_argv(vm_wasi_config); /* <- this line! */

The bt is:

#0  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:65
#1  0x00007ff7c2b4ee69 in std::ffi::c_str::CStr::from_ptr () at library/std/src/ffi/c_str.rs:1174
#2  std::sys::unix::args::imp::clone::{{closure}} () at library/std/src/sys/unix/args.rs:147
#3  core::iter::adapters::map::map_fold::{{closure}} () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/adapters/map.rs:82
#4  core::iter::traits::iterator::Iterator::fold () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:2112
#5  <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/adapters/map.rs:122
#6  core::iter::traits::iterator::Iterator::for_each () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:736
#7  <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_extend.rs:40
#8  <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_from_iter_nested.rs:56
#9  <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_from_iter.rs:33
#10 <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/mod.rs:2449
#11 core::iter::traits::iterator::Iterator::collect () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:1748
#12 std::sys::unix::args::imp::clone () at library/std/src/sys/unix/args.rs:145
#13 std::sys::unix::args::imp::args () at library/std/src/sys/unix/args.rs:137
#14 std::sys::unix::args::args () at library/std/src/sys/unix/args.rs:24
#15 std::env::args_os () at library/std/src/env.rs:780
#16 0x00007ff7c2b4ecf1 in std::env::args () at library/std/src/env.rs:745
#17 0x00007ff7c2578112 in wasi_cap_std_sync::WasiCtxBuilder::inherit_args () at library/std/src/panicking.rs:541
#18 0x00007ff7c24cff55 in wasmtime::wasi::wasi_config_t::into_wasi_ctx () at library/std/src/panicking.rs:541
#19 0x00007ff7c241a92a in wasmtime_context_set_wasi () at library/std/src/panicking.rs:541
#20 0x000000000068c766 in ...

My CPU has avx2 support:

grep avx2 /proc/cpuinfo
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves flush_l1d arch_capabilities
...

It only happened when the argv of the program is not empty.

Expected Results

Run successfully

Actual Results

Segfault on wasi_config_inherit_argv

Versions and Environment

Wasmtime version or commit: v0.29.0

Operating system: Linux run on WSL

Architecture: x64

Extra Info

view this post on Zulip Wasmtime GitHub notifications bot (Sep 09 2021 at 15:10):

alexcrichton commented on issue #3321:

I don't think there's really much we can do to fix this. The C API documents that wasmtime_context_set_wasi consumes the wasi_config_t and it can't be reused. Attempting to reuse it involves a use-after-free, which is undefined behavior and can do whatever it wants. In that sense we can't really preemptively fix this or panic or something like that. The only other option would be to change the API to not consume the input.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 10 2021 at 01:59):

spacewander commented on issue #3321:

Thanks!

view this post on Zulip Wasmtime GitHub notifications bot (Sep 10 2021 at 01:59):

spacewander closed issue #3321:

Test Case

Steps to Reproduce

When I try to integrate wasmtime to my host program written in C, the program crashed during executing

    vm_wasi_config = wasi_config_new();
    if (vm_wasi_config == NULL) {
        goto ...;
    }

    wasi_config_inherit_argv(vm_wasi_config); /* <- this line! */

The bt is:

#0  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:65
#1  0x00007ff7c2b4ee69 in std::ffi::c_str::CStr::from_ptr () at library/std/src/ffi/c_str.rs:1174
#2  std::sys::unix::args::imp::clone::{{closure}} () at library/std/src/sys/unix/args.rs:147
#3  core::iter::adapters::map::map_fold::{{closure}} () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/adapters/map.rs:82
#4  core::iter::traits::iterator::Iterator::fold () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:2112
#5  <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/adapters/map.rs:122
#6  core::iter::traits::iterator::Iterator::for_each () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:736
#7  <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_extend.rs:40
#8  <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_from_iter_nested.rs:56
#9  <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter ()
    at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/spec_from_iter.rs:33
#10 <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/vec/mod.rs:2449
#11 core::iter::traits::iterator::Iterator::collect () at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/iter/traits/iterator.rs:1748
#12 std::sys::unix::args::imp::clone () at library/std/src/sys/unix/args.rs:145
#13 std::sys::unix::args::imp::args () at library/std/src/sys/unix/args.rs:137
#14 std::sys::unix::args::args () at library/std/src/sys/unix/args.rs:24
#15 std::env::args_os () at library/std/src/env.rs:780
#16 0x00007ff7c2b4ecf1 in std::env::args () at library/std/src/env.rs:745
#17 0x00007ff7c2578112 in wasi_cap_std_sync::WasiCtxBuilder::inherit_args () at library/std/src/panicking.rs:541
#18 0x00007ff7c24cff55 in wasmtime::wasi::wasi_config_t::into_wasi_ctx () at library/std/src/panicking.rs:541
#19 0x00007ff7c241a92a in wasmtime_context_set_wasi () at library/std/src/panicking.rs:541
#20 0x000000000068c766 in ...

My CPU has avx2 support:

grep avx2 /proc/cpuinfo
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves flush_l1d arch_capabilities
...

It only happened when the argv of the program is not empty.

Expected Results

Run successfully

Actual Results

Segfault on wasi_config_inherit_argv

Versions and Environment

Wasmtime version or commit: v0.29.0

Operating system: Linux run on WSL

Architecture: x64

Extra Info


Last updated: Dec 23 2024 at 12:05 UTC