Repository navigation
kani: Add proof-harnesses for virtio queue implementation - #4066
Merged
Merged
Conversation
Each device was defining its own queue size constant, and they were all 256. Now there is exactly one constant in queue.rs, which can be referred to in unit tests/proof harnesses. Signed-off-by: Patrick Roy <[email protected]>
Functions in queue.rs now have debug_assert!s that validate they are only executed if the queue's in-memory layout is valid (to match assumptions made in our kani proofs). Two unittests were not respecting this requirement. This commit updates one of them to correctly initializes queues, and removes the other (as it was explicitly testing an operation on a mis-aligned queue). Signed-off-by: Patrick Roy <[email protected]>
The properties upheld by these proofs can roughly be grouped into three categories: - Specification conformance proofs (e.g. notification suppression works as described in section 2.6.7.2 of the virtio 1.1 spec, that all "valid" queues obey the alignment properties of the spec) - Absense of out of bound memory accesses (due to kani's built-in functionality of ensuring no panic!s are hit) - Common-sense properties modelled after the implemented functionality (e.g. functions returning an error leave guest memory untouched, of that len and is_empty agree). Notably, almost all of these proofs assume a valid queue layout (apart from the ones that aim to verify the is_valid functions). This is due to limitations in kani. Signed-off-by: Patrick Roy <[email protected]>
The previous is_valid check only checked whether the last byte of avail_ring, descriptor_table or used_ring are valid guest physical addresses. However, since guest memory is not neccessarily contiguous (for example, the MMIO gap leaves a hole), this allowed a guest to set up a queue structure that "starts" inside the MMIO gap and ends outside of it. This would pass validations, and then later potentially crash firecracker when a device tried to consume descriptors from it. This happens because while all actual memory reads and writes perform additional bounds checks, some code in queue.rs used .unwrap() under the assumption that all such bounds check would always pass (which they would, if is_valid() were implemented correctly). This would then result in a panic!(). Signed-off-by: Patrick Roy <[email protected]>
bchalios
approved these changes
Aug 22, 2023
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #4066 +/- ##
==========================================
- Coverage 82.72% 82.70% -0.02%
==========================================
Files 220 220
Lines 28260 28263 +3
==========================================
- Hits 23378 23375 -3
- Misses 4882 4888 +6
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
ShadowCurse
approved these changes
Aug 22, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
This PR adds Kani harnesses for our virtio queue implementation. The properties upheld by these proofs can roughly be grouped into three categories:
License Acceptance
By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following
Developer Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.PR Checklist
CHANGELOG.md.TODOs link to an issue.rust-vmm.