Thread (305 messages) 305 messages, 22 authors, 2023-01-05

RE: [PATCH Part2 v6 17/49] crypto: ccp: Add the SNP_{SET,GET}_EXT_CONFIG command

From: "Kalra, Ashish" <Ashish.Kalra@amd.com>
Date: 2022-06-22 01:58:17
Also in: kvm, linux-crypto, linux-mm, lkml

[AMD Official Use Only - General]

Hello Peter,
quoted
+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. 
quoted
+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 ?
quoted
+       /*
+        * 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.
quoted
        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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help