[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <BYAPR12MB2759B6CBC481A4A45167589A8EB29@BYAPR12MB2759.namprd12.prod.outlook.com>
Date: Wed, 22 Jun 2022 01:58:09 +0000
From: "Kalra, Ashish" <Ashish.Kalra@....com>
To: Peter Gonda <pgonda@...gle.com>
CC: the arch/x86 maintainers <x86@...nel.org>,
LKML <linux-kernel@...r.kernel.org>,
kvm list <kvm@...r.kernel.org>,
"linux-coco@...ts.linux.dev" <linux-coco@...ts.linux.dev>,
"linux-mm@...ck.org" <linux-mm@...ck.org>,
Linux Crypto Mailing List <linux-crypto@...r.kernel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Joerg Roedel <jroedel@...e.de>,
"Lendacky, Thomas" <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>,
Jim Mattson <jmattson@...gle.com>,
Andy Lutomirski <luto@...nel.org>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Sergio Lopez <slp@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Srinivas Pandruvada <srinivas.pandruvada@...ux.intel.com>,
David Rientjes <rientjes@...gle.com>,
Dov Murik <dovmurik@...ux.ibm.com>,
Tobin Feldman-Fitzthum <tobin@....com>,
Borislav Petkov <bp@...en8.de>,
"Roth, Michael" <Michael.Roth@....com>,
Vlastimil Babka <vbabka@...e.cz>,
"Kirill A . Shutemov" <kirill@...temov.name>,
Andi Kleen <ak@...ux.intel.com>,
Tony Luck <tony.luck@...el.com>, Marc Orr <marcorr@...gle.com>,
Sathyanarayanan Kuppuswamy
<sathyanarayanan.kuppuswamy@...ux.intel.com>,
Alper Gun <alpergun@...gle.com>,
"Dr. David Alan Gilbert" <dgilbert@...hat.com>,
"jarkko@...nel.org" <jarkko@...nel.org>
Subject: RE: [PATCH Part2 v6 17/49] crypto: ccp: Add the
SNP_{SET,GET}_EXT_CONFIG command
[AMD Official Use Only - General]
Hello Peter,
>> +static int sev_ioctl_snp_get_config(struct sev_issue_cmd *argp) {
>> + struct sev_device *sev = psp_master->sev_data;
>> + struct sev_user_data_ext_snp_config input;
>Lets memset |input| to zero to avoid leaking kernel memory, see
>"crypto: ccp - Use kzalloc for sev ioctl interfaces to prevent kernel memory leak"
Yes.
>> +static int sev_ioctl_snp_set_config(struct sev_issue_cmd *argp, bool
>> +writable) {
>> + struct sev_device *sev = psp_master->sev_data;
>> + struct sev_user_data_ext_snp_config input;
>> + struct sev_user_data_snp_config config;
>> + void *certs = NULL;
>> + int ret = 0;
>> +
>> + if (!sev->snp_inited || !argp->data)
>> + return -EINVAL;
>> +
>> + if (!writable)
>> + return -EPERM;
>> +
>> + if (copy_from_user(&input, (void __user *)argp->data, sizeof(input)))
>> + return -EFAULT;
>> +
>> + /* Copy the certs from userspace */
>> + if (input.certs_address) {
>> + if (!input.certs_len || !IS_ALIGNED(input.certs_len, PAGE_SIZE))
>> + return -EINVAL;
>> +
>> + certs = psp_copy_user_blob(input.certs_address,
>> + input.certs_len);
>I see that psp_copy_user_blob() uses memdup_user() which tracks the allocated memory to GFP_USER. Given this memory is long lived and now belongs to the PSP driver in perpetuity, should this be tracked with GFP_KERNEL?
But we need to copy from user space address, so what is the alternative here ?
>> + /*
>> + * If the new certs are passed then cache it else free the old certs.
>> + */
>> + if (certs) {
>> + kfree(sev->snp_certs_data);
>> + sev->snp_certs_data = certs;
>> + sev->snp_certs_len = input.certs_len;
>> + } else {
>> + kfree(sev->snp_certs_data);
>> + sev->snp_certs_data = NULL;
>> + sev->snp_certs_len = 0;
>> + }
>Do we need another lock here? When I look at 18/49 it seems like
>snp_guest_ext_guest_request() it seems like we have a race for
>|sev->snp_certs_data|
The certificate blob in snp_guest_ext_guest_request() will depend on the
certificate blob provided here by SNP_SET_EXT_CONFIG. There might be a potential
race with the SNP extended guest request NAE, let me have a look at it.
>> bool snp_inited;
>> struct snp_host_map snp_host_map[MAX_SNP_HOST_MAP_BUFS];
>> + void *snp_certs_data;
>> + u32 snp_certs_len;
>> + struct sev_user_data_snp_config snp_config;
>Since this gets copy_to_user'd can we memset this to 0 to prevent leaking kernel uninitialized memory? Similar to recent patches with kzalloc and __GPF_ZERO usage.
Yes.
Thanks,
Ashish
Powered by blists - more mailing lists