Skip to content

Commit 3a164b0

Browse files
jaisnantautschnigcelinval
authored
Add Challenge 2: Verify the memory safery of core intrinsics using raw pointers (rust-lang#14)
Adds the challenge to `Verify the memory safery of core intrinsics using raw pointers` By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --------- Co-authored-by: Michael Tautschnig <[email protected]> Co-authored-by: Celina G. Val <[email protected]>
1 parent 8931064 commit 3a164b0

File tree

4 files changed

+101
-21
lines changed

4 files changed

+101
-21
lines changed

doc/src/SUMMARY.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- [General Rules](./general-rules.md)
66
- [Challenge Template](./template.md)
7+
- [Tool application](./todo.md)
78

89
- [Verification Tools](./tools.md)
910
- [Kani](./tools/kani.md)
@@ -12,4 +13,4 @@
1213
---
1314

1415
# Challenges
15-
- [Coming soon](./todo.md)
16+
- [Memory safety of core intrinsics](./intrinsics-memory.md)

doc/src/general-rules.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ NOTE: This work is not officially affiliated, or endorsed by the Rust project or
1010
tracking issue where contributors can add comments and ask clarification questions.
1111
You can find the list of [open challenges here](https://github.com/model-checking/verify-rust-std/labels/Challenge).
1212

13-
**Solutions:** Solutions to a problem should be submitted as a single Pull Request (PR) to this repository.
13+
**Solutions:** Solutions to a problem should be submitted as a single Pull Request (PR) to this repository.
1414
The solution should run as part of the CI.
1515
See more details about [minimum requirements for each solution](general-rules.md#solution-requirements).
1616

@@ -33,7 +33,7 @@ well as to track the status of the challenge.
3333

3434
A proposed solution to a verification problem will only **be reviewed** if all the minimum requirements below are met:
3535

36-
* Each contribution or attempt should be submitted via a pull request to be analyzed by reviewers.
36+
* Each contribution or attempt should be submitted via a pull request to be analyzed by reviewers.
3737
* By submitting the solution, participants confirm that they can use, modify, copy, and redistribute their contribution,
3838
under the terms of their choice.
3939
* The contribution must be automated and should be checked and pass as part of the PR checks.
@@ -56,7 +56,7 @@ The type of obstacles users face may depend on which part of the standard librar
5656
Everyone is welcome to submit new challenge proposals for review by our committee.
5757
Follow the following steps to create a new proposal:
5858

59-
1. Create a tracking issue using the Issue template [Challenge Proposal](todo.md) for your challenge.
59+
1. Create a tracking issue using the Issue template [Challenge Proposal](template.md) for your challenge.
6060
2. In your fork of this repository do the following:
6161
1. Copy the template file (`book/src/challenge_template.md`) to `book/src/challenges/<ID_NUMBER>-<challenge-name>.md`.
6262
2. Fill in the details according to the template instructions.

doc/src/intrinsics-memory.md

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Challenge 2: Verify the memory safery of core intrinsics using raw pointers
2+
3+
- **Status:** Open
4+
- **Tracking Issue:** [Link to issue](https://github.com/model-checking/verify-rust-std/issues/16)
5+
- **Start date:** *24/06/12*
6+
- **End date:** *24/12/10*
7+
8+
-------------------
9+
10+
11+
## Goal
12+
13+
Annotate Rust core::intrinsics functions that manipulate raw pointers with their safety contract. Verify their usage in the standard library is in fact safe.
14+
15+
### Success Criteria
16+
17+
1. All the following intrinsic functions must be annotated with safety contracts.
18+
2. Any fallback intrinsic implementation must be verified.
19+
3. For intrinsics modeled in the tool of choice, explain how their implementation matches the intrinsics definition. This can either be done in the PR description or as an entry to the contest book as part of the “Tools” chapter.
20+
4. For each function, contestants must state clearly the list of assumptions for each proof, how the proofs can be audited, and the list of (implicit and explicit) properties that are guaranteed.
21+
5. The verification of each intrinsic should ensure all the documented safety conditions are met, and that meeting them is enough to guarantee safe usage.
22+
23+
24+
Intrinsic functions to be annotated with safety contracts
25+
26+
| Function | Location |
27+
|---------|---------|
28+
|typed_swap | core::intrisics |
29+
|vtable_size| core::intrisics |
30+
|vtable_align| core::intrisics |
31+
|copy_nonoverlapping| core::intrisics |
32+
|copy| core::intrisics |
33+
|write_bytes| core::intrisics |
34+
|size_of_val| core::intrisics |
35+
|arith_offset| core::intrisics |
36+
|volatile_copy_nonoverlapping_memory| core::intrisics |
37+
|volatile_copy_memory| core::intrisics |
38+
|volatile_set_memory| core::intrisics |
39+
|volatile_load| core::intrisics |
40+
|volatile_store| core::intrisics |
41+
|unaligned_volatile_load| core::intrisics |
42+
|unaligned_volatile_store| core::intrisics |
43+
|compare_bytes| core::intrisics |
44+
|min_align_of_val| core::intrisics |
45+
|ptr_offset_from| core::intrisics |
46+
|ptr_offset_from_unsigned| core::intrisics |
47+
|read_via_copy| core::intrisics |
48+
|write_via_move| core::intrisics |
49+
50+
51+
All the following usages of intrinsics were proven safe:
52+
53+
| Function | Location |
54+
|---------|---------|
55+
|copy_from_slice | core::slice |
56+
|parse_u64_into | std::fmt |
57+
|swap | core::mem |
58+
|align_of_val | core::mem |
59+
|zeroed | core::mem::maybe_uninit |
60+
61+
62+
63+
Annotate and verify all the functions that below that expose intrinsics with safety contracts
64+
65+
| Function | Location |
66+
|---------|---------|
67+
|copy_from_slice | std::ptr |
68+
|parse_u64_into | std::ptr |
69+
|swap | std::ptr |
70+
|align_of_val | std::ptr |
71+
|zeroed | std::ptr |
72+
73+
74+
75+
### List of UBs
76+
77+
All proofs must automatically ensure the absence of the following undefined behaviors [ref](https://github.com/rust-lang/reference/blob/142b2ed77d33f37a9973772bd95e6144ed9dce43/src/behavior-considered-undefined.md):
78+
79+
* Invoking undefined behavior via compiler intrinsics.
80+
* Accessing (loading from or storing to) a place that is dangling or based on a misaligned pointer.
81+
* Reading from uninitialized memory except for padding or unions.
82+
* Mutating immutable bytes.
83+
* Producing an invalid value
84+
85+
86+
Note: All solutions to verification challenges need to satisfy the criteria established in the [challenge book](general-rules.md)
87+
in addition to the ones listed above.

doc/src/template.md

+9-17
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,27 @@
2525

2626
*Mention any assumption that users may make. Example, "assuming the usage of Stacked Borrows".*
2727

28-
### Success Criteria*
28+
### Success Criteria
2929

3030
*Here are some examples of possible criteria:*
3131

3232
All the following unsafe functions must be annotated with safety contracts and the contracts have been verified:
3333

34-
|Function |Location |
35-
|--- |--- |
36-
| | |
37-
| | |
38-
| | |
39-
| | |
40-
| | |
34+
| Function | Location |
35+
|---------|---------|
36+
| abc | def |
4137

4238
At least N of the following usages were proven safe:
4339

44-
|Function |Location |
45-
|--- |--- |
46-
| | |
47-
| | |
48-
| | |
49-
| | |
50-
| | |
40+
| Function | Location |
41+
|---------|---------|
42+
| xyz | 123 |
5143

52-
All proofs must automatically ensure the absence of the following undefined behaviors [[ref]](https://github.com/rust-lang/reference/blob/142b2ed77d33f37a9973772bd95e6144ed9dce43/src/behavior-considered-undefined.md):
44+
All proofs must automatically ensure the absence of the following undefined behaviors [ref](https://github.com/rust-lang/reference/blob/142b2ed77d33f37a9973772bd95e6144ed9dce43/src/behavior-considered-undefined.md):
5345

5446
*List of UBs*
5547

5648
Note: All solutions to verification challenges need to satisfy the criteria established in the [challenge book](general-rules.md)
5749
in addition to the ones listed above.
5850

59-
[^challenge_id]: The number of the challenge sorted by publication date.
51+
[^challenge_id]: The number of the challenge sorted by publication date.

0 commit comments

Comments
 (0)