2018-03-05 14:17:59

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] crypto: ccp: Use memdup_user() rather than duplicating its implementation

From: Markus Elfring <[email protected]>
Date: Mon, 5 Mar 2018 13:50:13 +0100

Reuse existing functionality from memdup_user() instead of keeping
duplicate source code.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/crypto/ccp/psp-dev.c | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
index fcfa5b1eae61..8255258cd040 100644
--- a/drivers/crypto/ccp/psp-dev.c
+++ b/drivers/crypto/ccp/psp-dev.c
@@ -367,8 +367,6 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp)

void *psp_copy_user_blob(u64 __user uaddr, u32 len)
{
- void *data;
-
if (!uaddr || !len)
return ERR_PTR(-EINVAL);

@@ -376,18 +374,7 @@ void *psp_copy_user_blob(u64 __user uaddr, u32 len)
if (len > SEV_FW_BLOB_MAX_SIZE)
return ERR_PTR(-EINVAL);

- data = kmalloc(len, GFP_KERNEL);
- if (!data)
- return ERR_PTR(-ENOMEM);
-
- if (copy_from_user(data, (void __user *)(uintptr_t)uaddr, len))
- goto e_free;
-
- return data;
-
-e_free:
- kfree(data);
- return ERR_PTR(-EFAULT);
+ return memdup_user((void __user *)(uintptr_t)uaddr, len);
}
EXPORT_SYMBOL_GPL(psp_copy_user_blob);

--
2.16.2



2018-03-05 18:54:26

by Brijesh Singh

[permalink] [raw]
Subject: Re: [PATCH] crypto: ccp: Use memdup_user() rather than duplicating its implementation



On 3/5/18 7:10 AM, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Mon, 5 Mar 2018 13:50:13 +0100
>
> Reuse existing functionality from memdup_user() instead of keeping
> duplicate source code.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/crypto/ccp/psp-dev.c | 15 +--------------
> 1 file changed, 1 insertion(+), 14 deletions(-)

Reviewed-by: Brijesh Singh <[email protected]>

thanks

> diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
> index fcfa5b1eae61..8255258cd040 100644
> --- a/drivers/crypto/ccp/psp-dev.c
> +++ b/drivers/crypto/ccp/psp-dev.c
> @@ -367,8 +367,6 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp)
>
> void *psp_copy_user_blob(u64 __user uaddr, u32 len)
> {
> - void *data;
> -
> if (!uaddr || !len)
> return ERR_PTR(-EINVAL);
>
> @@ -376,18 +374,7 @@ void *psp_copy_user_blob(u64 __user uaddr, u32 len)
> if (len > SEV_FW_BLOB_MAX_SIZE)
> return ERR_PTR(-EINVAL);
>
> - data = kmalloc(len, GFP_KERNEL);
> - if (!data)
> - return ERR_PTR(-ENOMEM);
> -
> - if (copy_from_user(data, (void __user *)(uintptr_t)uaddr, len))
> - goto e_free;
> -
> - return data;
> -
> -e_free:
> - kfree(data);
> - return ERR_PTR(-EFAULT);
> + return memdup_user((void __user *)(uintptr_t)uaddr, len);
> }
> EXPORT_SYMBOL_GPL(psp_copy_user_blob);
>


2018-03-05 19:43:50

by Gary R Hook

[permalink] [raw]
Subject: Re: [PATCH] crypto: ccp: Use memdup_user() rather than duplicating its implementation

On 03/05/2018 07:10 AM, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Mon, 5 Mar 2018 13:50:13 +0100
>
> Reuse existing functionality from memdup_user() instead of keeping
> duplicate source code.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <[email protected]>

Acked-by: Gary R Hook <[email protected]>

> ---
> drivers/crypto/ccp/psp-dev.c | 15 +--------------
> 1 file changed, 1 insertion(+), 14 deletions(-)
>
> diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
> index fcfa5b1eae61..8255258cd040 100644
> --- a/drivers/crypto/ccp/psp-dev.c
> +++ b/drivers/crypto/ccp/psp-dev.c
> @@ -367,8 +367,6 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp)
>
> void *psp_copy_user_blob(u64 __user uaddr, u32 len)
> {
> - void *data;
> -
> if (!uaddr || !len)
> return ERR_PTR(-EINVAL);
>
> @@ -376,18 +374,7 @@ void *psp_copy_user_blob(u64 __user uaddr, u32 len)
> if (len > SEV_FW_BLOB_MAX_SIZE)
> return ERR_PTR(-EINVAL);
>
> - data = kmalloc(len, GFP_KERNEL);
> - if (!data)
> - return ERR_PTR(-ENOMEM);
> -
> - if (copy_from_user(data, (void __user *)(uintptr_t)uaddr, len))
> - goto e_free;
> -
> - return data;
> -
> -e_free:
> - kfree(data);
> - return ERR_PTR(-EFAULT);
> + return memdup_user((void __user *)(uintptr_t)uaddr, len);
> }
> EXPORT_SYMBOL_GPL(psp_copy_user_blob);
>
>


2018-03-16 15:55:54

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH] crypto: ccp: Use memdup_user() rather than duplicating its implementation

On Mon, Mar 05, 2018 at 02:10:20PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Mon, 5 Mar 2018 13:50:13 +0100
>
> Reuse existing functionality from memdup_user() instead of keeping
> duplicate source code.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <[email protected]>

Patch applied. Thanks.
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt