Skip to content

kani: Add proof-harnesses for virtio queue implementation - #4066

Merged
roypat merged 6 commits into
firecracker-microvm:mainfrom
roypat:kani-virtio
Aug 22, 2023
Merged

roypat merged 6 commits into
firecracker-microvm:mainfrom
roypat:kani-virtio

Conversation

@roypat

@roypat roypat commented Aug 22, 2023

Copy link
Copy Markdown
Contributor

Changes

This PR adds Kani harnesses for our virtio queue implementation. 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, or that len and is_empty agree).

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

  • If a specific issue led to this PR, this PR closes the issue.
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • API changes follow the Runbook for Firecracker API changes.
  • User-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.
  • New TODOs link to an issue.
  • Commits meet contribution quality standards.

  • This functionality cannot be added in rust-vmm.

roypat added 4 commits August 22, 2023 11:53
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]>
@roypat roypat added the Status: Awaiting review Indicates that a pull request is ready to be reviewed label Aug 22, 2023
@roypat
roypat requested review from ShadowCurse and bchalios August 22, 2023 11:16
@codecov

codecov Bot commented Aug 22, 2023 •

Copy link
Copy Markdown

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.02% ⚠️

Comparison is base (dc7aabd) 82.72% compared to head (295fd35) 82.70%.

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     
Flag Coverage Δ
4.14-c7g.metal 78.16% <100.00%> (-0.02%) ⬇️
4.14-m5d.metal 79.91% <100.00%> (-0.03%) ⬇️
4.14-m6a.metal 79.05% <100.00%> (-0.03%) ⬇️
4.14-m6g.metal 78.16% <100.00%> (-0.02%) ⬇️
4.14-m6i.metal 79.90% <100.00%> (-0.03%) ⬇️
5.10-c7g.metal 81.10% <100.00%> (-0.03%) ⬇️
5.10-m5d.metal 82.59% <100.00%> (-0.03%) ⬇️
5.10-m6a.metal 81.83% <100.00%> (-0.03%) ⬇️
5.10-m6g.metal 81.10% <100.00%> (-0.03%) ⬇️
5.10-m6i.metal 82.59% <100.00%> (-0.03%) ⬇️
6.1-c7g.metal 81.10% <100.00%> (-0.03%) ⬇️
6.1-m5d.metal 82.59% <100.00%> (-0.03%) ⬇️
6.1-m6a.metal 81.83% <100.00%> (-0.03%) ⬇️
6.1-m6g.metal 81.10% <100.00%> (-0.02%) ⬇️
6.1-m6i.metal 82.59% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
src/vmm/src/devices/virtio/balloon/device.rs 88.34% <ø> (ø)
src/vmm/src/devices/virtio/balloon/mod.rs 50.00% <ø> (ø)
src/vmm/src/devices/virtio/block/mod.rs 0.00% <ø> (ø)
src/vmm/src/devices/virtio/net/mod.rs 50.00% <ø> (ø)
src/vmm/src/devices/virtio/vsock/mod.rs 0.00% <ø> (ø)
src/vmm/src/devices/virtio/balloon/persist.rs 82.47% <100.00%> (ø)
src/vmm/src/devices/virtio/block/persist.rs 92.23% <100.00%> (ø)
src/vmm/src/devices/virtio/net/persist.rs 96.15% <100.00%> (ø)
src/vmm/src/devices/virtio/queue.rs 92.54% <100.00%> (-1.82%) ⬇️
src/vmm/src/devices/virtio/rng/device.rs 82.05% <100.00%> (ø)
... and 2 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Awaiting review Indicates that a pull request is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants