All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp()
@ 2021-01-12 16:10 Toke Høiland-Jørgensen
  2021-01-13  2:39 ` Tianjia Zhang
  2021-01-13 11:11 ` David Howells
  0 siblings, 2 replies; 13+ messages in thread
From: Toke Høiland-Jørgensen @ 2021-01-12 16:10 UTC (permalink / raw)
  To: David Howells, Herbert Xu, David S. Miller
  Cc: Toke Høiland-Jørgensen, Tianjia Zhang,
	Gilad Ben-Yossef, keyrings, linux-crypto, stable

When public_key_verify_signature() is called from
asymmetric_key_verify_signature(), the pkey_algo field of struct
public_key_signature will be NULL, which causes a NULL pointer dereference
in the strcmp() check. Fix this by adding a NULL check.

One visible manifestation of this is that userspace programs (such as the
'iwd' WiFi daemon) will be killed when trying to verify a TLS key using the
keyctl(2) interface.

Cc: stable@vger.kernel.org
Fixes: 215525639631 ("X.509: support OSCCA SM2-with-SM3 certificate verification")
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 crypto/asymmetric_keys/public_key.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
index 8892908ad58c..35b09e95a870 100644
--- a/crypto/asymmetric_keys/public_key.c
+++ b/crypto/asymmetric_keys/public_key.c
@@ -356,7 +356,7 @@ int public_key_verify_signature(const struct public_key *pkey,
 	if (ret)
 		goto error_free_key;
 
-	if (strcmp(sig->pkey_algo, "sm2") == 0 && sig->data_size) {
+	if (sig->pkey_algo && strcmp(sig->pkey_algo, "sm2") == 0 && sig->data_size) {
 		ret = cert_sig_digest_update(sig, tfm);
 		if (ret)
 			goto error_free_key;
-- 
2.30.0


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

* Re: [PATCH] crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp()
  2021-01-12 16:10 [PATCH] crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp() Toke Høiland-Jørgensen
@ 2021-01-13  2:39 ` Tianjia Zhang
  2021-01-13 11:29   ` Toke Høiland-Jørgensen
  2021-01-13 11:11 ` David Howells
  1 sibling, 1 reply; 13+ messages in thread
From: Tianjia Zhang @ 2021-01-13  2:39 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen, David Howells, Herbert Xu,
	David S. Miller
  Cc: Gilad Ben-Yossef, keyrings, linux-crypto, stable

Hi,

I have fixed this problem last week. Still thanks for your fixing.
patch is here: https://lkml.org/lkml/2021/1/7/201

Best regards,
Tianjia

On 1/13/21 12:10 AM, Toke Høiland-Jørgensen wrote:
> When public_key_verify_signature() is called from
> asymmetric_key_verify_signature(), the pkey_algo field of struct
> public_key_signature will be NULL, which causes a NULL pointer dereference
> in the strcmp() check. Fix this by adding a NULL check.
> 
> One visible manifestation of this is that userspace programs (such as the
> 'iwd' WiFi daemon) will be killed when trying to verify a TLS key using the
> keyctl(2) interface.
> 
> Cc: stable@vger.kernel.org
> Fixes: 215525639631 ("X.509: support OSCCA SM2-with-SM3 certificate verification")
> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
> ---
>   crypto/asymmetric_keys/public_key.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
> index 8892908ad58c..35b09e95a870 100644
> --- a/crypto/asymmetric_keys/public_key.c
> +++ b/crypto/asymmetric_keys/public_key.c
> @@ -356,7 +356,7 @@ int public_key_verify_signature(const struct public_key *pkey,
>   	if (ret)
>   		goto error_free_key;
>   
> -	if (strcmp(sig->pkey_algo, "sm2") == 0 && sig->data_size) {
> +	if (sig->pkey_algo && strcmp(sig->pkey_algo, "sm2") == 0 && sig->data_size) {
>   		ret = cert_sig_digest_update(sig, tfm);
>   		if (ret)
>   			goto error_free_key;
> 

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

* Re: [PATCH] crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp()
  2021-01-12 16:10 [PATCH] crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp() Toke Høiland-Jørgensen
  2021-01-13  2:39 ` Tianjia Zhang
@ 2021-01-13 11:11 ` David Howells
  2021-01-13 11:36   ` Toke Høiland-Jørgensen
                     ` (2 more replies)
  1 sibling, 3 replies; 13+ messages in thread
From: David Howells @ 2021-01-13 11:11 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen
  Cc: dhowells, Herbert Xu, David S. Miller, Tianjia Zhang,
	Gilad Ben-Yossef, keyrings, linux-crypto, stable

I'm intending to use Tianjia's patch.  Would you like to add a Reviewed-by?

David
---
commit 11078a592e6dcea6b9f30e822d3d30e3defc99ca
Author: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Date:   Thu Jan 7 17:28:55 2021 +0800

    X.509: Fix crash caused by NULL pointer
    
    On the following call path, `sig->pkey_algo` is not assigned
    in asymmetric_key_verify_signature(), which causes runtime
    crash in public_key_verify_signature().
    
      keyctl_pkey_verify
        asymmetric_key_verify_signature
          verify_signature
            public_key_verify_signature
    
    This patch simply check this situation and fixes the crash
    caused by NULL pointer.
    
    Fixes: 215525639631 ("X.509: support OSCCA SM2-with-SM3 certificate verification")
    Cc: stable@vger.kernel.org # v5.10+
    Reported-by: Tobias Markus <tobias@markus-regensburg.de>
    Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
    Signed-off-by: David Howells <dhowells@redhat.com>

diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
index 8892908ad58c..788a4ba1e2e7 100644
--- a/crypto/asymmetric_keys/public_key.c
+++ b/crypto/asymmetric_keys/public_key.c
@@ -356,7 +356,8 @@ int public_key_verify_signature(const struct public_key *pkey,
 	if (ret)
 		goto error_free_key;
 
-	if (strcmp(sig->pkey_algo, "sm2") == 0 && sig->data_size) {
+	if (sig->pkey_algo && strcmp(sig->pkey_algo, "sm2") == 0 &&
+	    sig->data_size) {
 		ret = cert_sig_digest_update(sig, tfm);
 		if (ret)
 			goto error_free_key;


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

* Re: [PATCH] crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp()
  2021-01-13  2:39 ` Tianjia Zhang
@ 2021-01-13 11:29   ` Toke Høiland-Jørgensen
  0 siblings, 0 replies; 13+ messages in thread
From: Toke Høiland-Jørgensen @ 2021-01-13 11:29 UTC (permalink / raw)
  To: Tianjia Zhang, David Howells, Herbert Xu, David S. Miller
  Cc: Gilad Ben-Yossef, keyrings, linux-crypto, stable

Tianjia Zhang <tianjia.zhang@linux.alibaba.com> writes:

> Hi,
>
> I have fixed this problem last week. Still thanks for your fixing.
> patch is here: https://lkml.org/lkml/2021/1/7/201

Ah, awesome! I did look if this had already been fixed, but your patch
wasn't in the crypto tree and didn't think to go perusing the mailing
lists. So sorry for the duplicate, and thanks for fixing this :)

-Toke


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

* Re: [PATCH] crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp()
  2021-01-13 11:11 ` David Howells
@ 2021-01-13 11:36   ` Toke Høiland-Jørgensen
  2021-01-13 12:57   ` David Howells
  2021-01-14  2:55   ` Jarkko Sakkinen
  2 siblings, 0 replies; 13+ messages in thread
From: Toke Høiland-Jørgensen @ 2021-01-13 11:36 UTC (permalink / raw)
  To: David Howells
  Cc: dhowells, Herbert Xu, David S. Miller, Tianjia Zhang,
	Gilad Ben-Yossef, keyrings, linux-crypto, stable

David Howells <dhowells@redhat.com> writes:

> I'm intending to use Tianjia's patch.

Yeah, sorry for missing that.

> Would you like to add a Reviewed-by?

Sure:

Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>

and also, if you like:

Tested-by: Toke Høiland-Jørgensen <toke@redhat.com>


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

* Re: [PATCH] crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp()
  2021-01-13 11:11 ` David Howells
  2021-01-13 11:36   ` Toke Høiland-Jørgensen
@ 2021-01-13 12:57   ` David Howells
  2021-01-18 17:13     ` Toke Høiland-Jørgensen
  2021-01-14  2:55   ` Jarkko Sakkinen
  2 siblings, 1 reply; 13+ messages in thread
From: David Howells @ 2021-01-13 12:57 UTC (permalink / raw)
  To: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?=
  Cc: dhowells, Herbert Xu, David S. Miller, Tianjia Zhang,
	Gilad Ben-Yossef, keyrings, linux-crypto, stable

Toke Høiland-Jørgensen <toke@redhat.com> wrote:

> Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>
> 
> and also, if you like:
> 
> Tested-by: Toke Høiland-Jørgensen <toke@redhat.com>

Thanks!

David


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

* Re: [PATCH] crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp()
  2021-01-13 11:11 ` David Howells
  2021-01-13 11:36   ` Toke Høiland-Jørgensen
  2021-01-13 12:57   ` David Howells
@ 2021-01-14  2:55   ` Jarkko Sakkinen
  2 siblings, 0 replies; 13+ messages in thread
From: Jarkko Sakkinen @ 2021-01-14  2:55 UTC (permalink / raw)
  To: David Howells
  Cc: Toke Høiland-Jørgensen, Herbert Xu, David S. Miller,
	Tianjia Zhang, Gilad Ben-Yossef, keyrings, linux-crypto, stable

On Wed, Jan 13, 2021 at 11:11:13AM +0000, David Howells wrote:
> I'm intending to use Tianjia's patch.  Would you like to add a Reviewed-by?
> 
> David

I can give.

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

/Jarkko

> ---
> commit 11078a592e6dcea6b9f30e822d3d30e3defc99ca
> Author: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
> Date:   Thu Jan 7 17:28:55 2021 +0800
> 
>     X.509: Fix crash caused by NULL pointer
>     
>     On the following call path, `sig->pkey_algo` is not assigned
>     in asymmetric_key_verify_signature(), which causes runtime
>     crash in public_key_verify_signature().
>     
>       keyctl_pkey_verify
>         asymmetric_key_verify_signature
>           verify_signature
>             public_key_verify_signature
>     
>     This patch simply check this situation and fixes the crash
>     caused by NULL pointer.
>     
>     Fixes: 215525639631 ("X.509: support OSCCA SM2-with-SM3 certificate verification")
>     Cc: stable@vger.kernel.org # v5.10+
>     Reported-by: Tobias Markus <tobias@markus-regensburg.de>
>     Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
>     Signed-off-by: David Howells <dhowells@redhat.com>
> 
> diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
> index 8892908ad58c..788a4ba1e2e7 100644
> --- a/crypto/asymmetric_keys/public_key.c
> +++ b/crypto/asymmetric_keys/public_key.c
> @@ -356,7 +356,8 @@ int public_key_verify_signature(const struct public_key *pkey,
>  	if (ret)
>  		goto error_free_key;
>  
> -	if (strcmp(sig->pkey_algo, "sm2") == 0 && sig->data_size) {
> +	if (sig->pkey_algo && strcmp(sig->pkey_algo, "sm2") == 0 &&
> +	    sig->data_size) {
>  		ret = cert_sig_digest_update(sig, tfm);
>  		if (ret)
>  			goto error_free_key;
> 
> 

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

* Re: [PATCH] crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp()
  2021-01-13 12:57   ` David Howells
@ 2021-01-18 17:13     ` Toke Høiland-Jørgensen
  2021-01-18 21:09       ` João Fonseca
  2021-03-10 12:02       ` Greg KH
  0 siblings, 2 replies; 13+ messages in thread
From: Toke Høiland-Jørgensen @ 2021-01-18 17:13 UTC (permalink / raw)
  To: David Howells
  Cc: dhowells, Herbert Xu, David S. Miller, Tianjia Zhang,
	Gilad Ben-Yossef, keyrings, linux-crypto, stable

David Howells <dhowells@redhat.com> writes:

> Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>
>> Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>
>> 
>> and also, if you like:
>> 
>> Tested-by: Toke Høiland-Jørgensen <toke@redhat.com>
>
> Thanks!

Any chance of that patch getting into -stable anytime soon? Would be
nice to have working WiFi without having to compile my own kernels ;)

-Toke


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

* Re: [PATCH] crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp()
  2021-01-18 17:13     ` Toke Høiland-Jørgensen
@ 2021-01-18 21:09       ` João Fonseca
  2021-01-21  5:58         ` Tee Hao Wei
  2021-03-10 12:02       ` Greg KH
  1 sibling, 1 reply; 13+ messages in thread
From: João Fonseca @ 2021-01-18 21:09 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen, David Howells
  Cc: Herbert Xu, David S. Miller, Tianjia Zhang, Gilad Ben-Yossef,
	keyrings, linux-crypto, stable

Toke Høiland-Jørgensen <toke@redhat.com> wrote:

> David Howells <dhowells@redhat.com> writes:
>
>> Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>>
>>> Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>
>>>
>>> and also, if you like:
>>>
>>> Tested-by: Toke Høiland-Jørgensen <toke@redhat.com>
>> Thanks!
> Any chance of that patch getting into -stable anytime soon? Would be
> nice to have working WiFi without having to compile my own kernels ;)
>
> -Toke
>
>
>
I have also just tested the patch and it seems to be working with the
PEAP method. I would also like to have this patch in the stable branch
as I normally don't have to compile my own kernels.

Also, if you want to add another tester:

Tested-by: João Fonseca <jpedrofonseca@ua.pt>

Thanks for the patch everyone.

-João 


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

* Re: [PATCH] crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp()
  2021-01-18 21:09       ` João Fonseca
@ 2021-01-21  5:58         ` Tee Hao Wei
  0 siblings, 0 replies; 13+ messages in thread
From: Tee Hao Wei @ 2021-01-21  5:58 UTC (permalink / raw)
  To: linux-crypto

On 19/1/21 5:09 am, João Fonseca wrote:
> Toke Høiland-Jørgensen <toke@redhat.com> wrote:
> 
>> David Howells <dhowells@redhat.com> writes:
>>
>>> Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>>>
>>>> Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>
>>>>
>>>> and also, if you like:
>>>>
>>>> Tested-by: Toke Høiland-Jørgensen <toke@redhat.com>
>>> Thanks!
>> Any chance of that patch getting into -stable anytime soon? Would be
>> nice to have working WiFi without having to compile my own kernels ;)
>>
>> -Toke
>>
>>
>>
> I have also just tested the patch and it seems to be working with the
> PEAP method. I would also like to have this patch in the stable branch
> as I normally don't have to compile my own kernels.
> 
> Also, if you want to add another tester:
> 
> Tested-by: João Fonseca <jpedrofonseca@ua.pt>
> 
> Thanks for the patch everyone.
> 
> -João
> 
> 

The patch finally made it to Torvalds's tree a few hours ago, so it 
should hopefully land in the next stable patch.

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7178a107f5ea7bdb1cc23073234f0ded0ef90ec7

-- 
Hao Wei


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

* Re: [PATCH] crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp()
  2021-01-18 17:13     ` Toke Høiland-Jørgensen
  2021-01-18 21:09       ` João Fonseca
@ 2021-03-10 12:02       ` Greg KH
  2021-03-15 10:52         ` Toke Høiland-Jørgensen
  1 sibling, 1 reply; 13+ messages in thread
From: Greg KH @ 2021-03-10 12:02 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen
  Cc: David Howells, Herbert Xu, David S. Miller, Tianjia Zhang,
	Gilad Ben-Yossef, keyrings, linux-crypto, stable

On Mon, Jan 18, 2021 at 06:13:02PM +0100, Toke Høiland-Jørgensen wrote:
> David Howells <dhowells@redhat.com> writes:
> 
> > Toke Høiland-Jørgensen <toke@redhat.com> wrote:
> >
> >> Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>
> >> 
> >> and also, if you like:
> >> 
> >> Tested-by: Toke Høiland-Jørgensen <toke@redhat.com>
> >
> > Thanks!
> 
> Any chance of that patch getting into -stable anytime soon? Would be
> nice to have working WiFi without having to compile my own kernels ;)

What ever happened to this patch?  I can't seem to find it in Linus's
tree anywhere :(

thanks,

greg k-h

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

* Re: [PATCH] crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp()
  2021-03-10 12:02       ` Greg KH
@ 2021-03-15 10:52         ` Toke Høiland-Jørgensen
  2021-03-15 12:07           ` Greg KH
  0 siblings, 1 reply; 13+ messages in thread
From: Toke Høiland-Jørgensen @ 2021-03-15 10:52 UTC (permalink / raw)
  To: Greg KH
  Cc: David Howells, Herbert Xu, David S. Miller, Tianjia Zhang,
	Gilad Ben-Yossef, keyrings, linux-crypto, stable

Greg KH <gregkh@linuxfoundation.org> writes:

> On Mon, Jan 18, 2021 at 06:13:02PM +0100, Toke Høiland-Jørgensen wrote:
>> David Howells <dhowells@redhat.com> writes:
>> 
>> > Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>> >
>> >> Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>
>> >> 
>> >> and also, if you like:
>> >> 
>> >> Tested-by: Toke Høiland-Jørgensen <toke@redhat.com>
>> >
>> > Thanks!
>> 
>> Any chance of that patch getting into -stable anytime soon? Would be
>> nice to have working WiFi without having to compile my own kernels ;)
>
> What ever happened to this patch?  I can't seem to find it in Linus's
> tree anywhere :(

This was a matter of crossed streams: Tianjia had already submitted an
identical fix, which went in as:

7178a107f5ea ("X.509: Fix crash caused by NULL pointer")

And that has made it into -stable, so all is well as far as I'm
concerned. Sorry for the confusion!

-Toke


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

* Re: [PATCH] crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp()
  2021-03-15 10:52         ` Toke Høiland-Jørgensen
@ 2021-03-15 12:07           ` Greg KH
  0 siblings, 0 replies; 13+ messages in thread
From: Greg KH @ 2021-03-15 12:07 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen
  Cc: David Howells, Herbert Xu, David S. Miller, Tianjia Zhang,
	Gilad Ben-Yossef, keyrings, linux-crypto, stable

On Mon, Mar 15, 2021 at 11:52:52AM +0100, Toke Høiland-Jørgensen wrote:
> Greg KH <gregkh@linuxfoundation.org> writes:
> 
> > On Mon, Jan 18, 2021 at 06:13:02PM +0100, Toke Høiland-Jørgensen wrote:
> >> David Howells <dhowells@redhat.com> writes:
> >> 
> >> > Toke Høiland-Jørgensen <toke@redhat.com> wrote:
> >> >
> >> >> Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>
> >> >> 
> >> >> and also, if you like:
> >> >> 
> >> >> Tested-by: Toke Høiland-Jørgensen <toke@redhat.com>
> >> >
> >> > Thanks!
> >> 
> >> Any chance of that patch getting into -stable anytime soon? Would be
> >> nice to have working WiFi without having to compile my own kernels ;)
> >
> > What ever happened to this patch?  I can't seem to find it in Linus's
> > tree anywhere :(
> 
> This was a matter of crossed streams: Tianjia had already submitted an
> identical fix, which went in as:
> 
> 7178a107f5ea ("X.509: Fix crash caused by NULL pointer")
> 
> And that has made it into -stable, so all is well as far as I'm
> concerned. Sorry for the confusion!

No worries, thanks for letting me know.

greg k-h

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

end of thread, other threads:[~2021-03-15 12:08 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-12 16:10 [PATCH] crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp() Toke Høiland-Jørgensen
2021-01-13  2:39 ` Tianjia Zhang
2021-01-13 11:29   ` Toke Høiland-Jørgensen
2021-01-13 11:11 ` David Howells
2021-01-13 11:36   ` Toke Høiland-Jørgensen
2021-01-13 12:57   ` David Howells
2021-01-18 17:13     ` Toke Høiland-Jørgensen
2021-01-18 21:09       ` João Fonseca
2021-01-21  5:58         ` Tee Hao Wei
2021-03-10 12:02       ` Greg KH
2021-03-15 10:52         ` Toke Høiland-Jørgensen
2021-03-15 12:07           ` Greg KH
2021-01-14  2:55   ` Jarkko Sakkinen

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.