From: Borislav Petkov <bp@alien8.de>
To: Brijesh Singh <brijesh.singh@amd.com>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org, linux-efi@vger.kernel.org,
platform-driver-x86@vger.kernel.org, linux-coco@lists.linux.dev,
linux-mm@kvack.org, Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Joerg Roedel <jroedel@suse.de>,
Tom Lendacky <thomas.lendacky@amd.com>,
"H. Peter Anvin" <hpa@zytor.com>,
Ard Biesheuvel <ardb@kernel.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>,
Andy Lutomirski <luto@kernel.org>,
Dave Hansen <dave.hansen@linux.intel.com>,
Sergio Lopez <slp@redhat.com>, Peter Gonda <pgonda@google.com>,
Peter Zijlstra <peterz@infradead.org>,
Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
David Rientjes <rientjes@google.com>,
Dov Murik <dovmurik@linux.ibm.com>,
Tobin Feldman-Fitzthum <tobin@ibm.com>,
Michael Roth <michael.roth@amd.com>,
Vlastimil Babka <vbabka@suse.cz>,
"Kirill A . Shutemov" <kirill@shutemov.name>,
Andi Kleen <ak@linux.intel.com>,
tony.luck@intel.com, marcorr@google.com,
sathyanarayanan.kuppuswamy@linux.intel.com
Subject: Re: [PATCH Part1 v5 38/38] virt: sevguest: Add support to get extended report
Date: Wed, 8 Sep 2021 19:53:21 +0200 [thread overview]
Message-ID: <YTj4kZCTudDauIn1@zn.tnic> (raw)
In-Reply-To: <20210820151933.22401-39-brijesh.singh@amd.com>
On Fri, Aug 20, 2021 at 10:19:33AM -0500, Brijesh Singh wrote:
> Version 2 of GHCB specification defines NAE to get the extended guest
Resolve "NAE" pls.
> request. It is similar to the SNP_GET_REPORT ioctl. The main difference
> is related to the additional data that be returned. The additional
"that will be returned"
> data returned is a certificate blob that can be used by the SNP guest
> user. The certificate blob layout is defined in the GHCB specification.
> The driver simply treats the blob as a opaque data and copies it to
> userspace.
>
> Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
> ---
> Documentation/virt/coco/sevguest.rst | 22 +++++
> drivers/virt/coco/sevguest/sevguest.c | 126 ++++++++++++++++++++++++++
> include/uapi/linux/sev-guest.h | 13 +++
> 3 files changed, 161 insertions(+)
>
> diff --git a/Documentation/virt/coco/sevguest.rst b/Documentation/virt/coco/sevguest.rst
> index 25446670d816..7acb8696fca4 100644
> --- a/Documentation/virt/coco/sevguest.rst
> +++ b/Documentation/virt/coco/sevguest.rst
> @@ -85,3 +85,25 @@ on the various fileds passed in the key derivation request.
>
> On success, the snp_derived_key_resp.data will contains the derived key
> value.
> +
> +2.2 SNP_GET_EXT_REPORT
> +----------------------
> +:Technology: sev-snp
> +:Type: guest ioctl
> +:Parameters (in/out): struct snp_ext_report_req
> +:Returns (out): struct snp_report_resp on success, -negative on error
> +
> +The SNP_GET_EXT_REPORT ioctl is similar to the SNP_GET_REPORT. The difference is
> +related to the additional certificate data that is returned with the report.
> +The certificate data returned is being provided by the hypervisor through the
> +SNP_SET_EXT_CONFIG.
> +
> +The ioctl uses the SNP_GUEST_REQUEST (MSG_REPORT_REQ) command provided by the SEV-SNP
> +firmware to get the attestation report.
> +
> +On success, the snp_ext_report_resp.data will contains the attestation report
"will contain"
> +and snp_ext_report_req.certs_address will contains the certificate blob. If the
ditto.
> +length of the blob is lesser than expected then snp_ext_report_req.certs_len will
"is smaller"
> +be updated with the expected value.
> +
> +See GHCB specification for further detail on how to parse the certificate blob.
> diff --git a/drivers/virt/coco/sevguest/sevguest.c b/drivers/virt/coco/sevguest/sevguest.c
> index 621b1c5a9cfc..d978eb432c4c 100644
> --- a/drivers/virt/coco/sevguest/sevguest.c
> +++ b/drivers/virt/coco/sevguest/sevguest.c
> @@ -39,6 +39,7 @@ struct snp_guest_dev {
> struct device *dev;
> struct miscdevice misc;
>
> + void *certs_data;
> struct snp_guest_crypto *crypto;
> struct snp_guest_msg *request, *response;
> };
> @@ -347,6 +348,117 @@ static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_user_guest_
> return rc;
> }
>
> +static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_user_guest_request *arg)
> +{
> + struct snp_guest_crypto *crypto = snp_dev->crypto;
> + struct snp_guest_request_data input = {};
> + struct snp_ext_report_req req;
> + int ret, npages = 0, resp_len;
> + struct snp_report_resp *resp;
> + struct snp_report_req *rreq;
> + unsigned long fw_err = 0;
> +
> + if (!arg->req_data || !arg->resp_data)
> + return -EINVAL;
> +
> + /* Copy the request payload from the userspace */
"from userspace"
> + if (copy_from_user(&req, (void __user *)arg->req_data, sizeof(req)))
> + return -EFAULT;
> +
> + rreq = &req.data;
> +
> + /* Message version must be non-zero */
> + if (!rreq->msg_version)
> + return -EINVAL;
> +
> + if (req.certs_len) {
> + if (req.certs_len > SEV_FW_BLOB_MAX_SIZE ||
> + !IS_ALIGNED(req.certs_len, PAGE_SIZE))
> + return -EINVAL;
> + }
> +
> + if (req.certs_address && req.certs_len) {
> + if (!access_ok(req.certs_address, req.certs_len))
> + return -EFAULT;
> +
> + /*
> + * Initialize the intermediate buffer with all zero's. This buffer
> + * is used in the guest request message to get the certs blob from
> + * the host. If host does not supply any certs in it, then we copy
Please use passive voice: no "we" or "I", etc,
> + * zeros to indicate that certificate data was not provided.
> + */
> + memset(snp_dev->certs_data, 0, req.certs_len);
> +
> + input.data_gpa = __pa(snp_dev->certs_data);
> + npages = req.certs_len >> PAGE_SHIFT;
> + }
> +
> + /*
> + * The intermediate response buffer is used while decrypting the
> + * response payload. Make sure that it has enough space to cover the
> + * authtag.
> + */
> + resp_len = sizeof(resp->data) + crypto->a_len;
> + resp = kzalloc(resp_len, GFP_KERNEL_ACCOUNT);
> + if (!resp)
> + return -ENOMEM;
> +
> + if (copy_from_user(resp, (void __user *)arg->resp_data, sizeof(*resp))) {
> + ret = -EFAULT;
> + goto e_free;
> + }
> +
> + /* Encrypt the userspace provided payload */
> + ret = enc_payload(snp_dev, rreq->msg_version, SNP_MSG_REPORT_REQ,
> + &rreq->user_data, sizeof(rreq->user_data));
> + if (ret)
> + goto e_free;
> +
> + /* Call firmware to process the request */
> + input.req_gpa = __pa(snp_dev->request);
> + input.resp_gpa = __pa(snp_dev->response);
> + input.data_npages = npages;
> + memset(snp_dev->response, 0, sizeof(*snp_dev->response));
> + ret = snp_issue_guest_request(EXT_GUEST_REQUEST, &input, &fw_err);
> +
> + /* Popogate any firmware error to the userspace */
> + arg->fw_err = fw_err;
> +
> + /* If certs length is invalid then copy the returned length */
> + if (arg->fw_err == SNP_GUEST_REQ_INVALID_LEN) {
> + req.certs_len = input.data_npages << PAGE_SHIFT;
> +
> + if (copy_to_user((void __user *)arg->req_data, &req, sizeof(req)))
> + ret = -EFAULT;
> +
> + goto e_free;
> + }
> +
> + if (ret)
> + goto e_free;
This one is really confusing. You assign ret in the if branch
above but then you test ret outside too, just in case the
snp_issue_guest_request() call above has failed.
But then if that call has failed, you still go and do some cleanup work
for invalid certs length...
So that get_ext_report() function is doing too many things at once and
is crying to be split.
For example, the glue around snp_issue_guest_request() is already carved
out in handle_guest_request(). Why aren't you calling that function here
too?
That'll keep the enc, request, dec payload game separate and then the
rest of the logic can remain in get_ext_report()...
...
> static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned long arg)
> {
> struct snp_guest_dev *snp_dev = to_snp_dev(file);
> @@ -368,6 +480,10 @@ static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned long
> ret = get_derived_key(snp_dev, &input);
> break;
> }
> + case SNP_GET_EXT_REPORT: {
> + ret = get_ext_report(snp_dev, &input);
> + break;
> + }
> default:
> break;
> }
> @@ -453,6 +569,12 @@ static int __init snp_guest_probe(struct platform_device *pdev)
> goto e_free_req;
> }
>
> + snp_dev->certs_data = alloc_shared_pages(SEV_FW_BLOB_MAX_SIZE);
> + if (IS_ERR(snp_dev->certs_data)) {
> + ret = PTR_ERR(snp_dev->certs_data);
> + goto e_free_resp;
> + }
Same comments here as for patch 37.
> +
> misc = &snp_dev->misc;
> misc->minor = MISC_DYNAMIC_MINOR;
> misc->name = DEVICE_NAME;
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
next prev parent reply other threads:[~2021-09-08 17:53 UTC|newest]
Thread overview: 123+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-20 15:18 [PATCH Part1 v5 00/38] Add AMD Secure Nested Paging (SEV-SNP) Guest Support Brijesh Singh
2021-08-20 15:18 ` [PATCH Part1 v5 01/38] x86/mm: Add sev_feature_enabled() helper Brijesh Singh
2021-08-20 15:18 ` [PATCH Part1 v5 02/38] x86/sev: Shorten GHCB terminate macro names Brijesh Singh
2021-08-20 15:18 ` [PATCH Part1 v5 03/38] x86/sev: Get rid of excessive use of defines Brijesh Singh
2021-08-20 15:18 ` [PATCH Part1 v5 04/38] x86/head64: Carve out the guest encryption postprocessing into a helper Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 05/38] x86/sev: Define the Linux specific guest termination reasons Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 06/38] x86/sev: Save the negotiated GHCB version Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 07/38] x86/sev: Add support for hypervisor feature VMGEXIT Brijesh Singh
2021-08-23 9:47 ` Borislav Petkov
2021-08-23 18:25 ` Brijesh Singh
2021-08-23 18:34 ` Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 08/38] x86/sev: Check SEV-SNP features support Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 09/38] x86/sev: Add a helper for the PVALIDATE instruction Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 10/38] x86/sev: Check the vmpl level Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 11/38] x86/compressed: Add helper for validating pages in the decompression stage Brijesh Singh
2021-08-23 14:16 ` Borislav Petkov
2021-08-23 18:55 ` Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 12/38] x86/compressed: Register GHCB memory when SEV-SNP is active Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 13/38] x86/sev: " Brijesh Singh
2021-08-23 17:35 ` Borislav Petkov
2021-08-23 18:56 ` Brijesh Singh
2021-08-23 19:45 ` [PATCH] x86/sev: Remove do_early_exception() forward declarations Borislav Petkov
2021-08-23 20:06 ` Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 14/38] x86/sev: Add helper for validating pages in early enc attribute changes Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 15/38] x86/kernel: Make the bss.decrypted section shared in RMP table Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 16/38] x86/kernel: Validate rom memory before accessing when SEV-SNP is active Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 17/38] x86/mm: Add support to validate memory when changing C-bit Brijesh Singh
2021-08-25 11:06 ` Borislav Petkov
2021-08-25 13:54 ` Brijesh Singh
2021-08-25 14:00 ` Borislav Petkov
2021-08-27 17:09 ` Borislav Petkov
2021-08-20 15:19 ` [PATCH Part1 v5 18/38] KVM: SVM: Define sev_features and vmpl field in the VMSA Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 19/38] KVM: SVM: Create a separate mapping for the SEV-ES save area Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 20/38] KVM: SVM: Create a separate mapping for the GHCB " Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 21/38] KVM: SVM: Update the SEV-ES save area mapping Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 22/38] x86/sev: Use SEV-SNP AP creation to start secondary CPUs Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 23/38] x86/head/64: set up a startup %gs for stack protector Brijesh Singh
2021-08-25 14:29 ` Borislav Petkov
2021-08-25 15:18 ` Michael Roth
2021-08-25 16:29 ` Borislav Petkov
2021-08-27 13:38 ` Michael Roth
2021-08-31 8:03 ` Borislav Petkov
2021-08-31 23:30 ` Michael Roth
2021-08-25 15:07 ` Joerg Roedel
2021-08-25 17:07 ` Michael Roth
2021-08-20 15:19 ` [PATCH Part1 v5 24/38] x86/sev: move MSR-based VMGEXITs for CPUID to helper Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 25/38] KVM: x86: move lookup of indexed CPUID leafs " Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 26/38] x86/compressed/acpi: move EFI config table access to common code Brijesh Singh
2021-08-25 15:18 ` Borislav Petkov
2021-08-25 17:14 ` Michael Roth
2021-08-20 15:19 ` [PATCH Part1 v5 27/38] x86/boot: Add Confidential Computing type to setup_data Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 28/38] x86/compressed/64: enable SEV-SNP-validated CPUID in #VC handler Brijesh Singh
2021-08-25 19:19 ` Borislav Petkov
2021-08-27 16:46 ` Michael Roth
2021-08-31 10:04 ` Borislav Petkov
2021-09-01 1:03 ` Michael Roth
2021-09-02 10:53 ` Borislav Petkov
2021-08-20 15:19 ` [PATCH Part1 v5 29/38] x86/boot: add a pointer to Confidential Computing blob in bootparams Brijesh Singh
2021-08-27 13:51 ` Borislav Petkov
2021-08-27 18:48 ` Michael Roth
2021-08-20 15:19 ` [PATCH Part1 v5 30/38] x86/compressed/64: store Confidential Computing blob address " Brijesh Singh
2021-08-27 14:15 ` Borislav Petkov
2021-08-27 19:09 ` Michael Roth
2021-08-31 10:26 ` Borislav Petkov
2021-08-20 15:19 ` [PATCH Part1 v5 31/38] x86/compressed/64: add identity mapping for Confidential Computing blob Brijesh Singh
2021-08-27 14:43 ` Borislav Petkov
2021-08-20 15:19 ` [PATCH Part1 v5 32/38] x86/sev: enable SEV-SNP-validated CPUID in #VC handlers Brijesh Singh
2021-08-27 15:18 ` Borislav Petkov
2021-08-27 15:47 ` Brijesh Singh
2021-08-27 16:56 ` Borislav Petkov
2021-08-27 18:39 ` Michael Roth
2021-08-27 18:32 ` Michael Roth
2021-08-30 16:03 ` Michael Roth
2021-08-31 16:22 ` Borislav Petkov
2021-09-01 1:16 ` Michael Roth
2021-09-02 11:05 ` Borislav Petkov
2021-08-20 15:19 ` [PATCH Part1 v5 33/38] x86/sev: Provide support for SNP guest request NAEs Brijesh Singh
2021-08-27 17:44 ` Borislav Petkov
2021-08-27 18:07 ` Brijesh Singh
2021-08-27 18:13 ` Borislav Petkov
2021-08-27 18:27 ` Brijesh Singh
2021-08-27 18:38 ` Borislav Petkov
2021-08-27 19:57 ` Tom Lendacky
2021-08-27 20:17 ` Borislav Petkov
2021-08-27 20:31 ` Tom Lendacky
2021-08-20 15:19 ` [PATCH Part1 v5 34/38] x86/sev: Add snp_msg_seqno() helper Brijesh Singh
2021-08-27 18:41 ` Borislav Petkov
2021-08-30 15:07 ` Brijesh Singh
2021-09-02 11:26 ` Borislav Petkov
2021-09-02 15:27 ` Brijesh Singh
2021-08-31 20:46 ` Dov Murik
2021-08-31 21:13 ` Brijesh Singh
2021-09-09 14:54 ` Peter Gonda
2021-09-09 15:26 ` Brijesh Singh
2021-09-09 15:43 ` Peter Gonda
2021-09-09 16:17 ` Brijesh Singh
2021-09-09 16:21 ` Peter Gonda
2021-09-09 19:26 ` Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 35/38] x86/sev: Register SNP guest request platform device Brijesh Singh
2021-08-31 11:37 ` Dov Murik
2021-08-31 16:03 ` Brijesh Singh
2021-09-02 16:40 ` Borislav Petkov
2021-09-02 19:58 ` Brijesh Singh
2021-09-03 8:15 ` Dov Murik
2021-09-03 12:08 ` Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 36/38] virt: Add SEV-SNP guest driver Brijesh Singh
2021-09-06 17:38 ` Borislav Petkov
2021-09-07 13:35 ` Brijesh Singh
2021-09-08 13:44 ` Borislav Petkov
2021-08-20 15:19 ` [PATCH Part1 v5 37/38] virt: sevguest: Add support to derive key Brijesh Singh
2021-08-31 18:59 ` Dov Murik
2021-08-31 21:04 ` Brijesh Singh
2021-09-01 5:33 ` Dov Murik
2021-09-08 14:00 ` Borislav Petkov
2021-09-08 21:44 ` Brijesh Singh
2021-08-20 15:19 ` [PATCH Part1 v5 38/38] virt: sevguest: Add support to get extended report Brijesh Singh
2021-08-31 20:22 ` Dov Murik
2021-08-31 21:11 ` Brijesh Singh
2021-09-01 8:32 ` Dov Murik
2021-09-08 17:53 ` Borislav Petkov [this message]
2021-09-15 11:46 ` Brijesh Singh
2021-09-15 10:02 ` Dr. David Alan Gilbert
2021-09-15 11:53 ` Brijesh Singh
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=YTj4kZCTudDauIn1@zn.tnic \
--to=bp@alien8.de \
--cc=ak@linux.intel.com \
--cc=ardb@kernel.org \
--cc=brijesh.singh@amd.com \
--cc=dave.hansen@linux.intel.com \
--cc=dovmurik@linux.ibm.com \
--cc=hpa@zytor.com \
--cc=jmattson@google.com \
--cc=jroedel@suse.de \
--cc=kirill@shutemov.name \
--cc=kvm@vger.kernel.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=marcorr@google.com \
--cc=michael.roth@amd.com \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=pgonda@google.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=rientjes@google.com \
--cc=sathyanarayanan.kuppuswamy@linux.intel.com \
--cc=seanjc@google.com \
--cc=slp@redhat.com \
--cc=srinivas.pandruvada@linux.intel.com \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=tobin@ibm.com \
--cc=tony.luck@intel.com \
--cc=vbabka@suse.cz \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=x86@kernel.org \
/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 NNTP newsgroup(s).