diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c index 1603dc8d2d75..703901526a62 100644 --- a/drivers/crypto/ccp/psp-dev.c +++ b/drivers/crypto/ccp/psp-dev.c @@ -387,7 +387,10 @@ cmd: ret = __sev_do_cmd_locked(SEV_CMD_PEK_CSR, data, &argp->error); - /* If we query the CSR length, FW responded with expected data. */ + /* + * Firmware will returns the length of the CSR blob (either the minimum + * required length or the actual length written), return it to the user. + */ input.length = data->len; if (copy_to_user((void __user *)argp->data, &input, sizeof(input))) { @@ -395,6 +398,9 @@ cmd: goto e_free_blob; } + if (ret || WARN_ON_ONCE(argp->error)) + goto e_free_blob; + if (blob) { if (copy_to_user((void __user *)input.address, blob, input.length)) ret = -EFAULT;