Skip to content

Undefined behavior: do_in_place_scope tries to drop scope when scope reference passed to user is still alive #1008

Closed
@SOF3

Description

@SOF3

As my project is a bit complex, I have not been successful in creating a minimal reproducing example yet, but an unstripped example run can be found below.

GitHub CI run: https://github.com/SOF3/dynec/actions/runs/3861470087/jobs/6582464784#step:4:487

Source: https://github.com/SOF3/dynec/blob/2e83e3433b54977277a7ba340ac216a60b7da526/src/scheduler/executor.rs#L80-L121

Miri output:

error: Undefined Behavior: not granting access to tag <18216744> because that would remove [SharedReadOnly for <18182613>] which is protected because it is an argument of call 4729027
    --> /home/runner/.rustup/toolchains/nightly-2022-11-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/sync.rs:1706:13
     |
1706 |     fn drop(&mut self) {
     |             ^^^^^^^^^ not granting access to tag <18216744> because that would remove [SharedReadOnly for <18182613>] which is protected because it is an argument of call 4729027
     |
     = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
     = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <18216744> was created by a SharedReadWrite retag at offsets [0x0..0x8]
    --> src/scheduler/executor.rs:80:13
     |
80   | /             pool.in_place_scope(|scope| {
81   | |                 let (main_ealloc_shard, worker_ealloc_shards) = ealloc_shards
82   | |                     .split_last_mut()
83   | |                     .expect("ealloc_shards.len() == self.concurrency + 1");
...    |
120  | |                 )
121  | |             });
     | |______________^
help: <18182613> is this argument
    --> /home/runner/.rustup/toolchains/nightly-2022-11-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/thread.rs:108:17
     |
108  |                 Box::from_raw(main as *mut Box<dyn FnOnce()>)();
     |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     = note: BACKTRACE:
     = note: inside `<std::sync::Arc<rayon_core::registry::Registry> as std::ops::Drop>::drop` at /home/runner/.rustup/toolchains/nightly-2022-11-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/sync.rs:1706:13
     = note: inside `std::ptr::drop_in_place::<std::sync::Arc<rayon_core::registry::Registry>> - shim(Some(std::sync::Arc<rayon_core::registry::Registry>))` at /home/runner/.rustup/toolchains/nightly-2022-11-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:490:1
     = note: inside `std::ptr::drop_in_place::<rayon_core::scope::ScopeBase<'_>> - shim(Some(rayon_core::scope::ScopeBase<'_>))` at /home/runner/.rustup/toolchains/nightly-2022-11-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:490:1
     = note: inside `std::ptr::drop_in_place::<rayon::Scope<'_>> - shim(Some(rayon::Scope<'_>))` at /home/runner/.rustup/toolchains/nightly-2022-11-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:490:1
     = note: inside `rayon_core::scope::do_in_place_scope::<'_, [closure@src/scheduler/executor.rs:80:33: 80:40], ()>` at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.10.1/src/scope/mod.rs:441:1
     = note: inside `rayon::ThreadPool::in_place_scope::<'_, [closure@src/scheduler/executor.rs:80:33: 80:40], ()>` at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.10.1/src/thread_pool/mod.rs:284:9
note: inside `scheduler::executor::Executor::execute_full_cycle::<tracer::Aggregate<(tracer::Log, scheduler::tests::RunCounterTracer, tracer::Aggregate<(scheduler::tests::UnmarkCounterTracer, scheduler::tests::MaxConcurrencyTracer)>)>>` at src/scheduler/executor.rs:80:13
    --> src/scheduler/executor.rs:80:13
     |
80   | /             pool.in_place_scope(|scope| {
81   | |                 let (main_ealloc_shard, worker_ealloc_shards) = ealloc_shards
82   | |                     .split_last_mut()
83   | |                     .expect("ealloc_shards.len() == self.concurrency + 1");
...    |
120  | |                 )
121  | |             });
     | |______________^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions