linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KEYS: asymmetric: Fix error codes
@ 2023-07-03 14:18 Dan Carpenter
  2023-07-07  4:20 ` Herbert Xu
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Dan Carpenter @ 2023-07-03 14:18 UTC (permalink / raw)
  To: Herbert Xu
  Cc: David Howells, David S. Miller, keyrings, linux-crypto,
	kernel-janitors

These error paths should return the appropriate error codes instead of
returning success.

Fixes: 63ba4d67594a ("KEYS: asymmetric: Use new crypto interface without scatterlists")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 crypto/asymmetric_keys/public_key.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
index e787598cb3f7..773e159dbbcb 100644
--- a/crypto/asymmetric_keys/public_key.c
+++ b/crypto/asymmetric_keys/public_key.c
@@ -185,8 +185,10 @@ static int software_key_query(const struct kernel_pkey_params *params,
 
 	if (issig) {
 		sig = crypto_alloc_sig(alg_name, 0, 0);
-		if (IS_ERR(sig))
+		if (IS_ERR(sig)) {
+			ret = PTR_ERR(sig);
 			goto error_free_key;
+		}
 
 		if (pkey->key_is_private)
 			ret = crypto_sig_set_privkey(sig, key, pkey->keylen);
@@ -208,8 +210,10 @@ static int software_key_query(const struct kernel_pkey_params *params,
 		}
 	} else {
 		tfm = crypto_alloc_akcipher(alg_name, 0, 0);
-		if (IS_ERR(tfm))
+		if (IS_ERR(tfm)) {
+			ret = PTR_ERR(tfm);
 			goto error_free_key;
+		}
 
 		if (pkey->key_is_private)
 			ret = crypto_akcipher_set_priv_key(tfm, key, pkey->keylen);
@@ -300,8 +304,10 @@ static int software_key_eds_op(struct kernel_pkey_params *params,
 
 	if (issig) {
 		sig = crypto_alloc_sig(alg_name, 0, 0);
-		if (IS_ERR(sig))
+		if (IS_ERR(sig)) {
+			ret = PTR_ERR(sig);
 			goto error_free_key;
+		}
 
 		if (pkey->key_is_private)
 			ret = crypto_sig_set_privkey(sig, key, pkey->keylen);
@@ -313,8 +319,10 @@ static int software_key_eds_op(struct kernel_pkey_params *params,
 		ksz = crypto_sig_maxsize(sig);
 	} else {
 		tfm = crypto_alloc_akcipher(alg_name, 0, 0);
-		if (IS_ERR(tfm))
+		if (IS_ERR(tfm)) {
+			ret = PTR_ERR(tfm);
 			goto error_free_key;
+		}
 
 		if (pkey->key_is_private)
 			ret = crypto_akcipher_set_priv_key(tfm, key, pkey->keylen);
@@ -411,8 +419,10 @@ int public_key_verify_signature(const struct public_key *pkey,
 
 	key = kmalloc(pkey->keylen + sizeof(u32) * 2 + pkey->paramlen,
 		      GFP_KERNEL);
-	if (!key)
+	if (!key) {
+		ret = -ENOMEM;
 		goto error_free_tfm;
+	}
 
 	memcpy(key, pkey->key, pkey->keylen);
 	ptr = key + pkey->keylen;
-- 
2.39.2


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

* Re: [PATCH] KEYS: asymmetric: Fix error codes
  2023-07-03 14:18 [PATCH] KEYS: asymmetric: Fix error codes Dan Carpenter
@ 2023-07-07  4:20 ` Herbert Xu
  2023-07-07  6:01 ` David Howells
  2023-07-10 23:10 ` Jarkko Sakkinen
  2 siblings, 0 replies; 8+ messages in thread
From: Herbert Xu @ 2023-07-07  4:20 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: David Howells, David S. Miller, keyrings, linux-crypto,
	kernel-janitors

On Mon, Jul 03, 2023 at 05:18:08PM +0300, Dan Carpenter wrote:
> These error paths should return the appropriate error codes instead of
> returning success.
> 
> Fixes: 63ba4d67594a ("KEYS: asymmetric: Use new crypto interface without scatterlists")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>  crypto/asymmetric_keys/public_key.c | 20 +++++++++++++++-----
>  1 file changed, 15 insertions(+), 5 deletions(-)

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] 8+ messages in thread

