From: Dov Murik <dovmurik@linux.ibm.com>
To: linux-coco@lists.linux.dev
Cc: Dov Murik <dovmurik@linux.ibm.com>,
Tobin Feldman-Fitzthum <tobin@linux.ibm.com>,
James Bottomley <jejb@linux.ibm.com>,
Claudio Carvalho <cclaudio@linux.ibm.com>
Subject: [RFC PATCH 3/3] virt: sevguest: Add support to get attestation report from SVSM
Date: Wed, 7 Jun 2023 18:06:46 +0300 [thread overview]
Message-ID: <20230607150646.97208-4-dovmurik@linux.ibm.com> (raw)
In-Reply-To: <20230607150646.97208-1-dovmurik@linux.ibm.com>
Expose SNP_SVSM_ATTEST_SERVICES ioctl function which allows userspace to
retrieve SNP attestation report.
Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>
---
drivers/virt/coco/sevguest/sevguest.c | 95 +++++++++++++++++++++++++++
include/uapi/linux/sev-guest.h | 34 ++++++++++
2 files changed, 129 insertions(+)
diff --git a/drivers/virt/coco/sevguest/sevguest.c b/drivers/virt/coco/sevguest/sevguest.c
index 0c6d1d05b9e7..a1c4acec679f 100644
--- a/drivers/virt/coco/sevguest/sevguest.c
+++ b/drivers/virt/coco/sevguest/sevguest.c
@@ -510,6 +510,97 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques
return ret;
}
+static int call_svsm_attest_services(struct snp_guest_dev *snp_dev,
+ struct snp_guest_request_ioctl *arg)
+{
+ struct snp_svsm_attest_services_req req;
+ struct snp_svsm_attest_services_resp *resp;
+ int ret;
+ struct page *page;
+ u8 *nonce, *report, *services_manifest, *certs;
+ u32 report_size, services_manifest_size, certs_size;
+
+ if (!arg->req_data || !arg->resp_data)
+ return -EINVAL;
+
+ if (copy_from_user(&req, (void __user *)arg->req_data, sizeof(req)))
+ return -EFAULT;
+
+ if (!access_ok(req.certs_address, req.certs_len))
+ return -EFAULT;
+
+ /*
+ * Since we're allocating 32 bytes, the buffer is ensured to not cross
+ * a page boundary.
+ */
+ nonce = kzalloc(sizeof(req.nonce), GFP_KERNEL_ACCOUNT);
+ if (!nonce)
+ return -EFAULT;
+ memcpy(nonce, req.nonce, sizeof(req.nonce));
+
+ /* The report buffer passed to SVSM must be 4KB aligned */
+ page = alloc_pages(GFP_KERNEL_ACCOUNT, get_order(sizeof(resp->report)));
+ if (IS_ERR(page)) {
+ ret = -EFAULT;
+ goto free_nonce;
+ }
+ report = page_address(page);
+ report_size = sizeof(resp->report);
+
+ /* The services manifest buffer passed to SVSM must be 4KB aligned */
+ page = alloc_pages(GFP_KERNEL_ACCOUNT,
+ get_order(sizeof(resp->services_manifest)));
+ if (IS_ERR(page)) {
+ ret = -EFAULT;
+ goto free_report;
+ }
+ services_manifest = page_address(page);
+ services_manifest_size = sizeof(resp->services_manifest);
+
+ /* The certificates buffer passed to SVSM must be 4KB aligned */
+ page = alloc_pages(GFP_KERNEL_ACCOUNT, get_order(req.certs_len));
+ if (IS_ERR(page)) {
+ ret = -EFAULT;
+ goto free_manifest;
+ }
+ certs = page_address(page);
+ certs_size = req.certs_len;
+
+ ret = snp_svsm_attest_services(nonce, sizeof(req.nonce), report,
+ &report_size, services_manifest,
+ &services_manifest_size, certs,
+ &certs_size);
+ if (ret)
+ goto free_certs;
+
+ if (copy_to_user((void __user *)req.certs_address, certs,
+ req.certs_len)) {
+ ret = -EFAULT;
+ goto free_certs;
+ }
+ resp = kzalloc(sizeof(*resp), GFP_KERNEL_ACCOUNT);
+ resp->report_len = report_size;
+ resp->services_manifest_len = services_manifest_size;
+ resp->certs_len = certs_size;
+ memcpy(resp->services_manifest, services_manifest,
+ sizeof(services_manifest_size));
+ memcpy(resp->report, report, sizeof(report_size));
+ if (copy_to_user((void __user *)arg->resp_data, resp, sizeof(*resp)))
+ ret = -EFAULT;
+ kfree(resp);
+
+free_certs:
+ free_pages((unsigned long)certs, get_order(req.certs_len));
+free_manifest:
+ free_pages((unsigned long)services_manifest,
+ get_order(sizeof(resp->services_manifest)));
+free_report:
+ free_pages((unsigned long)report, get_order(sizeof(resp->report)));
+free_nonce:
+ kfree(nonce);
+ return ret;
+}
+
static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned long arg)
{
struct snp_guest_dev *snp_dev = to_snp_dev(file);
@@ -545,6 +636,9 @@ static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned long
case SNP_GET_EXT_REPORT:
ret = get_ext_report(snp_dev, &input);
break;
+ case SNP_SVSM_ATTEST_SERVICES:
+ ret = call_svsm_attest_services(snp_dev, &input);
+ break;
default:
break;
}
@@ -703,6 +797,7 @@ static int __init snp_guest_probe(struct platform_device *pdev)
goto e_free_cert_data;
dev_info(dev, "Initialized SNP guest driver (using vmpck_id %d)\n", vmpck_id);
+ //do_svsm_attest(dev);
return 0;
e_free_cert_data:
diff --git a/include/uapi/linux/sev-guest.h b/include/uapi/linux/sev-guest.h
index 256aaeff7e65..60caf767e024 100644
--- a/include/uapi/linux/sev-guest.h
+++ b/include/uapi/linux/sev-guest.h
@@ -66,6 +66,36 @@ struct snp_ext_report_req {
__u32 certs_len;
};
+struct snp_svsm_attest_services_req {
+ /* nonce that should be included in the report */
+ __u8 nonce[32];
+
+ /* where to copy the certificate blob */
+ __u64 certs_address;
+
+ /* length of the certificate buffer */
+ __u32 certs_len;
+};
+
+struct snp_svsm_attest_services_resp {
+ /* length of the returned attestation report */
+ __u32 report_len;
+
+ /* length of the returned services manifest */
+ __u32 services_manifest_len;
+
+ /* length of the returned certificates blob */
+ __u32 certs_len;
+
+ __u8 rsvd[4];
+
+ /* services manifest */
+ __u8 services_manifest[1024];
+
+ /* attestation report, see SEV-SNP spec for the format */
+ __u8 report[3000];
+};
+
#define SNP_GUEST_REQ_IOC_TYPE 'S'
/* Get SNP attestation report */
@@ -77,4 +107,8 @@ struct snp_ext_report_req {
/* Get SNP extended report as defined in the GHCB specification version 2. */
#define SNP_GET_EXT_REPORT _IOWR(SNP_GUEST_REQ_IOC_TYPE, 0x2, struct snp_guest_request_ioctl)
+/* Get SVSM attest services report as defined in the SVSM specification */
+#define SNP_SVSM_ATTEST_SERVICES \
+ _IOWR(SNP_GUEST_REQ_IOC_TYPE, 0x3, struct snp_guest_request_ioctl)
+
#endif /* __UAPI_LINUX_SEV_GUEST_H_ */
--
2.35.3
next prev parent reply other threads:[~2023-06-07 15:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-07 15:06 [RFC PATCH 0/3] Retrieve SNP attestation from SVSM Dov Murik
2023-06-07 15:06 ` [RFC PATCH 1/3] x86/sev: Add __svsm_msr_protocol_2() which returns register values Dov Murik
2023-06-07 15:06 ` [RFC PATCH 2/3] x86/sev: Add snp_svsm_attest_services() Dov Murik
2023-06-07 15:06 ` Dov Murik [this message]
2023-06-07 16:23 ` [RFC PATCH 3/3] virt: sevguest: Add support to get attestation report from SVSM Daniel P. Berrangé
2023-06-07 17:05 ` Dov Murik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230607150646.97208-4-dovmurik@linux.ibm.com \
--to=dovmurik@linux.ibm.com \
--cc=cclaudio@linux.ibm.com \
--cc=jejb@linux.ibm.com \
--cc=linux-coco@lists.linux.dev \
--cc=tobin@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).