Skip to contentSkip to conversation

crypto: spacc - Fix uninitialized variable in spacc_aead_process()

PATCH New Dan Carpenter 1 participant 3 messages Aug 15, 2024 1 message not in the archive Crypto API

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/3 crypto: spacc - Fix uninitialized variable in spacc_aead_process()

Smatch complains that:

drivers/crypto/dwc-spacc/spacc_aead.c:1031 spacc_aead_process()
error: uninitialized symbol 'ptaadsize'.

This could happen if, for example, tctx->mode was CRYPTO_MODE_NULL and req->cryptlen was less than icvremove.

Fixes 06af76b46c78 ("crypto: spacc - Add SPAcc aead support")
---
 drivers/crypto/dwc-spacc/spacc_aead.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/crypto/dwc-spacc/spacc_aead.c +1 -3
index 3468ff605957..50ef9053fc4d 100755
@@ -823,7 +823,7 @@ static int spacc_aead_process(struct aead_request *req, u64 seq, int encrypt)
 	u32 dstoff;
 	int icvremove;
 	int ivaadsize;
-	int ptaadsize;
+	int ptaadsize = 0;
 	int iv_to_context;
 	int spacc_proc_len;
 	u32 spacc_icv_offset = 0;
@@ -974,8 +974,6 @@ static int spacc_aead_process(struct aead_request *req, u64 seq, int encrypt)
 	    tctx->mode == CRYPTO_MODE_NULL) {
 		if (req->cryptlen >= icvremove)
 			ptaadsize = req->cryptlen - icvremove;
-	} else {
-		ptaadsize = 0;
 	}
 
 	/* Calculate and set the below, important parameters
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/3 crypto: spacc - Fix NULL vs IS_ERR() check in spacc_aead_fallback()

In reply to a message not in the archive

The crypto_alloc_aead() function doesn't return NULL pointers, it returns error pointers. Fix the error checking.

Fixes 06af76b46c78 ("crypto: spacc - Add SPAcc aead support")
---
 drivers/crypto/dwc-spacc/spacc_aead.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/dwc-spacc/spacc_aead.c +2 -2
index 50ef9053fc4d..da9df329f9d4 100755
@@ -784,9 +784,9 @@ static int spacc_aead_fallback(struct aead_request *req,
 	ctx->fb.aead = crypto_alloc_aead(aead_name, 0,
 					 CRYPTO_ALG_NEED_FALLBACK |
 					 CRYPTO_ALG_ASYNC);
-	if (!ctx->fb.aead) {
+	if (IS_ERR(ctx->fb.aead)) {
 		pr_err("Spacc aead fallback tfm is NULL!\n");
-		return -EINVAL;
+		return PTR_ERR(ctx->fb.aead);
 	}
 
 	subreq = aead_request_alloc(ctx->fb.aead, GFP_KERNEL);
Signature · 1 line
2.43.0
#3 lore raw

PATCH 3/3 crypto: spacc - Check for allocation failure in spacc_skcipher_fallback()

In reply to a message not in the archive

Check for crypto_alloc_skcipher() failure.

Fixes c8981d9230d8 ("crypto: spacc - Add SPAcc Skcipher support")
---
 drivers/crypto/dwc-spacc/spacc_skcipher.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/crypto/dwc-spacc/spacc_skcipher.c +2 -0
index 488c03ff6c36..8c698b75dd92 100644
@@ -67,6 +67,8 @@ static int spacc_skcipher_fallback(unsigned char *name,
 	tctx->fb.cipher = crypto_alloc_skcipher(name,
 						CRYPTO_ALG_TYPE_SKCIPHER,
 						CRYPTO_ALG_NEED_FALLBACK);
+	if (IS_ERR(tctx->fb.cipher))
+		return PTR_ERR(tctx->fb.cipher);
 
 	crypto_skcipher_set_reqsize(reqtfm,
 				    sizeof(struct spacc_crypto_reqctx) +
Signature · 1 line
2.43.0