Skip to contentSkip to conversation

crypto: ccp - release hmac_buf if ccp_run_sha_cmd fails

PATCH In review Navid Emamdoost 4 participants 6 messages Sep 13, 2019 – Oct 4, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 drivers/crypto/ccp/ccp-ops.c | 1 +
 1 file changed, 1 insertion(+)
drivers/crypto/ccp/ccp-ops.c +1 -0
index 9bc3c62157d7..cff16f0cc15b 100644
@@ -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;
 		}
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 13 lines · Navid Emamdoost

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

---
 drivers/crypto/ccp/ccp-ops.c | 1 +
 1 file changed, 1 insertion(+)
drivers/crypto/ccp/ccp-ops.c +0 -0
index 9bc3c62157d7..cff16f0cc15b 100644

drivers/crypto/ccp/ccp-ops.c static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) · line 1785

Quoted 4 lines
drivers/crypto/ccp/ccp-ops.c +1 -0
@@ -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...

drivers/crypto/ccp/ccp-ops.c static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) · line 1787

Quoted 2 lines
drivers/crypto/ccp/ccp-ops.c +0 -0
 			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

Quoted 2 lines
drivers/crypto/ccp/ccp-ops.c +0 -0
 		}
#2 lore raw
Quoted 23 lines · Thomas
Quoted 13 lines · Navid Emamdoost

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

---
  drivers/crypto/ccp/ccp-ops.c | 1 +
  1 file changed, 1 insertion(+)
drivers/crypto/ccp/ccp-ops.c +0 -0
index 9bc3c62157d7..cff16f0cc15b 100644

drivers/crypto/ccp/ccp-ops.c static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) · line 1785

Quoted 4 lines
drivers/crypto/ccp/ccp-ops.c +1 -0
@@ -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...

Quoted 4 lines

drivers/crypto/ccp/ccp-ops.c static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) · line 1787

Quoted 2 lines
drivers/crypto/ccp/ccp-ops.c +0 -0
  			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

#3 lore raw

PATCH v2 1/1 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.

---
 drivers/crypto/ccp/ccp-ops.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/ccp/ccp-ops.c +2 -1
index 9bc3c62157d7..440df9208f8f 100644
@@ -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));
Signature · 1 line
2.17.1
Acked-by on v2 1/1
#4 lore raw

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

Quoted 7 lines · Navid Emamdoost

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.

Quoted 19 lines
---
  drivers/crypto/ccp/ccp-ops.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/ccp/ccp-ops.c +2 -1
index 9bc3c62157d7..440df9208f8f 100644
@@ -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));
maintainer
#5 lore raw

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

In reply to Navid Emamdoost
Quoted 10 lines · Navid Emamdoost

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.

---
 drivers/crypto/ccp/ccp-ops.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt