Skip to content

Commit 376bd28

Browse files
committed
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 <[email protected]> Fixes: 7360e4b ("crypto: ccp: Implement SEV_PEK_CERT_IMPORT...") Fixes: e799035 ("crypto: ccp: Implement SEV_PEK_CSR ioctl...") Fixes: 76a2b52 ("crypto: ccp: Implement SEV_PDH_CERT_EXPORT...") Fixes: d6112ea ("crypto: ccp - introduce SEV_GET_ID2 command") Signed-off-by: Herbert Xu <[email protected]> Reviewed-by: Brijesh Singh <[email protected]> Acked-by: Tom Lendacky <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent c61e564 commit 376bd28

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

drivers/crypto/ccp/sev-dev.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable)
376376
struct sev_device *sev = psp_master->sev_data;
377377
struct sev_user_data_pek_csr input;
378378
struct sev_data_pek_csr *data;
379+
void __user *input_address;
379380
void *blob = NULL;
380381
int ret;
381382

@@ -394,6 +395,7 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable)
394395
goto cmd;
395396

396397
/* allocate a physically contiguous buffer to store the CSR blob */
398+
input_address = (void __user *)input.address;
397399
if (input.length > SEV_FW_BLOB_MAX_SIZE) {
398400
ret = -EFAULT;
399401
goto e_free;
@@ -426,7 +428,7 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable)
426428
}
427429

428430
if (blob) {
429-
if (copy_to_user((void __user *)input.address, blob, input.length))
431+
if (copy_to_user(input_address, blob, input.length))
430432
ret = -EFAULT;
431433
}
432434

@@ -437,7 +439,7 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable)
437439
return ret;
438440
}
439441

440-
void *psp_copy_user_blob(u64 __user uaddr, u32 len)
442+
void *psp_copy_user_blob(u64 uaddr, u32 len)
441443
{
442444
if (!uaddr || !len)
443445
return ERR_PTR(-EINVAL);
@@ -446,7 +448,7 @@ void *psp_copy_user_blob(u64 __user uaddr, u32 len)
446448
if (len > SEV_FW_BLOB_MAX_SIZE)
447449
return ERR_PTR(-EINVAL);
448450

449-
return memdup_user((void __user *)(uintptr_t)uaddr, len);
451+
return memdup_user((void __user *)uaddr, len);
450452
}
451453
EXPORT_SYMBOL_GPL(psp_copy_user_blob);
452454

@@ -621,6 +623,7 @@ static int sev_ioctl_do_get_id2(struct sev_issue_cmd *argp)
621623
{
622624
struct sev_user_data_get_id2 input;
623625
struct sev_data_get_id *data;
626+
void __user *input_address;
624627
void *id_blob = NULL;
625628
int ret;
626629

@@ -631,6 +634,8 @@ static int sev_ioctl_do_get_id2(struct sev_issue_cmd *argp)
631634
if (copy_from_user(&input, (void __user *)argp->data, sizeof(input)))
632635
return -EFAULT;
633636

637+
input_address = (void __user *)input.address;
638+
634639
data = kzalloc(sizeof(*data), GFP_KERNEL);
635640
if (!data)
636641
return -ENOMEM;
@@ -660,8 +665,7 @@ static int sev_ioctl_do_get_id2(struct sev_issue_cmd *argp)
660665
}
661666

662667
if (id_blob) {
663-
if (copy_to_user((void __user *)input.address,
664-
id_blob, data->len)) {
668+
if (copy_to_user(input_address, id_blob, data->len)) {
665669
ret = -EFAULT;
666670
goto e_free;
667671
}
@@ -720,6 +724,8 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)
720724
struct sev_user_data_pdh_cert_export input;
721725
void *pdh_blob = NULL, *cert_blob = NULL;
722726
struct sev_data_pdh_cert_export *data;
727+
void __user *input_cert_chain_address;
728+
void __user *input_pdh_cert_address;
723729
int ret;
724730

725731
/* 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)
745751
!input.cert_chain_address)
746752
goto cmd;
747753

754+
input_pdh_cert_address = (void __user *)input.pdh_cert_address;
755+
input_cert_chain_address = (void __user *)input.cert_chain_address;
756+
748757
/* Allocate a physically contiguous buffer to store the PDH blob. */
749758
if (input.pdh_cert_len > SEV_FW_BLOB_MAX_SIZE) {
750759
ret = -EFAULT;
@@ -788,15 +797,15 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)
788797
}
789798

790799
if (pdh_blob) {
791-
if (copy_to_user((void __user *)input.pdh_cert_address,
800+
if (copy_to_user(input_pdh_cert_address,
792801
pdh_blob, input.pdh_cert_len)) {
793802
ret = -EFAULT;
794803
goto e_free_cert;
795804
}
796805
}
797806

798807
if (cert_blob) {
799-
if (copy_to_user((void __user *)input.cert_chain_address,
808+
if (copy_to_user(input_cert_chain_address,
800809
cert_blob, input.cert_chain_len))
801810
ret = -EFAULT;
802811
}

include/linux/psp-sev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ int sev_guest_df_flush(int *error);
597597
*/
598598
int sev_guest_decommission(struct sev_data_decommission *data, int *error);
599599

600-
void *psp_copy_user_blob(u64 __user uaddr, u32 len);
600+
void *psp_copy_user_blob(u64 uaddr, u32 len);
601601

602602
#else /* !CONFIG_CRYPTO_DEV_SP_PSP */
603603

0 commit comments

Comments
 (0)