* Re: [PATCH] KEYS: asymmetric: Fix error codes
  2023-07-03 14:18 [PATCH] KEYS: asymmetric: Fix error codes Dan Carpenter
  2023-07-07  4:20 ` Herbert Xu
@ 2023-07-07  6:01 ` David Howells
  2023-07-10 23:10 ` Jarkko Sakkinen
  2 siblings, 0 replies; 8+ messages in thread
From: David Howells @ 2023-07-07  6:01 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: dhowells, Herbert Xu, David S. Miller, keyrings, linux-crypto,
	kernel-janitors

Dan Carpenter <dan.carpenter@linaro.org> wrote:

> These error paths should return the appropriate error codes instead of
> returning success.
> 
> Fixes: 63ba4d67594a ("KEYS: asymmetric: Use new crypto interface without scatterlists")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Reviewed-by: David Howells <dhowells@redhat.com>


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

* Re: [PATCH] KEYS: asymmetric: Fix error codes
  2023-07-03 14:18 [PATCH] KEYS: asymmetric: Fix error codes Dan Carpenter
  2023-07-07  4:20 ` Herbert Xu
  2023-07-07  6:01 ` David Howells
@ 2023-07-10 23:10 ` Jarkko Sakkinen
  2023-07-10 23:12   ` Jarkko Sakkinen
  2 siblings, 1 reply; 8+ messages in thread
From: Jarkko Sakkinen @ 2023-07-10 23:10 UTC (permalink / raw)
  To: Dan Carpenter, Herbert Xu
  Cc: David Howells, David S. Miller, keyrings, linux-crypto,
	kernel-janitors

On Mon Jul 3, 2023 at 5:18 PM EEST, Dan Carpenter wrote:
> These error paths should return the appropriate error codes instead of
> returning success.
>
> Fixes: 63ba4d67594a ("KEYS: asymmetric: Use new crypto interface without scatterlists")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>  crypto/asymmetric_keys/public_key.c | 20 +++++++++++++++-----
>  1 file changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
> index e787598cb3f7..773e159dbbcb 100644
> --- a/crypto/asymmetric_keys/public_key.c
> +++ b/crypto/asymmetric_keys/public_key.c
> @@ -185,8 +185,10 @@ static int software_key_query(const struct kernel_pkey_params *params,
>  
>  	if (issig) {
>  		sig = crypto_alloc_sig(alg_name, 0, 0);
> -		if (IS_ERR(sig))
> +		if (IS_ERR(sig)) {
> +			ret = PTR_ERR(sig);
>  			goto error_free_key;
> +		}
>  
>  		if (pkey->key_is_private)
>  			ret = crypto_sig_set_privkey(sig, key, pkey->keylen);
> @@ -208,8 +210,10 @@ static int software_key_query(const struct kernel_pkey_params *params,
>  		}
>  	} else {
>  		tfm = crypto_alloc_akcipher(alg_name, 0, 0);
> -		if (IS_ERR(tfm))
> +		if (IS_ERR(tfm)) {
> +			ret = PTR_ERR(tfm);
>  			goto error_free_key;
> +		}
>  
>  		if (pkey->key_is_private)
>  			ret = crypto_akcipher_set_priv_key(tfm, key, pkey->keylen);
> @@ -300,8 +304,10 @@ static int software_key_eds_op(struct kernel_pkey_params *params,
>  
>  	if (issig) {
>  		sig = crypto_alloc_sig(alg_name, 0, 0);
> -		if (IS_ERR(sig))
> +		if (IS_ERR(sig)) {
> +			ret = PTR_ERR(sig);
>  			goto error_free_key;
> +		}
>  
>  		if (pkey->key_is_private)
>  			ret = crypto_sig_set_privkey(sig, key, pkey->keylen);
> @@ -313,8 +319,10 @@ static int software_key_eds_op(struct kernel_pkey_params *params,
>  		ksz = crypto_sig_maxsize(sig);
>  	} else {
>  		tfm = crypto_alloc_akcipher(alg_name, 0, 0);
> -		if (IS_ERR(tfm))
> +		if (IS_ERR(tfm)) {
> +			ret = PTR_ERR(tfm);
>  			goto error_free_key;
> +		}
>  
>  		if (pkey->key_is_private)
>  			ret = crypto_akcipher_set_priv_key(tfm, key, pkey->keylen);
> @@ -411,8 +419,10 @@ int public_key_verify_signature(const struct public_key *pkey,
>  
>  	key = kmalloc(pkey->keylen + sizeof(u32) * 2 + pkey->paramlen,
>  		      GFP_KERNEL);
> -	if (!key)
> +	if (!key) {
> +		ret = -ENOMEM;
>  		goto error_free_tfm;
> +	}
>  
>  	memcpy(key, pkey->key, pkey->keylen);
>  	ptr = key + pkey->keylen;
> -- 
> 2.39.2

I'll pick this as I'm late with 6.5 PR.

Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

BR, Jarkko

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

* Re: [PATCH] KEYS: asymmetric: Fix error codes
  2023-07-10 23:10 ` Jarkko Sakkinen
