Repository navigation
Open
Labels
T-High PriorityTag issues that have high priorityT-UserTag user issues / requests[C] BugThis is a bug. Something isn't working.[E] PerformanceTrack performance improvement (Time / Memory / CPU)[F] CrashKani crashed
Description
I tried this code:
fn main() {
println!("Hello, world!");
}
#[derive(Debug)]
pub enum MyError {
Variant1 { field1: usize },
Variant2 { field2: usize, field3: usize },
IOError(std::io::Error),
}
#[kani::proof]
fn confusion() {
Ok::<_, MyError>(23).unwrap();
Err::<usize, _>(MyError::Variant1 { field1: kani::any() });
}using the following command line invocation:
cargo kani
with Kani version: 0.30.0
I expected to see this happen: Verification to complete
Instead, this happened: When running kani, it gets stuck unwinding a recursion in std::ptr::drop_in_place. Particularly, the below lines are repeated ad infinitum (with increasing iteration numbers):
aborting path on assume(false) at file /github/home/.rustup/toolchains/nightly-2023-04-30-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/error/repr_bitpacked.rs line 280 column 13 function std::io::error::repr_bitpacked::decode_repr::<std::boxed::Box<std::io::error::Custom>, [closure@<std::io::error::repr_bitpacked::Repr as std::ops::Drop>::drop::{closure#0}]> thread 0
aborting path on assume(false) at file /github/home/.rustup/toolchains/nightly-2023-04-30-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs line 977 column 15 function std::option::Option::<std::io::ErrorKind>::unwrap_or_else::<[closure@std::io::error::repr_bitpacked::decode_repr<std::boxed::Box<std::io::error::Custom>, [closure@<std::io::error::repr_bitpacked::Repr as std::ops::Drop>::drop::{closure#0}]>::{closure#0}]> thread 0
aborting path on assume(false) at file /github/home/.rustup/toolchains/nightly-2023-04-30-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/hint.rs line 105 column 9 function std::hint::unreachable_unchecked thread 0
aborting path on assume(false) at file /github/home/.rustup/toolchains/nightly-2023-04-30-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/error/repr_bitpacked.rs line 266 column 17 function std::io::error::repr_bitpacked::decode_repr::<std::boxed::Box<std::io::error::Custom>, [closure@<std::io::error::repr_bitpacked::Repr as std::ops::Drop>::drop::{closure#0}]>::{closure#0} thread 0
Unwinding recursion std::ptr::drop_in_place::<std::io::error::ErrorData<std::boxed::Box<std::io::error::Custom>>> iteration 2
Unwinding recursion std::ptr::drop_in_place::<std::boxed::Box<std::io::error::Custom>> iteration 2
Unwinding recursion std::ptr::drop_in_place::<std::io::error::Custom> iteration 2
Unwinding recursion std::ptr::drop_in_place::<std::boxed::Box<dyn std::error::Error + std::marker::Send + std::marker::Sync>> iteration 2
aborting path on assume(false) at thread 0
Unwinding recursion std::ptr::drop_in_place::<MyError> iteration 3
Unwinding recursion std::ptr::drop_in_place::<std::io::Error> iteration 3
Unwinding recursion std::ptr::drop_in_place::<std::io::error::repr_bitpacked::Repr> iteration 3
Unwinding recursion <std::io::error::repr_bitpacked::Repr as std::ops::Drop>::drop iteration 3
Now, normally this would not be a problem because I can just set #[kani::unwind(...)] and ignore this, but the problem is that even with a limited unwind value, this seems to cause any proof that contain code triggering this to explode in terms of memory usage and SAT complexity (causing it to run out of memory during SAT solving even on a .metal instance). Additional weirdness I could observe:
- I for the live of me cannot find where code inside
std::io::errorwould ever callstd::ptr::drop_in_place. The entire standard library only has a handful of these, and none of them seem to lie on the code paths here (they are in some collections and in something called aThinBoxthat I'm not really sure where its used, but doesnt seem to be used here) - maybe for these it would be useful to also print a file and line number? - Changing almost anything about the above snippet of code makes the unwinding go away (its the result of hours of minimizing a test case, and it has left me in tears), although there is some freedom of whether the
kani::any()is placed inVariant1orVariant2, or what type is used in the place ofusize) - I am aware that drop_in_place is an intrinsic that kani does not support, but shouldn't that just give me an error that an unsupported construct was encountered? Instead it seems like kani tries to do some verification on the stdlib "implementation" of it, which is using infinite recursion (with a comment that the body doesnt matter since it gets replaced by some compiler pass) [1].
I also tried stubbing it out, but that didn't seem to work either - I suppose because its an intrinsic?
Metadata
Metadata
Assignees
Labels
T-High PriorityTag issues that have high priorityT-UserTag user issues / requests[C] BugThis is a bug. Something isn't working.[E] PerformanceTrack performance improvement (Time / Memory / CPU)[F] CrashKani crashed
Type
Projects
- StatusShow more project fieldsTodo
Activity
[-][Bug] Infinite unwinding of `std::ptr::drop_in_place` in program containing enum wrapping std::io::Error in specific very manner[/-][+][Bug] Infinite unwinding of `std::ptr::drop_in_place` in program containing enum wrapping std::io::Error in very specific manner[/+]zhassan-aws commentedon Jun 16, 2023
Thanks for reporting the issue @roypat. It is reproducible without
kani::any()as well:zhassan-aws commentedon Jun 16, 2023
The infinite unwinding does not occur with function pointer restrictions:
zhassan-aws commentedon Jun 16, 2023
The
drop_in_placeseems to be coming from formatting code associated with theDebugtrait. If I replace thederive(Debug)with an empty implementation:the generated MIR does not reference
drop_in_place:However, the unwind log from CBMC mysteriously still refers to
drop_in_place!roypat commentedon Jun 16, 2023
Hey @zhassan-aws, thanks for looking into this so quickly! I just checked and can confirm that
--restrict-vtable --enable-unstablealso makes the more complex proof from which this example is derived work! :Dcelinval commentedon Jun 19, 2023
Unfortunately, not everything gets dumped into the *kani.mir files. The rust compiler doesn't support dumping the MIR generated for some items such as DropGlue. That's why you are not seeing any occurrence of
drop_in_place. However, that is still being generated by the compiler and it will be invoked when we handleDropstatements.roypat commentedon Aug 22, 2023
This issue is fairly prominent in the harnesses included in firecracker-microvm/firecracker#4066, where verification only completes without going out of memory thanks to low unwind values (2). Increasing the bounds will often leads to out of memory or severely increased runtime, which seems to be related to unwinding in
std::ptr::drop_in_placeand thestd::io::errormodule.fix: Use stub to fix kani performance issues
fix: Use stub to fix kani performance issues
fix: Use stub to fix kani performance issues
fix: Use stub to fix kani performance issues
kani: Work around performance issues
kani: Work around performance issues