crypto: ccp - Fix sparse warnings in sev-dev

This patch fixes a bunch of sparse warnings in sev-dev where the
__user marking is incorrectly handled.

Reported-by: kbuild test robot <lkp@intel.com>
Fixes: 7360e4b143 ("crypto: ccp: Implement SEV_PEK_CERT_IMPORT...")
Fixes: e799035609 ("crypto: ccp: Implement SEV_PEK_CSR ioctl...")
Fixes: 76a2b524a4 ("crypto: ccp: Implement SEV_PDH_CERT_EXPORT...")
Fixes: d6112ea0cb ("crypto: ccp - introduce SEV_GET_ID2 command")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Reviewed-by: Brijesh Singh <brijesh.singh@amd.com>
Acked-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Herbert Xu 2020-06-04 18:09:41 +10:00
parent c61e5644c6
commit 376bd28d03
2 changed files with 17 additions and 8 deletions

View File

@ -376,6 +376,7 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable)
struct sev_device *sev = psp_master->sev_data; struct sev_device *sev = psp_master->sev_data;
struct sev_user_data_pek_csr input; struct sev_user_data_pek_csr input;
struct sev_data_pek_csr *data; struct sev_data_pek_csr *data;
void __user *input_address;
void *blob = NULL; void *blob = NULL;
int ret; int ret;
@ -394,6 +395,7 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable)
goto cmd; goto cmd;
/* allocate a physically contiguous buffer to store the CSR blob */ /* allocate a physically contiguous buffer to store the CSR blob */
input_address = (void __user *)input.address;
if (input.length > SEV_FW_BLOB_MAX_SIZE) { if (input.length > SEV_FW_BLOB_MAX_SIZE) {
ret = -EFAULT; ret = -EFAULT;
goto e_free; goto e_free;
@ -426,7 +428,7 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable)
} }
if (blob) { if (blob) {
if (copy_to_user((void __user *)input.address, blob, input.length)) if (copy_to_user(input_address, blob, input.length))
ret = -EFAULT; ret = -EFAULT;
} }
@ -437,7 +439,7 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable)
return ret; return ret;
} }
void *psp_copy_user_blob(u64 __user uaddr, u32 len) void *psp_copy_user_blob(u64 uaddr, u32 len)
{ {
if (!uaddr || !len) if (!uaddr || !len)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
@ -446,7 +448,7 @@ void *psp_copy_user_blob(u64 __user uaddr, u32 len)
if (len > SEV_FW_BLOB_MAX_SIZE) if (len > SEV_FW_BLOB_MAX_SIZE)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
return memdup_user((void __user *)(uintptr_t)uaddr, len); return memdup_user((void __user *)uaddr, len);
} }
EXPORT_SYMBOL_GPL(psp_copy_user_blob); EXPORT_SYMBOL_GPL(psp_copy_user_blob);
@ -621,6 +623,7 @@ static int sev_ioctl_do_get_id2(struct sev_issue_cmd *argp)
{ {
struct sev_user_data_get_id2 input; struct sev_user_data_get_id2 input;
struct sev_data_get_id *data; struct sev_data_get_id *data;
void __user *input_address;
void *id_blob = NULL; void *id_blob = NULL;
int ret; int ret;
@ -631,6 +634,8 @@ static int sev_ioctl_do_get_id2(struct sev_issue_cmd *argp)
if (copy_from_user(&input, (void __user *)argp->data, sizeof(input))) if (copy_from_user(&input, (void __user *)argp->data, sizeof(input)))
return -EFAULT; return -EFAULT;
input_address = (void __user *)input.address;
data = kzalloc(sizeof(*data), GFP_KERNEL); data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
@ -660,8 +665,7 @@ static int sev_ioctl_do_get_id2(struct sev_issue_cmd *argp)
} }
if (id_blob) { if (id_blob) {
if (copy_to_user((void __user *)input.address, if (copy_to_user(input_address, id_blob, data->len)) {
id_blob, data->len)) {
ret = -EFAULT; ret = -EFAULT;
goto e_free; goto e_free;
} }
@ -720,6 +724,8 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)
struct sev_user_data_pdh_cert_export input; struct sev_user_data_pdh_cert_export input;
void *pdh_blob = NULL, *cert_blob = NULL; void *pdh_blob = NULL, *cert_blob = NULL;
struct sev_data_pdh_cert_export *data; struct sev_data_pdh_cert_export *data;
void __user *input_cert_chain_address;
void __user *input_pdh_cert_address;
int ret; int ret;
/* If platform is not in INIT state then transition it to INIT. */ /* If platform is not in INIT state then transition it to INIT. */
@ -745,6 +751,9 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)
!input.cert_chain_address) !input.cert_chain_address)
goto cmd; goto cmd;
input_pdh_cert_address = (void __user *)input.pdh_cert_address;
input_cert_chain_address = (void __user *)input.cert_chain_address;
/* Allocate a physically contiguous buffer to store the PDH blob. */ /* Allocate a physically contiguous buffer to store the PDH blob. */
if (input.pdh_cert_len > SEV_FW_BLOB_MAX_SIZE) { if (input.pdh_cert_len > SEV_FW_BLOB_MAX_SIZE) {
ret = -EFAULT; ret = -EFAULT;
@ -788,7 +797,7 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)
} }
if (pdh_blob) { if (pdh_blob) {
if (copy_to_user((void __user *)input.pdh_cert_address, if (copy_to_user(input_pdh_cert_address,
pdh_blob, input.pdh_cert_len)) { pdh_blob, input.pdh_cert_len)) {
ret = -EFAULT; ret = -EFAULT;
goto e_free_cert; goto e_free_cert;
@ -796,7 +805,7 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)
} }
if (cert_blob) { if (cert_blob) {
if (copy_to_user((void __user *)input.cert_chain_address, if (copy_to_user(input_cert_chain_address,
cert_blob, input.cert_chain_len)) cert_blob, input.cert_chain_len))
ret = -EFAULT; ret = -EFAULT;
} }

View File

@ -597,7 +597,7 @@ int sev_guest_df_flush(int *error);
*/ */
int sev_guest_decommission(struct sev_data_decommission *data, int *error); int sev_guest_decommission(struct sev_data_decommission *data, int *error);
void *psp_copy_user_blob(u64 __user uaddr, u32 len); void *psp_copy_user_blob(u64 uaddr, u32 len);
#else /* !CONFIG_CRYPTO_DEV_SP_PSP */ #else /* !CONFIG_CRYPTO_DEV_SP_PSP */