All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] crypto: chcr - Fix error handling related to 'chcr_alloc_shash'
@ 2017-04-13 18:25 ` Christophe JAILLET
  0 siblings, 0 replies; 4+ messages in thread
From: Christophe JAILLET @ 2017-04-13 18:25 UTC (permalink / raw)
  To: herbert, davem, harsh, hariprasad
  Cc: linux-crypto, linux-kernel, kernel-janitors, Christophe JAILLET

Up to now, 'crypto_alloc_shash()' may return a valid pointer, an error
pointer or NULL (in case of invalid parameter)
Update it to always return an error pointer in case of error. It now
returns ERR_PTR(-EINVAL) instead of NULL in case of invalid parameter.

This simplifies error handling.

Also fix a crash in 'chcr_authenc_setkey()' if 'chcr_alloc_shash()'
returns an error pointer and the "goto out" path is taken.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
v2: Modify 'chcr_alloc_shash' to return ERR_PTR(-EINVAL) instead of NULL
    in case of invalid parameter.
---
 drivers/crypto/chelsio/chcr_algo.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/chelsio/chcr_algo.c b/drivers/crypto/chelsio/chcr_algo.c
index 41bc7f4f58cd..1fb1ac9d70b1 100644
--- a/drivers/crypto/chelsio/chcr_algo.c
+++ b/drivers/crypto/chelsio/chcr_algo.c
@@ -294,7 +294,7 @@ static inline void get_aes_decrypt_key(unsigned char *dec_key,
 
 static struct crypto_shash *chcr_alloc_shash(unsigned int ds)
 {
-	struct crypto_shash *base_hash = NULL;
+	struct crypto_shash *base_hash = ERR_PTR(-EINVAL);
 
 	switch (ds) {
 	case SHA1_DIGEST_SIZE:
@@ -2259,7 +2259,7 @@ static int chcr_authenc_setkey(struct crypto_aead *authenc, const u8 *key,
 	int err = 0, i, key_ctx_len = 0;
 	unsigned char ck_size = 0;
 	unsigned char pad[CHCR_HASH_MAX_BLOCK_SIZE_128] = { 0 };
-	struct crypto_shash *base_hash = NULL;
+	struct crypto_shash *base_hash = ERR_PTR(-EINVAL);
 	struct algo_param param;
 	int align;
 	u8 *o_ptr = NULL;
@@ -2351,7 +2351,7 @@ static int chcr_authenc_setkey(struct crypto_aead *authenc, const u8 *key,
 	}
 out:
 	aeadctx->enckey_len = 0;
-	if (base_hash)
+	if (!IS_ERR(base_hash))
 		chcr_free_shash(base_hash);
 	return -EINVAL;
 }
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2] crypto: chcr - Fix error handling related to 'chcr_alloc_shash'
@ 2017-04-13 18:25 ` Christophe JAILLET
  0 siblings, 0 replies; 4+ messages in thread
From: Christophe JAILLET @ 2017-04-13 18:25 UTC (permalink / raw)
  To: herbert, davem, harsh, hariprasad
  Cc: linux-crypto, linux-kernel, kernel-janitors, Christophe JAILLET

Up to now, 'crypto_alloc_shash()' may return a valid pointer, an error
pointer or NULL (in case of invalid parameter)
Update it to always return an error pointer in case of error. It now
returns ERR_PTR(-EINVAL) instead of NULL in case of invalid parameter.

This simplifies error handling.

Also fix a crash in 'chcr_authenc_setkey()' if 'chcr_alloc_shash()'
returns an error pointer and the "goto out" path is taken.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
v2: Modify 'chcr_alloc_shash' to return ERR_PTR(-EINVAL) instead of NULL
    in case of invalid parameter.
---
 drivers/crypto/chelsio/chcr_algo.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/chelsio/chcr_algo.c b/drivers/crypto/chelsio/chcr_algo.c
index 41bc7f4f58cd..1fb1ac9d70b1 100644
--- a/drivers/crypto/chelsio/chcr_algo.c
+++ b/drivers/crypto/chelsio/chcr_algo.c
@@ -294,7 +294,7 @@ static inline void get_aes_decrypt_key(unsigned char *dec_key,
 
 static struct crypto_shash *chcr_alloc_shash(unsigned int ds)
 {
-	struct crypto_shash *base_hash = NULL;
+	struct crypto_shash *base_hash = ERR_PTR(-EINVAL);
 
 	switch (ds) {
 	case SHA1_DIGEST_SIZE:
@@ -2259,7 +2259,7 @@ static int chcr_authenc_setkey(struct crypto_aead *authenc, const u8 *key,
 	int err = 0, i, key_ctx_len = 0;
 	unsigned char ck_size = 0;
 	unsigned char pad[CHCR_HASH_MAX_BLOCK_SIZE_128] = { 0 };
-	struct crypto_shash *base_hash = NULL;
+	struct crypto_shash *base_hash = ERR_PTR(-EINVAL);
 	struct algo_param param;
 	int align;
 	u8 *o_ptr = NULL;
@@ -2351,7 +2351,7 @@ static int chcr_authenc_setkey(struct crypto_aead *authenc, const u8 *key,
 	}
 out:
 	aeadctx->enckey_len = 0;
-	if (base_hash)
+	if (!IS_ERR(base_hash))
 		chcr_free_shash(base_hash);
 	return -EINVAL;
 }
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] crypto: chcr - Fix error handling related to 'chcr_alloc_shash'
  2017-04-13 18:25 ` Christophe JAILLET
@ 2017-04-21 13:15   ` Herbert Xu
  -1 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2017-04-21 13:15 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: davem, harsh, hariprasad, linux-crypto, linux-kernel, kernel-janitors

On Thu, Apr 13, 2017 at 08:25:15PM +0200, Christophe JAILLET wrote:
> Up to now, 'crypto_alloc_shash()' may return a valid pointer, an error
> pointer or NULL (in case of invalid parameter)
> Update it to always return an error pointer in case of error. It now
> returns ERR_PTR(-EINVAL) instead of NULL in case of invalid parameter.
> 
> This simplifies error handling.
> 
> Also fix a crash in 'chcr_authenc_setkey()' if 'chcr_alloc_shash()'
> returns an error pointer and the "goto out" path is taken.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] crypto: chcr - Fix error handling related to 'chcr_alloc_shash'
@ 2017-04-21 13:15   ` Herbert Xu
  0 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2017-04-21 13:15 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: davem, harsh, hariprasad, linux-crypto, linux-kernel, kernel-janitors

On Thu, Apr 13, 2017 at 08:25:15PM +0200, Christophe JAILLET wrote:
> Up to now, 'crypto_alloc_shash()' may return a valid pointer, an error
> pointer or NULL (in case of invalid parameter)
> Update it to always return an error pointer in case of error. It now
> returns ERR_PTR(-EINVAL) instead of NULL in case of invalid parameter.
> 
> This simplifies error handling.
> 
> Also fix a crash in 'chcr_authenc_setkey()' if 'chcr_alloc_shash()'
> returns an error pointer and the "goto out" path is taken.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-21 13:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-13 18:25 [PATCH v2] crypto: chcr - Fix error handling related to 'chcr_alloc_shash' Christophe JAILLET
2017-04-13 18:25 ` Christophe JAILLET
2017-04-21 13:15 ` Herbert Xu
2017-04-21 13:15   ` Herbert Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.