diff --git a/doc/src/SUMMARY.md b/doc/src/SUMMARY.md index 9a8023d63908a..3565a3f713727 100644 --- a/doc/src/SUMMARY.md +++ b/doc/src/SUMMARY.md @@ -18,3 +18,4 @@ - [Pointer Arithmetic](./challenges/0003-pointer-arithmentic.md) - [Memory safety of BTreeMap's `btree::node` module](./challenges/0004-btree-node.md) - [Inductive data type](./challenges/0005-linked-list.md) + - [Safety of NonNull](./challenges/0006-nonnull.md) diff --git a/doc/src/challenges/0006-nonnull.md b/doc/src/challenges/0006-nonnull.md new file mode 100644 index 0000000000000..ef2add5bda8af --- /dev/null +++ b/doc/src/challenges/0006-nonnull.md @@ -0,0 +1,84 @@ +# Challenge 6: Safety of NonNull + +- **Status:** Open +- **Tracking Issue:** [Link to issue](TODO: https://github.com/model-checking/verify-rust-std/issues/TBA) +- **Start date:** *2024-08-16* +- **End date:** *2024-12-10* + +------------------- + + +## Goal + +Verify absence of undefined behavior of the [`ptr::NonNull` module](https://github.com/rust-lang/rust/blob/master/library/core/src/ptr/non_null.rs). +Most of its functions are marked `unsafe`, yet they are used in 62 other modules +of the standard library. + +### Success Criteria + +Prove absence of undefined behavior of the following 48 public functions. You +may wish to do so by attaching pre- and postconditions to these, and then (if +needed by the tooling that you choose to use) adding verification harnesses. + +1. `NonNull::add` +1. `NonNull::addr` +1. `NonNull::align_offset` +1. `NonNull::as_mut<'a>` +1. `NonNull::as_mut_ptr` +1. `NonNull::as_non_null_ptr` +1. `NonNull::as_ptr` +1. `NonNull::as_ref<'a>` +1. `NonNull::as_uninit_mut<'a>` +1. `NonNull::as_uninit_ref<'a>` +1. `NonNull::as_uninit_slice<'a>` +1. `NonNull::as_uninit_slice_mut<'a>` +1. `NonNull::byte_add` +1. `NonNull::byte_offset_from` +1. `NonNull::byte_offset` +1. `NonNull::byte_sub` +1. `NonNull::cast` +1. `NonNull::copy_from_nonoverlapping` +1. `NonNull::copy_from` +1. `NonNull::copy_to_nonoverlapping` +1. `NonNull::copy_to` +1. `NonNull::dangling` +1. `NonNull::drop_in_place` +1. `NonNull::from_raw_parts` +1. `NonNull::get_unchecked_mut` +1. `NonNull::is_aligned_to` +1. `NonNull::is_aligned` +1. `NonNull::is_empty` +1. `NonNull::len` +1. `NonNull::map_addr` +1. `NonNull::new_unchecked` +1. `NonNull::new` +1. `NonNull::offset_from` +1. `NonNull::offset` +1. `NonNull::read_unaligned` +1. `NonNull::read_volatile` +1. `NonNull::read` +1. `NonNull::replace` +1. `NonNull::slice_from_raw_parts` +1. `NonNull::sub_ptr` +1. `NonNull::sub` +1. `NonNull::swap` +1. `NonNull::to_raw_parts` +1. `NonNull::with_addr` +1. `NonNull::write_bytes` +1. `NonNull::write_unaligned` +1. `NonNull::write_volatile` +1. `NonNull::write` + +### List of UBs + +In addition to any properties called out as `SAFETY` comments in the source +code, +all proofs must automatically ensure the absence of the following [undefined behaviors](https://github.com/rust-lang/reference/blob/142b2ed77d33f37a9973772bd95e6144ed9dce43/src/behavior-considered-undefined.md): + +* Accessing (loading from or storing to) a place that is dangling or based on a misaligned pointer. +* Reading from uninitialized memory. +* Mutating immutable bytes. +* Producing an invalid value + +Note: All solutions to verification challenges need to satisfy the criteria established in the [challenge book](../general-rules.md) +in addition to the ones listed above.