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

SNP Attestation #108

Merged
merged 14 commits into from
Mar 10, 2023
Merged

SNP Attestation #108

merged 14 commits into from
Mar 10, 2023

Conversation

tylerfanelli
Copy link
Collaborator

@tylerfanelli tylerfanelli commented Jan 17, 2023

No description provided.

@tylerfanelli tylerfanelli marked this pull request as draft January 17, 2023 16:08
@slp
Copy link
Contributor

slp commented Jan 24, 2023

So far is looking really good, minor details aside. Do you want a full review now or should we wait until this PR is no longer a draft?

@tylerfanelli
Copy link
Collaborator Author

@slp I don't suppose a full review is necessary yet. I'm fine with your comment, and just wanted to gauge your initial thoughts. Thanks!

@tylerfanelli tylerfanelli marked this pull request as ready for review February 14, 2023 19:40
@tylerfanelli tylerfanelli marked this pull request as draft February 15, 2023 06:20
@tylerfanelli tylerfanelli marked this pull request as ready for review February 27, 2023 07:05
@tylerfanelli
Copy link
Collaborator Author

@slp This is ready for full review.

init/init.c Outdated Show resolved Hide resolved
return NULL;
}

if (mount("securityfs", "/sfs", "securityfs",
Copy link
Contributor

Choose a reason for hiding this comment

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

We still need this code for SEV/SEV-ES. After opening krun-sev.json, we need to check the "tee" field and either use this code or, for the SNP case, use the new one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in dcd5828

static int
KBS_CURL_ERR(char *errmsg)
{
printf("ERROR (kbs_curl_post): %s\n", errmsg);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not entirely sure this function is useful. We're losing the ability to pass format strings (varargs) and it's used from more places than kbs_curl_post, so the function name is confusing.

Probably a macro that uses __func__ to print the function name and supports passing varargs to printf would work better.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 28e1566


kbs_attestation_marshal_tee_pubkey(json, mod, exp);

sprintf(buf, "\"tee-evidence\":\"{\\\"report\\\":\\\"{");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth marshaling the entire report into JSON? Seems quite expensive to me when compared to, for instance, treating the entire report as a binary blob, encoding it in an hexadecimal string and sending it to the Attestation Server. Then the AS can decode the hexadecimal string into a [u8] array, and transmute it into a sev::firmware::guest::types::AttestationReport.

Copy link
Collaborator Author

@tylerfanelli tylerfanelli Mar 7, 2023

Choose a reason for hiding this comment

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

Hex encoded in b01b723


/*
* SNP attestation report structure. Based off of the attestation report
* structure described in firmware version 1.51.
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 any chance they've changed this struct again in 1.52? I had to put a 32 bit padding before report_data to align properly its contents.

Copy link
Collaborator Author

@tylerfanelli tylerfanelli Mar 7, 2023

Choose a reason for hiding this comment

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

Fixed in b01b723

Copy link
Contributor

@slp slp left a comment

Choose a reason for hiding this comment

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

I see some really nice work here. I've tested and works fine, except for the problem with the snp_report misalignment and the measurement comparison (I suspect we might need to update the vmsa blob too).

In addition to the comments in the code, I'd also suggest that, for consistency with init.c, please use tabs instead of spaces and always use curly braces even when the conditional has a single statement (we should also put a coding style somewhere).

@tylerfanelli
Copy link
Collaborator Author

@slp Another note. I'll be removing the certificate code and modifying SNP_GET_EXT_REPORT to SNP_GET_REPORT, since we're basically leaving it up to the attestation server to retrieve the certificates.

sprintf(buf, "\\\\\\\"plat_info\\\\\\\":%lu,", report->platform_info);
OPENSSL_buf2hexstr_ex(report_hexstr, 0x1000, &report_hexstr_len,
(unsigned char *) report, sizeof(*report), '\0');
report_hexstr[report_hexstr_len] = '\0';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TODO: Is this required? Or does OpenSSL null-terminate the string?

@tylerfanelli
Copy link
Collaborator Author

@slp Can you re-review? I've added changes fixing all of your original concerns.

@slp
Copy link
Contributor

slp commented Mar 9, 2023

I've been testing this and it's working great after fixing the SNP measurement generation in libkrunfw. I've also confirmed still works fine with SEV/SEV-ES.

Could you please rebase so we can merge it?

Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
For SNP, we don't care much for krun_set_tee_config(), as the
attestation is done from the guest. Instead, wrtie the TEE config file
to the data disk and allow the guest to read it from the init binary.

Also including an example TEE config disk image
"snp-config-data-disk.img" with the workload ID "test" and attestation
URL of localhost to allow for a user to test the attestation
functionality.

Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
With the updates allowing a TEE example to submit an disk image
containing a TEE config file, we can now mount the image and read the
TEE config in the init binary. We do this (and parse the TEE config) for
the workload ID and attestation URL of the guest.

Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
The initial phase of a KBS attestation is the CHALLENGE. The CHALLENGE
serves as the function that an attestation server uses to generate an
ephermal nonce and send it back to the client for inclusion in the
SNP attestation report.

Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
Given the nonce from the attestation server (KBS CHALLENGE), include
this nonce in the attestation and retrieve an attestation report.

Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
The TEE public key is used for validating a guest's attestation report
with the attestation server. The attestation's response will eventually
be encrypted with this public key, so only the guest will be able to
decrypt the message.

Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
In the ATTESTATION phase, the guest will marshal of its input data (SNP
attestation report, certificate chain, etc..) and send it to the KBS
attestation server to attest the workload. If there is no error reported
for this step, a client can assume that the attestation was successful.

Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
A JSON string is returned from the attestation server (specifically, a
JSON string of a kbs_types::Challenge). Parse this struct to read the
string value of the nonce.

Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
…ssphrase

Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
With firmware update 1.52, the firmware required extra padding bits to
align properly. Furthermore, instead of traversing each field and
writing it out to the JSON buffer, use OpenSSL to hex encode the report
before sending to the attestation server.

Due to the fact that we now submit the SNP generation (which allows the
attestation server to retrieve the certificate chain), we don't need to
send the certificate chain to the attestation server from libkrun. Thus,
only grab the report using SNP_GET_REPORT instead of SNP_GET_EXT_REPORT.

Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
@tylerfanelli
Copy link
Collaborator Author

@slp Rebased :) thanks!

Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
@slp slp merged commit 10dcdf1 into containers:main Mar 10, 2023
@tylerfanelli tylerfanelli deleted the init_snp branch March 29, 2024 03:34
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.

2 participants