Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kani for unsafe rust #16

Open
podhrmic opened this issue Sep 27, 2023 · 3 comments
Open

Kani for unsafe rust #16

podhrmic opened this issue Sep 27, 2023 · 3 comments

Comments

@podhrmic
Copy link

Hi @nspin !

As we talked, I had a brief look at the unsafe code in rust-sel4 and whether Kani could be helpful here:

  1. the unsafe logic is already fairly limited, e.g. a pointer dereference, memory transmutation or external function call. That is good (less unsafe code the better), but also there is not that much that Kani can test (not counting trivial properties, such as any usize ptr that is not null can be dereferenced)
  2. we would usually start with converting unit tests to symbolic Kani tests - given there are (almost?) no tests in rust-sel4 crates, maybe we should start by adding tests/fuzzing? Don't get me wrong - your code looks really good, currently it is just hard to say why should we trust it works (maybe you have some ideas?)
  3. depending on the properties we want to proof, maybe other tools than Kani could be more applicable - e.g. Prusti or Flux.
@nspin
Copy link
Member

nspin commented Oct 6, 2023

Thanks for bringing this up!

the unsafe logic is already fairly limited, e.g. a pointer dereference, memory transmutation or external function call. That is good (less unsafe code the better), but also there is not that much that Kani can test (not counting trivial properties, such as any usize ptr that is not null can be dereferenced)

Yes, much of the unsafe code in this project is outside of the scope of what Kani can analyze. That said, there is, of course, plenty of analysis to be done towards increasing confidence in this project's use of unsafe! This includes finding ways to further minimizing its use, documenting assumptions and safety conditions, informal reasoning, and perhaps even applying tools which enable more rigorous analysis, including Kani and possibly others.

we would usually start with converting unit tests to symbolic Kani tests - given there are (almost?) no tests in rust-sel4 crates, maybe we should start by adding tests/fuzzing? Don't get me wrong - your code looks really good, currently it is just hard to say why should we trust it works (maybe you have some ideas?)

I agree that this project needs more tests with limited scope (including unit tests), and fuzzing! Some crates will require additional code infrastructure like mocking. I've been thinking about this, and I believe that certain mocking utilities may be useful for application developers using these crates as well, allowing them to develop and debug their application code on their development system, without emulation, instead of on seL4. So we might get extra bang for our buck there.

I've had a go at introducing Kani into this project (#30). I chose the sel4-bitfield-ops crate because it is both important (used heavily for object invocations and ABI-defined bitfield manipulation by the sel4-sys crate) and also easy to apply these techniques to.

I will report progress on all of these fronts in this issue.

@nspin
Copy link
Member

nspin commented May 29, 2024

I've introduced Verus into the project with this PR:

#143

For now, Verus feels like a heavyweight dependency for the core crates in this repo, but I plan to experiment with applying Verus to other areas of the code.

@podhrmic
Copy link
Author

Very cool! I would be curious how your experience with Verus compares with Kani.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants