2019-09-14 14:18:37

by Navid Emamdoost

[permalink] [raw]
Subject: [PATCH] crypto: ccp - release hmac_buf if ccp_run_sha_cmd fails

In ccp_run_sha_cmd, if the type of sha is invalid, the allocated
hmac_buf should be released.

Signed-off-by: Navid Emamdoost <[email protected]>
---
drivers/crypto/ccp/ccp-ops.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c
index 9bc3c62157d7..cff16f0cc15b 100644
--- a/drivers/crypto/ccp/ccp-ops.c
+++ b/drivers/crypto/ccp/ccp-ops.c
@@ -1782,6 +1782,7 @@ static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
LSB_ITEM_SIZE);
break;
default:
+ kfree(hmac_buf);
ret = -EINVAL;
goto e_ctx;
}
--
2.17.1


2019-09-16 13:24:16

by Tom Lendacky

[permalink] [raw]
Subject: Re: [PATCH] crypto: ccp - release hmac_buf if ccp_run_sha_cmd fails

On 9/13/19 6:48 PM, Navid Emamdoost wrote:
> In ccp_run_sha_cmd, if the type of sha is invalid, the allocated
> hmac_buf should be released.
>
> Signed-off-by: Navid Emamdoost <[email protected]>
> ---
> drivers/crypto/ccp/ccp-ops.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c
> index 9bc3c62157d7..cff16f0cc15b 100644
> --- a/drivers/crypto/ccp/ccp-ops.c
> +++ b/drivers/crypto/ccp/ccp-ops.c
> @@ -1782,6 +1782,7 @@ static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
> LSB_ITEM_SIZE);
> break;
> default:
> + kfree(hmac_buf);

Well, theoretically we can never reach this section since the routine
would have never proceeded past the first switch statement at the
beginning of the function. But, if the code is ever modified and some of
the switch statements missed then it's possible...

> ret = -EINVAL;
> goto e_ctx;

I know it's not part of your change, but this looks like it should be
goto e_data instead of e_ctx, too.

Thanks,
Tom

> }
>

2019-09-19 13:55:29

by Gary R Hook

[permalink] [raw]
Subject: Re: [PATCH] crypto: ccp - release hmac_buf if ccp_run_sha_cmd fails

On 9/16/19 8:22 AM, Lendacky, Thomas wrote:
> On 9/13/19 6:48 PM, Navid Emamdoost wrote:
>> In ccp_run_sha_cmd, if the type of sha is invalid, the allocated
>> hmac_buf should be released.
>>
>> Signed-off-by: Navid Emamdoost <[email protected]>
>> ---
>> drivers/crypto/ccp/ccp-ops.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c
>> index 9bc3c62157d7..cff16f0cc15b 100644
>> --- a/drivers/crypto/ccp/ccp-ops.c
>> +++ b/drivers/crypto/ccp/ccp-ops.c
>> @@ -1782,6 +1782,7 @@ static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
>> LSB_ITEM_SIZE);
>> break;
>> default:
>> + kfree(hmac_buf);
> Well, theoretically we can never reach this section since the routine
> would have never proceeded past the first switch statement at the
> beginning of the function. But, if the code is ever modified and some of
> the switch statements missed then it's possible...
>
>> ret = -EINVAL;
>> goto e_ctx;
> I know it's not part of your change, but this looks like it should be
> goto e_data instead of e_ctx, too.
I agree with this. Please resubmit with the suggested change, and use a
commit message along the the lines of

crypto: ccp - Release all allocated memory if sha type is invalid


Gary

2019-09-19 18:22:03

by Navid Emamdoost

[permalink] [raw]
Subject: [PATCH v2] crypto: ccp - Release all allocated memory if sha type is invalid

Release all allocated memory if sha type is invalid:
In ccp_run_sha_cmd, if the type of sha is invalid, the allocated
hmac_buf should be released.

v2: fix the goto.

Signed-off-by: Navid Emamdoost <[email protected]>
---
drivers/crypto/ccp/ccp-ops.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c
index 9bc3c62157d7..440df9208f8f 100644
--- a/drivers/crypto/ccp/ccp-ops.c
+++ b/drivers/crypto/ccp/ccp-ops.c
@@ -1782,8 +1782,9 @@ static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
LSB_ITEM_SIZE);
break;
default:
+ kfree(hmac_buf);
ret = -EINVAL;
- goto e_ctx;
+ goto e_data;
}

memset(&hmac_cmd, 0, sizeof(hmac_cmd));
--
2.17.1

2019-09-19 18:43:43

by Gary R Hook

[permalink] [raw]
Subject: Re: [PATCH v2] crypto: ccp - Release all allocated memory if sha type is invalid



On 9/19/19 11:04 AM, Navid Emamdoost wrote:
> Release all allocated memory if sha type is invalid:
> In ccp_run_sha_cmd, if the type of sha is invalid, the allocated
> hmac_buf should be released.
>
> v2: fix the goto.
>
> Signed-off-by: Navid Emamdoost <[email protected]>

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

> ---
> drivers/crypto/ccp/ccp-ops.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c
> index 9bc3c62157d7..440df9208f8f 100644
> --- a/drivers/crypto/ccp/ccp-ops.c
> +++ b/drivers/crypto/ccp/ccp-ops.c
> @@ -1782,8 +1782,9 @@ static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
> LSB_ITEM_SIZE);
> break;
> default:
> + kfree(hmac_buf);
> ret = -EINVAL;
> - goto e_ctx;
> + goto e_data;
> }
>
> memset(&hmac_cmd, 0, sizeof(hmac_cmd));

2019-10-04 15:46:26

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH v2] crypto: ccp - Release all allocated memory if sha type is invalid

On Thu, Sep 19, 2019 at 11:04:48AM -0500, Navid Emamdoost wrote:
> Release all allocated memory if sha type is invalid:
> In ccp_run_sha_cmd, if the type of sha is invalid, the allocated
> hmac_buf should be released.
>
> v2: fix the goto.
>
> Signed-off-by: Navid Emamdoost <[email protected]>
> ---
> drivers/crypto/ccp/ccp-ops.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)

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