@ 2023-07-10 23:12   ` Jarkko Sakkinen
  2023-07-11  8:40     ` Dan Carpenter
  0 siblings, 1 reply; 8+ messages in thread
From: Jarkko Sakkinen @ 2023-07-10 23:12 UTC (permalink / raw)
  To: Jarkko Sakkinen, Dan Carpenter, Herbert Xu
  Cc: David Howells, David S. Miller, keyrings, linux-crypto,
	kernel-janitors

On Tue Jul 11, 2023 at 2:10 AM EEST, Jarkko Sakkinen wrote:
> On Mon Jul 3, 2023 at 5:18 PM EEST, Dan Carpenter wrote:
> > These error paths should return the appropriate error codes instead of
> > returning success.
> >
> > Fixes: 63ba4d67594a ("KEYS: asymmetric: Use new crypto interface without scatterlists")
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> > ---
> >  crypto/asymmetric_keys/public_key.c | 20 +++++++++++++++-----
> >  1 file changed, 15 insertions(+), 5 deletions(-)
> >
> > diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
> > index e787598cb3f7..773e159dbbcb 100644
> > --- a/crypto/asymmetric_keys/public_key.c
> > +++ b/crypto/asymmetric_keys/public_key.c
> > @@ -185,8 +185,10 @@ static int software_key_query(const struct kernel_pkey_params *params,
> >  
> >  	if (issig) {
> >  		sig = crypto_alloc_sig(alg_name, 0, 0);
> > -		if (IS_ERR(sig))
> > +		if (IS_ERR(sig)) {
> > +			ret = PTR_ERR(sig);
> >  			goto error_free_key;
> > +		}
> >  
> >  		if (pkey->key_is_private)
> >  			ret = crypto_sig_set_privkey(sig, key, pkey->keylen);
> > @@ -208,8 +210,10 @@ static int software_key_query(const struct kernel_pkey_params *params,
> >  		}
> >  	} else {
> >  		tfm = crypto_alloc_akcipher(alg_name, 0, 0);
> > -		if (IS_ERR(tfm))
> > +		if (IS_ERR(tfm)) {
> > +			ret = PTR_ERR(tfm);
> >  			goto error_free_key;
> > +		}
> >  
> >  		if (pkey->key_is_private)
> >  			ret = crypto_akcipher_set_priv_key(tfm, key, pkey->keylen);
> > @@ -300,8 +304,10 @@ static int software_key_eds_op(struct kernel_pkey_params *params,
> >  
> >  	if (issig) {
> >  		sig = crypto_alloc_sig(alg_name, 0, 0);
> > -		if (IS_ERR(sig))
> > +		if (IS_ERR(sig)) {
> > +			ret = PTR_ERR(sig);
> >  			goto error_free_key;
> > +		}
> >  
> >  		if (pkey->key_is_private)
> >  			ret = crypto_sig_set_privkey(sig, key, pkey->keylen);
> > @@ -313,8 +319,10 @@ static int software_key_eds_op(struct kernel_pkey_params *params,
> >  		ksz = crypto_sig_maxsize(sig);
> >  	} else {
> >  		tfm = crypto_alloc_akcipher(alg_name, 0, 0);
> > -		if (IS_ERR(tfm))
> > +		if (IS_ERR(tfm)) {
> > +			ret = PTR_ERR(tfm);
> >  			goto error_free_key;
> > +		}
> >  
> >  		if (pkey->key_is_private)
> >  			ret = crypto_akcipher_set_priv_key(tfm, key, pkey->keylen);
> > @@ -411,8 +419,10 @@ int public_key_verify_signature(const struct public_key *pkey,
> >  
> >  	key = kmalloc(pkey->keylen + sizeof(u32) * 2 + pkey->paramlen,
> >  		      GFP_KERNEL);
> > -	if (!key)
> > +	if (!key) {
> > +		ret = -ENOMEM;
> >  		goto error_free_tfm;
> > +	}
> >  
> >  	memcpy(key, pkey->key, pkey->keylen);
> >  	ptr = key + pkey->keylen;
> > -- 
> > 2.39.2
>
> I'll pick this as I'm late with 6.5 PR.
>
> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

Causes merge conflicts with my tree:

https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git/

BR, Jarkko

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

* Re: [PATCH] KEYS: asymmetric: Fix error codes
  2023-07-10 23:12   ` Jarkko Sakkinen
@ 2023-07-11  8:40     ` Dan Carpenter
  2023-07-11 21:51       ` Jarkko Sakkinen
  0 siblings, 1 reply; 8+ messages in thread
From: Dan Carpenter @ 2023-07-11  8:40 UTC (permalink / raw)
  To: Jarkko Sakkinen, Herbert Xu
  Cc: David Howells, David S. Miller, keyrings, linux-crypto,
	kernel-janitors

On Tue, Jul 11, 2023 at 02:12:22AM +0300, Jarkko Sakkinen wrote:
> > > Fixes: 63ba4d67594a ("KEYS: asymmetric: Use new crypto interface without scatterlists")

[ snip ]

> >
> > I'll pick this as I'm late with 6.5 PR.
> >
> > Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
> 
> Causes merge conflicts with my tree:
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git/

Your master branch doesn't include the "Use new crypto interface" commit
so it doesn't have the bug.

(I'm just testing against linux-next and I don't know how the crypto
trees work).

regards,
dan carpenter

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

* Re: [PATCH] KEYS: asymmetric: Fix error codes
  2023-07-11  8:40     ` Dan Carpenter
@ 2023-07-11 21:51       ` Jarkko Sakkinen
  2023-07-11 23:27         ` Herbert Xu
  0 siblings, 1 reply; 8+ messages in thread
From: Jarkko Sakkinen @ 2023-07-11 21:51 UTC (permalink / raw)
  To: Dan Carpenter, Herbert Xu
  Cc: David Howells, David S. Miller, keyrings, linux-crypto,
	kernel-janitors

On Tue, 2023-07-11 at 11:40 +0300, Dan Carpenter wrote:
> On Tue, Jul 11, 2023 at 02:12:22AM +0300, Jarkko Sakkinen wrote:
> > > > Fixes: 63ba4d67594a ("KEYS: asymmetric: Use new crypto interface without scatterlists")
> 
> [ snip ]
> 
> > > 
> > > I'll pick this as I'm late with 6.5 PR.
> > > 
> > > Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
> > 
> > Causes merge conflicts with my tree:
> > 
> > https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git/
> 
> Your master branch doesn't include the "Use new crypto interface" commit
> so it doesn't have the bug.
> 
> (I'm just testing against linux-next and I don't know how the crypto
> trees work).
> 
> regards,
> dan carpenter

It is unfortunately based on Linus' tree :-/

BR, Jarkko


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

* Re: [PATCH] KEYS: asymmetric: Fix error codes
  2023-07-11 21:51       ` Jarkko Sakkinen
@ 2023-07-11 23:27         ` Herbert Xu
  0 siblings, 0 replies; 8+ messages in thread
From: Herbert Xu @ 2023-07-11 23:27 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: Dan Carpenter, David Howells, David S. Miller, keyrings,
	linux-crypto, kernel-janitors

On Wed, Jul 12, 2023 at 12:51:45AM +0300, Jarkko Sakkinen wrote:
> On Tue, 2023-07-11 at 11:40 +0300, Dan Carpenter wrote:
> > On Tue, Jul 11, 2023 at 02:12:22AM +0300, Jarkko Sakkinen wrote:
> > > > > Fixes: 63ba4d67594a ("KEYS: asymmetric: Use new crypto interface without scatterlists")
> > 
> > [ snip ]
> > 
> > > > 
> > > > I'll pick this as I'm late with 6.5 PR.
> > > > 
> > > > Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
> > > 
> > > Causes merge conflicts with my tree:
> > > 
> > > https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git/
> > 
> > Your master branch doesn't include the "Use new crypto interface" commit
> > so it doesn't have the bug.
> > 
> > (I'm just testing against linux-next and I don't know how the crypto
> > trees work).
> > 
> > regards,
> > dan carpenter
> 
> It is unfortunately based on Linus' tree :-/

Both this fix and the pathces it depends on have gone through
the crypto tree and is now merged upstream.

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] 8+ messages in thread

end of thread, other threads:[~2023-07-11 23:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-03 14:18 [PATCH] KEYS: asymmetric: Fix error codes Dan Carpenter
2023-07-07  4:20 ` Herbert Xu
2023-07-07  6:01 ` David Howells
2023-07-10 23:10 ` Jarkko Sakkinen
2023-07-10 23:12   ` Jarkko Sakkinen
2023-07-11  8:40     ` Dan Carpenter
2023-07-11 21:51       ` Jarkko Sakkinen
2023-07-11 23:27         ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).