Fix/improve some error handling related to 'chcr_alloc_shash'
Subsystems (3)
cover Fix/improve some error handling related to 'chcr_alloc_shash'
This serie is divided into 2 patches. They are more or less related to the same issue, but the first patch is not a bug in itself, just a clean-up (IMHO).
If I'm correct, the 2nd one, is a real (unlikely) issue.
Christophe JAILLET (2):
crypto: chcr - Improve error checking
crypto: chcr - Fix error checking
drivers/crypto/chelsio/chcr_algo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/2 crypto: chcr - Improve error checking
'chcr_alloc_shash()' can return NULL. Here it is not possible because this code is reached only if 'get_alg_config()' a few lines above has succeeded. So we are garanteed that the value of 'max_authsize' is a correct parameter.
Anyway, this is harmless to add a check for NULL.
--- drivers/crypto/chelsio/chcr_algo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/chelsio/chcr_algo.c +1 -1
@@ -2294,7 +2294,7 @@ static int chcr_authenc_setkey(struct crypto_aead *authenc, const u8 *key, aeadctx->enckey_len << 3); base_hash =chcr_alloc_shash (max_authsize); -if (IS_ERR (base_hash)) { +if (IS_ERR_OR_NULL (base_hash)) {pr_err ("chcr : Base driver cannot be loaded\n" ); goto out; }
Signature · 1 line
2.11.0
Re: [PATCH 1/2] crypto: chcr - Improve error checking
Quoted 16 lines · Christophe JAILLET
'
chcr_alloc_shash()' can return NULL. Here it is not possible because this code is reached only if 'get_alg_config()' a few lines above has succeeded. So we are garanteed that the value of 'max_authsize' is a correct parameter.
Anyway, this is harmless to add a check for NULL.Signed-off-by Christophe JAILLET <[email protected]>--- drivers/crypto/chelsio/chcr_algo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/crypto/chelsio/chcr_algo.c +0
-0
drivers/crypto/chelsio/chcr_algo.c static int chcr_authenc_setkey(struct crypto_aead *authenc, const u8 *key, · line 2299
Quoted 7 lines
drivers/crypto/chelsio/chcr_algo.c +1
-1@@ -2294,7 +2294,7 @@ static int chcr_authenc_setkey(struct crypto_aead *authenc, const u8 *key, aeadctx->enckey_len << 3); base_hash =chcr_alloc_shash (max_authsize); -if (IS_ERR (base_hash)) { +if (IS_ERR_OR_NULL (base_hash)) {pr_err ("chcr : Base driver cannot be loaded\n" ); goto out;
Ugh... When you mix NULL and error pointers, it should be because NULL is a valid return. We should change chcr_alloc_shash() to return ERR_PTR(-EINVAL) instead of NULL.
Also the "goto out;" is buggy, of course. The problem with magical free everything style error handling is that "base_hash" wasn't allocated so this will oops for both NULL and error pointers.
regards,
dan carpenter
PATCH 2/2 crypto: chcr - Fix error checking
In reply to Christophe JAILLETIf 'chcr_alloc_shash()' a few lines above fails, 'base_hash' can be an error pointer when we 'goto out'.
So checking for NULL here is not enough because it is likely that 'chcr_free_shash' will crash if we pass an error pointer.
---
Another solution, amybe safer, would be to instrument 'chcr_free_shash' or 'crypto_free_shash' to accept an error pointer and return immediatelly in such a case.
--- drivers/crypto/chelsio/chcr_algo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/chelsio/chcr_algo.c +1 -1
@@ -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_OR_NULL (base_hash))chcr_free_shash (base_hash);return -EINVAL ; }
Signature · 1 line
2.11.0
Re: [PATCH 2/2] crypto: chcr - Fix error checking
Quoted 19 lines · Christophe JAILLET
If '
chcr_alloc_shash()' a few lines above fails, 'base_hash' can be an error pointer when we 'goto out'.
So checking for NULL here is not enough because it is likely that 'chcr_free_shash' will crash if we pass an error pointer.Signed-off-by Christophe JAILLET <[email protected]>---
Another solution, amybe safer, would be to instrument 'chcr_free_shash' or 'crypto_free_shash' to accept an error pointer and return immediatelly in such a case.--- drivers/crypto/chelsio/chcr_algo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/crypto/chelsio/chcr_algo.c +0
-0
drivers/crypto/chelsio/chcr_algo.c static int chcr_authenc_setkey(struct crypto_aead *authenc, const u8 *key, · line 2355
Quoted 6 lines
drivers/crypto/chelsio/chcr_algo.c +1
-1@@ -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_OR_NULL (base_hash))chcr_free_shash (base_hash);
Ah... Ok. Fine, but redo the first patch anyway because it shouldn't ever be NULL.
regards,
dan carpenter
Re: [PATCH 2/2] crypto: chcr - Fix error checking
Quoted 29 lines · Dan Carpenter
Quoted 19 lines · Christophe JAILLET
If '
chcr_alloc_shash()' a few lines above fails, 'base_hash' can be an error pointer when we 'goto out'.
So checking for NULL here is not enough because it is likely that 'chcr_free_shash' will crash if we pass an error pointer.Signed-off-by Christophe JAILLET <[email protected]>---
Another solution, amybe safer, would be to instrument 'chcr_free_shash' or 'crypto_free_shash' to accept an error pointer and return immediatelly in such a case.--- drivers/crypto/chelsio/chcr_algo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/crypto/chelsio/chcr_algo.c +0
-0drivers/crypto/chelsio/chcr_algo.c static int chcr_authenc_setkey(struct crypto_aead *authenc, const u8 *key, · line 2355
Quoted 6 lines
drivers/crypto/chelsio/chcr_algo.c +1
-1@@ -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_OR_NULL (base_hash))chcr_free_shash (base_hash);Ah... Ok. Fine, but redo the first patch anyway because it shouldn't ever be NULL.
Quoted 2 lines
regards,
dan carpenter
Hi Dan,
I will update the first patch as you proposed in order to:
- teach 'chcr_alloc_shash' not to return NULL
- initialize 'base_hash' with ERR_PTR(-EINVAL)
- update the above test to !IS_ERR.
The 2 patches will be merged in only 1.
Thanks for your suggestions.
Best regards,
CJ
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/2] crypto: chcr - Fix error checking
Quoted 41 lines · Christophe JAILLET
Quoted 35 lines · Dan Carpenter
Quoted 22 lines · Christophe JAILLET
If '
chcr_alloc_shash()' a few lines above fails, 'base_hash' can be an error pointer when we 'goto out'.
So checking for NULL here is not enough because it is likely that 'chcr_free_shash' will crash if we pass an error pointer.Signed-off-by Christophe JAILLET <[email protected]>---
Another solution, amybe safer, would be to instrument 'chcr_free_shash' or
'crypto_free_shash' to accept an error pointer and return immediatelly in such a case.--- drivers/crypto/chelsio/chcr_algo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/crypto/chelsio/chcr_algo.c +0
-0drivers/crypto/chelsio/chcr_algo.c static int chcr_authenc_setkey(struct crypto_aead · line 2356
Quoted 7 lines
drivers/crypto/chelsio/chcr_algo.c +1
-1@@ -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_OR_NULL (base_hash))chcr_free_shash (base_hash);Ah... Ok. Fine, but redo the first patch anyway because it shouldn't ever be NULL.
Quoted 2 lines
regards,
dan carpenterHi Dan,
Quoted 7 lines
I will update the first patch as you proposed in order to:
- teach 'chcr_alloc_shash' not to return NULL
- initialize 'base_hash' withERR_PTR(-EINVAL)
- update the above test to !IS_ERR.
The 2 patches will be merged in only 1.Thanks for your suggestions.
Thanks for pointing the error. or You can simply return instead of goto. Just like that.
1.3 @@ -2455,7 +2455,8 @@ static int chcr_authenc_setkey(struct cr
1.4 base_hash = chcr_alloc_shash(max_authsize);
1.5 if (IS_ERR(base_hash)) {
1.6 pr_err("chcr : Base driver cannot be loaded\n");
1.7 - goto out;
1.8 + aeadctx->enckey_len = 0;
1.9 + return -EINVAL;
1.10 }
1.11 {
1.12 SHASH_DESC_ON_STACK(shash, base_hash);Quoted 4 lines
Best regards,
CJ
Re: [PATCH 2/2] crypto: chcr - Fix error checking
Quoted 54 lines · Harsh Jain
Quoted 41 lines · Christophe JAILLET
Quoted 35 lines · Dan Carpenter
Quoted 22 lines · Christophe JAILLET
If '
chcr_alloc_shash()' a few lines above fails, 'base_hash' can be an error pointer when we 'goto out'.
So checking for NULL here is not enough because it is likely that 'chcr_free_shash' will crash if we pass an error pointer.Signed-off-by Christophe JAILLET <[email protected]>---
Another solution, amybe safer, would be to instrument 'chcr_free_shash' or
'crypto_free_shash' to accept an error pointer and return immediatelly in such a case.--- drivers/crypto/chelsio/chcr_algo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/crypto/chelsio/chcr_algo.c +0
-0drivers/crypto/chelsio/chcr_algo.c static int chcr_authenc_setkey(struct crypto_aead · line 2356
Quoted 7 lines
drivers/crypto/chelsio/chcr_algo.c +1
-1@@ -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_OR_NULL (base_hash))chcr_free_shash (base_hash);Ah... Ok. Fine, but redo the first patch anyway because it shouldn't ever be NULL.
Quoted 2 lines
regards,
dan carpenterHi Dan,
Quoted 7 lines
I will update the first patch as you proposed in order to:
- teach 'chcr_alloc_shash' not to return NULL
- initialize 'base_hash' withERR_PTR(-EINVAL)
- update the above test to !IS_ERR.
The 2 patches will be merged in only 1.Thanks for your suggestions.
Thanks for pointing the error. or You can simply return instead of goto. Just like that.
Quoted 7 lines
1.3 @@ -2455,7 +2455,8 @@ static int chcr_authenc_setkey(struct cr
1.4 base_hash = chcr_alloc_shash(max_authsize);
1.5 if (IS_ERR(base_hash)) {
1.6 pr_err("chcr : Base driver cannot be loaded\n");
1.7 - goto out;
1.8 + aeadctx->enckey_len = 0;
1.9 + return -EINVAL;Don't do that. There should be a goto.
regards,
dan carpenter
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/2] crypto: chcr - Fix error checking
Quoted 57 lines · Dan Carpenter
Quoted 49 lines · Harsh Jain
Quoted 37 lines · Christophe JAILLET
Quoted 32 lines · Dan Carpenter
Quoted 21 lines · Christophe JAILLET
If '
chcr_alloc_shash()' a few lines above fails, 'base_hash' can be an error pointer when we 'goto out'.
So checking for NULL here is not enough because it is likely that 'chcr_free_shash' will crash if we pass an error pointer.Signed-off-by Christophe JAILLET <[email protected]>---
Another solution, amybe safer, would be to instrument 'chcr_free_shash' or
'crypto_free_shash' to accept an error pointer and return immediatelly in such a case.--- drivers/crypto/chelsio/chcr_algo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/crypto/chelsio/chcr_algo.c +0
-0drivers/crypto/chelsio/chcr_algo.c static int chcr_authenc_setkey(struct crypto_aead · line 2356
Quoted 7 lines
drivers/crypto/chelsio/chcr_algo.c +1
-1@@ -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_OR_NULL (base_hash))chcr_free_shash (base_hash);Ah... Ok. Fine, but redo the first patch anyway because it shouldn't ever be NULL.
Quoted 2 lines
regards,
dan carpenterHi Dan,
Quoted 7 lines
I will update the first patch as you proposed in order to:
- teach 'chcr_alloc_shash' not to return NULL
- initialize 'base_hash' withERR_PTR(-EINVAL)
- update the above test to !IS_ERR.
The 2 patches will be merged in only 1.Thanks for your suggestions.
Thanks for pointing the error. or You can simply return instead of goto. Just like that.
Quoted 7 lines
1.3 @@ -2455,7 +2455,8 @@ static int chcr_authenc_setkey(struct cr 1.4 base_hash = chcr_alloc_shash(max_authsize); 1.5 if (IS_ERR(base_hash)) { 1.6 pr_err("chcr : Base driver cannot be loaded\n"); 1.7 - goto out; 1.8 + aeadctx->enckey_len = 0; 1.9 + return -EINVAL;
Quoted 6 lines
Don't do that. There should be a goto.
regards,
dan carpenter
Agreed.
Having direct return after some other gotos statement puzzles my coccinelle scripts and are spurious (at least IMHO).
best regards,
CJ
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html