@@ -455,14 +455,22 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp)
if (!data)
return -ENOMEM;
- /* Userspace wants to query the certificate length */
- if (!input.pdh_cert_address || !input.pdh_cert_len ||
- !input.cert_chain_address || !input.cert_chain_address)
+ /* Userspace wants to query the certificate length. */
+ if (!input.pdh_cert_address ||
+ !input.pdh_cert_len ||
+ !input.cert_chain_address)
goto cmd;
- /* allocate a physically contiguous buffer to store the PDH blob */
- if (!access_ok(VERIFY_WRITE, input.pdh_cert_address, input.pdh_cert_len) ||
- (input.pdh_cert_len > SEV_FW_BLOB_MAX_SIZE)) {
+ /* allocate a physically contiguous buffer to store the PDH blob. */
+ if ((input.pdh_cert_len > SEV_FW_BLOB_MAX_SIZE) ||
+ !access_ok(VERIFY_WRITE, input.pdh_cert_address, input.pdh_cert_len)) {
+ ret = -EFAULT;
+ goto e_free;
+ }
+
+ /* allocate a physically contiguous buffer to store the cert chain blob. */
+ if ((input.cert_chain_len > SEV_FW_BLOB_MAX_SIZE) ||
+ !access_ok(VERIFY_WRITE, input.cert_chain_address, input.cert_chain_len)) {
ret = -EFAULT;
goto e_free;
}
@@ -476,13 +484,6 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp)
data->pdh_cert_address = __psp_pa(pdh_blob);
data->pdh_cert_len = input.pdh_cert_len;
- /* allocate a physically contiguous buffer to store the cert chain blob */
- if (!access_ok(VERIFY_WRITE, input.cert_chain_address, input.cert_chain_len) ||
- (input.cert_chain_len > SEV_FW_BLOB_MAX_SIZE)) {
- ret = -EFAULT;
- goto e_free_pdh;
- }
-
cert_blob = kmalloc(input.cert_chain_len, GFP_KERNEL);
if (!cert_blob) {
ret = -ENOMEM;
@@ -493,18 +494,16 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp)
data->cert_chain_len = input.cert_chain_len;
cmd:
- /* If platform is not in INIT state then transition it to INIT */
+ /* If platform is not in INIT state then transition it to INIT. */
if (psp_master->sev_state != SEV_STATE_INIT) {
- ret = __sev_platform_init_locked(psp_master->sev_init, &argp->error);
+ ret = __sev_platform_init_locked(&psp_master->cmd_buf, &argp->error);
if (ret)
goto e_free_cert;
}
ret = __sev_do_cmd_locked(SEV_CMD_PDH_CERT_EXPORT, data, &argp->error);
- /*
- * If we query the length, FW responded with expected data
- */
+ /* If we query the length, FW responded with expected data. */
input.cert_chain_len = data->cert_chain_len;
input.pdh_cert_len = data->pdh_cert_len;