Re: [PATCH v3 02/11] KVM: SVM: Add KVM_SEND_UPDATE_DATA command

From: Peter Gonda
Date: Tue Nov 12 2019 - 17:23:22 EST


On Wed, Jul 10, 2019 at 1:14 PM Singh, Brijesh <brijesh.singh@xxxxxxx> wrote:

> +static int sev_send_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp)
> +{
> + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info;
> + struct sev_data_send_update_data *data;
> + struct kvm_sev_send_update_data params;
> + void *hdr = NULL, *trans_data = NULL;
> + struct page **guest_page = NULL;
> + unsigned long n;
> + int ret, offset;
> +
> + if (!sev_guest(kvm))
> + return -ENOTTY;
> +
> + if (copy_from_user(&params, (void __user *)(uintptr_t)argp->data,
> + sizeof(struct kvm_sev_send_update_data)))
> + return -EFAULT;
> +
> + data = kzalloc(sizeof(*data), GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + /* userspace wants to query either header or trans length */
> + if (!params.trans_len || !params.hdr_len)
> + goto cmd;
> +
> + ret = -EINVAL;
> + if (!params.trans_uaddr || !params.guest_uaddr ||
> + !params.guest_len || !params.hdr_uaddr)
> + goto e_free;
> +
> + /* Check if we are crossing the page boundry */
> + ret = -EINVAL;
> + offset = params.guest_uaddr & (PAGE_SIZE - 1);
> + if ((params.guest_len + offset > PAGE_SIZE))
> + goto e_free;
> +
> + ret = -ENOMEM;
> + hdr = kmalloc(params.hdr_len, GFP_KERNEL);
> + if (!hdr)
> + goto e_free;

Should we be checking params.hdr_len against SEV_FW_BLOB_MAX_SIZE?

> +
> + data->hdr_address = __psp_pa(hdr);
> + data->hdr_len = params.hdr_len;
> +
> + ret = -ENOMEM;
> + trans_data = kmalloc(params.trans_len, GFP_KERNEL);
> + if (!trans_data)
> + goto e_free;

Ditto, should we be checking params.hdr_len against SEV_FW_BLOB_MAX_SIZE?