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

Increase underhill_attestation lib unit test coverage #635

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

mattbodd
Copy link
Contributor

@mattbodd mattbodd commented Jan 9, 2025

This PR:

  • Adds unit tests to the underhill_attestation crate's lib
    • Covers all functions in lib that don't expect a GuestEmulationTransportClient parameter (any guidance on how to construct this in a test would be appreciated)

@mattbodd mattbodd requested review from a team as code owners January 9, 2025 03:50
@@ -1042,7 +1042,7 @@ async fn persist_all_key_protectors(
.dek_buffer
.fill(0);
key_protector.gsp[key_protector.active_kp as usize % NUMBER_KP].gsp_length = 0;
key_protector.active_kp += 1;
key_protector.active_kp += 1; // TODO: This is vulnerable to overflows
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there an issue tracking this? what would the mitigation be?

Copy link
Contributor Author

@mattbodd mattbodd Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a dev branch where I'm working on a fix. I can create an issue and reference it in my eventual PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that'd be great 👍

Copy link
Contributor

@mingweishih mingweishih Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only do modulo 2 against the value so the overflow should be safe, but it's great to improve the code that was ported from C/C++

Copy link
Contributor Author

@mattbodd mattbodd Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaik arithmetic overflow will lead to a panic in Rust (unless that can/is disabled somehow in OpenVMM/OpenHCL) so this could lead to an OpenHCL crash. I demonstrated this with a should_panic test in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, in that case can we do wrapped add here instead of having the test?

Copy link
Contributor Author

@mattbodd mattbodd Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually panicing due to arithmetic overflow doesn't look like the default behavior when building with release. So in the wild this would just overflow to 0. I think it could still be worth looking at making this a little nicer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After checking my understanding that the overflow won't panic when built in release, I'm less inclined to create an issue for this @daprilik. As Ming-wei mentioned, the usage of active_kp doesn't care if the value has overflowed to 0 so this logic should be fine. I can take the overflow test out since it doesn't demonstrate release behavior.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If overflow is explicitly expected and allowed, this code should switch over to using wrapping_add, and there should be a comment pointing out why wrapping around isn't an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documented this in #640 and suggested a couple improvements

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

Successfully merging this pull request may close these issues.

3 participants