[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <55df11df-bf30-171e-9774-e6a6d380802a@linux.ibm.com>
Date: Wed, 1 Sep 2021 08:33:11 +0300
From: Dov Murik <dovmurik@...ux.ibm.com>
To: Brijesh Singh <brijesh.singh@....com>, x86@...nel.org,
linux-kernel@...r.kernel.org, kvm@...r.kernel.org,
linux-efi@...r.kernel.org, platform-driver-x86@...r.kernel.org,
linux-coco@...ts.linux.dev, linux-mm@...ck.org
Cc: Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Joerg Roedel <jroedel@...e.de>,
Tom Lendacky <thomas.lendacky@....com>,
"H. Peter Anvin" <hpa@...or.com>, Ard Biesheuvel <ardb@...nel.org>,
Paolo Bonzini <pbonzini@...hat.com>,
Sean Christopherson <seanjc@...gle.com>,
Vitaly Kuznetsov <vkuznets@...hat.com>,
Wanpeng Li <wanpengli@...cent.com>,
Jim Mattson <jmattson@...gle.com>,
Andy Lutomirski <luto@...nel.org>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Sergio Lopez <slp@...hat.com>, Peter Gonda <pgonda@...gle.com>,
Peter Zijlstra <peterz@...radead.org>,
Srinivas Pandruvada <srinivas.pandruvada@...ux.intel.com>,
David Rientjes <rientjes@...gle.com>,
Tobin Feldman-Fitzthum <tobin@....com>,
Borislav Petkov <bp@...en8.de>,
Michael Roth <michael.roth@....com>,
Vlastimil Babka <vbabka@...e.cz>,
"Kirill A . Shutemov" <kirill@...temov.name>,
Andi Kleen <ak@...ux.intel.com>, tony.luck@...el.com,
marcorr@...gle.com, sathyanarayanan.kuppuswamy@...ux.intel.com,
Dov Murik <dovmurik@...ux.ibm.com>
Subject: Re: [PATCH Part1 v5 37/38] virt: sevguest: Add support to derive key
On 01/09/2021 0:04, Brijesh Singh wrote:
> Hi Dov,
>
>
> On 8/31/21 1:59 PM, Dov Murik wrote:
>>> +
>>> + /*
>>> + * 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);
>>
>> The length of resp->data is 64 bytes; I assume crypto->a_len is not a
>> lot more (and probably known in advance for AES GCM). Maybe use a
>> buffer on the stack instead of allocating and freeing?
>>
>
> The authtag size can be up to 16 bytes, so I guess I can allocate 80
> bytes on stack and avoid the kzalloc().
>
>>
>>> + if (!resp)
>>> + return -ENOMEM;
>>> +
>>> + /* Issue the command to get the attestation report */
>>> + rc = handle_guest_request(snp_dev, req.msg_version,
>>> SNP_MSG_KEY_REQ,
>>> + &req.data, sizeof(req.data), resp->data, resp_len,
>>> + &arg->fw_err);
>>> + if (rc)
>>> + goto e_free;
>>> +
>>> + /* Copy the response payload to userspace */
>>> + if (copy_to_user((void __user *)arg->resp_data, resp,
>>> sizeof(*resp)))
>>> + rc = -EFAULT;
>>> +
>>> +e_free:
>>> + kfree(resp);
>>
>> Since resp contains key material, I think you should explicit_memzero()
>> it before freeing, so the key bytes don't linger around in unused
>> memory. I'm not sure if any copies are made inside the
>> handle_guest_request call above; maybe zero these as well.
>>
>
> I can do that, but I guess I am trying to find a reason for it. The resp
> buffer is encrypted page, so, the key is protected from the hypervisor
> access. Are you thinking about an attack within the VM guest OS ?
>
Yes, that's the concern, specifically with sensitive buffers (keys).
You don't want many copies floating around in unused memory.
-Dov
Powered by blists - more mailing lists