Skip to contentSkip to conversation

crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp()

PATCH In review Toke Høiland-Jørgensen 7 participants 13 messages Jan 12, 2021 – Mar 15, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp()

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.

Fixes 215525639631 ("X.509: support OSCCA SM2-with-SM3 certificate verification")
---
 crypto/asymmetric_keys/public_key.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/asymmetric_keys/public_key.c +1 -1
index 8892908ad58c..35b09e95a870 100644
@@ -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;
Signature · 1 line
2.30.0
#1 lore raw

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

Quoted 30 lines · Toke Høiland-Jørgensen

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.

Fixes 215525639631 ("X.509: support OSCCA SM2-with-SM3 certificate verification")
---
  crypto/asymmetric_keys/public_key.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
crypto/asymmetric_keys/public_key.c +1 -1
index 8892908ad58c..35b09e95a870 100644
@@ -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 lore raw
Quoted 4 lines · Tianjia Zhang

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

maintainer
#3 lore raw
In reply to Toke Høiland-Jørgensen

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

David
---
commit 11078a592e6dcea6b9f30e822d3d30e3defc99ca

Author: Tianjia Zhang <[email protected]>
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 [email protected] # v5.10+
crypto/asymmetric_keys/public_key.c +2 -1
index 8892908ad58c..788a4ba1e2e7 100644
@@ -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;
Tested-by
#7 lore raw
Quoted 6 lines · Toke Høiland-Jørgensen
Quoted 4 lines · David Howells
Quoted 2 lines · Toke Høiland-Jørgensen
Quoted 11 lines
Quoted 4 lines
Quoted 3 lines

and also, if you like:

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:

Thanks for the patch everyone.

-João

#8 lore raw
Quoted 23 lines · João Fonseca
Quoted 6 lines · Toke Høiland-Jørgensen
Quoted 4 lines · David Howells
Quoted 2 lines · Toke Høiland-Jørgensen
Quoted 11 lines
Quoted 4 lines
Quoted 3 lines

and also, if you like:

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.

Quoted 9 lines

Also, if you want to add another tester:

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

Signature · 1 line
Hao Wei
maintainer
#9 lore raw
In reply to Toke Høiland-Jørgensen
Quoted 6 lines · Toke Høiland-Jørgensen
Quoted 4 lines · David Howells
Quoted 2 lines · Toke Høiland-Jørgensen
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

and also, if you like:

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

#10 lore raw
Quoted 11 lines · Greg KH
Quoted 10 lines · Toke Høiland-Jørgensen
Quoted 8 lines · David Howells
Quoted 5 lines · Toke Høiland-Jørgensen

and also, if you like:

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

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

maintainer
#11 lore raw
Quoted 21 lines · Toke Høiland-Jørgensen
Quoted 11 lines · Greg KH
Quoted 10 lines · Toke Høiland-Jørgensen
Quoted 8 lines · David Howells
Quoted 5 lines · Toke Høiland-Jørgensen

and also, if you like:

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

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 :(

Quoted 7 lines

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

maintainer Reviewed-by
#12 lore raw
In reply to David Howells
Quoted 3 lines · David Howells

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

David

I can give.

/Jarkko

Quoted 41 lines

---
commit 11078a592e6dcea6b9f30e822d3d30e3defc99ca

Author: Tianjia Zhang <[email protected]>
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 [email protected] # v5.10+
crypto/asymmetric_keys/public_key.c +2 -1
index 8892908ad58c..788a4ba1e2e7 100644
@@ -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;