Skip to content

Conversation

@jul-sh
Copy link

@jul-sh jul-sh commented Apr 21, 2022

rebased and ready for review. Implements attestation in the UEFI app side, adding the client side in a separate PR.

Comment on lines 20 to 21
//! A simplified version of the implementation from the `grpc_unary_attestation`
//! crate. TODO(#2741): Refactor this to share more code between the two runtimes.
Copy link
Author

@jul-sh jul-sh Apr 21, 2022

Choose a reason for hiding this comment

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

Will do some of that before opening this PR, to simplify review, ref #2741

Copy link
Author

Choose a reason for hiding this comment

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

done in #2743

Copy link
Author

Choose a reason for hiding this comment

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

Leaving this TODO in as some additional refactoring can probably be done with the AttestationHandler here, which mirrors the AttestationServer in the grpc attestation crate. — But redundancy is fairly small, so we can move ahead with this PR for now.

@jul-sh jul-sh force-pushed the handshake branch 2 times, most recently from 5cdc3d3 to 98e9f9d Compare April 21, 2022 17:03
@jul-sh jul-sh force-pushed the handshake branch 4 times, most recently from b5538e0 to e36dbfd Compare April 22, 2022 10:07
@jul-sh jul-sh marked this pull request as ready for review April 22, 2022 10:16
@jul-sh jul-sh requested a review from a team as a code owner April 22, 2022 10:16
@jul-sh jul-sh requested review from andrisaar and conradgrobler and removed request for a team April 22, 2022 10:16
Comment on lines 76 to 77
const MOCK_SESSION_ID: [u8; 8] = [0; 8];

Copy link
Author

Choose a reason for hiding this comment

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

Mock for now as we only have a single proof of concept client. Will swap this out once I amend the client code to support attestation

Copy link
Collaborator

@conradgrobler conradgrobler left a comment

Choose a reason for hiding this comment

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

Thanks

// * `index` - index of the serial port, zero-based.
//
// Normally does not return, unless an error is raised.
fn serial_echo(handle: Handle, bt: &BootServices, index: usize) -> Result<!, uefi::Error<()>> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like this will conflict with #2745. It is probably a good idea to wait for that to be merged and then rebase on top of it.

Copy link
Author

Choose a reason for hiding this comment

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

sgtm

const MOCK_TEE_CERTIFICATE: [u8; 0] = [];
const MOCK_ADDITIONAL_INFO: [u8; 0] = [];

impl<F> AttestationHandler<F>
Copy link
Collaborator

Choose a reason for hiding this comment

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

This feels like this is more generic functionality, and could be reused for different scenarios. It might be a good idea to move it somewhere more reusable (either remote_attestation_sessions (my preference) or the new runtime crate from #2745, or even yet another crate (although that is probably overkill)).

Copy link
Collaborator

Choose a reason for hiding this comment

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

As you mentioned in #2742 (comment) this can be done later as part of #2471

}
}

pub fn message(&mut self, session_id: SessionId, request: Vec<u8>) -> Vec<u8> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should return a Result<Vec<u8>> rather than panic. In the current Oak functions loader Tonic has a handler for request-related tasks that panic, but I think we should not panic anywhere in code for UEFI/bare-metal runtimes unless it is an unrecoverable fatal error that should kill the server.

Copy link
Author

@jul-sh jul-sh Apr 22, 2022

Choose a reason for hiding this comment

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

Agreed. I left it like this for the initial remote attestation proof of concept only, but will swap it out for proper error handling by updating this PR.

Copy link
Author

Choose a reason for hiding this comment

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

Updated this PR with basic error handling inside the remote attestation module. However if an error occurs it'll still panic inside the main function of the UEFI app which unwraps any Result of the serial_echo function. Now that's "failed to read message from serial port", "failed remote attestation", "failed to write message to serial port".

We probably don't actually want to panic for "failed remote attestation", and possibly also not for "failed to read message from serial port". Instead we could send an error status code to the companion app, keeping the UEFI app running + serial port open.

I'll open a separate PR for implementing that bit, as it seems best to discuss that in isolation. Probs more related to the general UEFI app <-> loader comms protocol question than to remote attestation specifically.

cc @andrisaar

// Needed to expose advanced CPU features to the UEFI app. Specifically
// RDRAND which is required for remote attestation.
cmd.arg("-enable-kvm");
cmd.args(&["-cpu", "Broadwell-IBRS"]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any particular reason for Broadwell-IBRS? Granted, I don't know what the default CPU that qemu emulates is, but if you want something with RDRAND I think you can explicitly ask for that with +rdrand, something like "-cpu host,+rdrand". I think explicitly listing that we require rdrand is better than hiding it in the CPU definition.

That being said, qemu docs are not the best, so please do check the syntax for the -cpu flag to see how it works.

Copy link
Author

@jul-sh jul-sh Apr 22, 2022

Choose a reason for hiding this comment

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

Any particular reason for Broadwell-IBRS?

No strong reason for the particular model, other than it supports RDRAND while being old enough that it can hopefully be virtualized by most hosts. This particular line just matches what we went with in #2703.

In general we do want to specify a specific model. The reason is that in virtualization mode, qemu does not use a default CPU. Instead it's either host passthrough (unstable between hosts, not recommended by docs) or a named model. :)

See https://qemu-project.gitlab.io/qemu/system/qemu-cpu-models.html#two-ways-to-configure-cpu-models-with-qemu-kvm for more details

where
F: Send + Sync + Clone + FnOnce(Vec<u8>) -> Vec<u8>,
{
pub fn create(request_handler: F) -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't the normal Rust convention to call these constructor methods new?

Copy link
Author

@jul-sh jul-sh Apr 22, 2022

Choose a reason for hiding this comment

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

Seems like there is a loose convention towards new indeed, https://doc.rust-lang.org/nomicon/constructors.html mentions it.

In our codebase we tend to use both create and new in different places , agreed that settling on a convention would be nice though probs out of scope for this. new does seem like a good choice. I choose create here to be consistent with the rest of the remote attestation related structs in the codebase.

@jul-sh jul-sh requested a review from andrisaar April 22, 2022 16:05
@jul-sh
Copy link
Author

jul-sh commented Apr 22, 2022

@andrisaar Could you take a look at the updated version of this PR? (post merging #2745)

Copy link
Collaborator

@conradgrobler conradgrobler left a comment

Choose a reason for hiding this comment

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

Nice.

Copy link
Collaborator

@andrisaar andrisaar left a comment

Choose a reason for hiding this comment

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

Nice, no changes to the uefi app itself!

@tiziano88 tiziano88 changed the title Implement simple remote attestion for the UEFI app Implement simple remote attestation for the UEFI app Apr 22, 2022
@jul-sh jul-sh merged commit 16aad75 into project-oak:main Apr 22, 2022
@jul-sh jul-sh deleted the handshake branch April 22, 2022 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants