crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp()
Subsystems (4)
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.
--- crypto/asymmetric_keys/public_key.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/asymmetric_keys/public_key.c +1 -1
@@ -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
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 fromasymmetric_key_verify_signature(), thepkey_algofield of structpublic_key_signaturewill be NULL, which causes a NULL pointer dereference in thestrcmp()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")Signed-off-by Toke Høiland-Jørgensen <[email protected]>--- crypto/asymmetric_keys/public_key.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)crypto/asymmetric_keys/public_key.c +1
-1@@ -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;
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
David Howells
maintainerI'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.
crypto/asymmetric_keys/public_key.c +2 -1
@@ -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;
Quoted 1 line · David Howells
I'm intending to use Tianjia's patch.
Yeah, sorry for missing that.
Quoted 1 line
Would you like to add a Reviewed-by?
Sure:
and also, if you like:
David Howells
maintainerQuoted 5 lines · Toke Høiland-Jørgensen
Reviewed-by Toke Høiland-Jørgensen <[email protected]>and also, if you like:
Thanks!
David
Quoted 9 lines · David Howells
Quoted 5 lines · Toke Høiland-Jørgensen
Reviewed-by Toke Høiland-Jørgensen <[email protected]>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
João Fonseca
Tested-byQuoted 6 lines · Toke Høiland-Jørgensen
Quoted 4 lines · David Howells
Quoted 2 lines · Toke Høiland-Jørgensen
Reviewed-by Toke Høiland-Jørgensen <[email protected]>
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
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
Reviewed-by Toke Høiland-Jørgensen <[email protected]>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:
Tested-by João Fonseca <[email protected]>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.
Signature · 1 line
Hao Wei
Greg KH
maintainerQuoted 6 lines · Toke Høiland-Jørgensen
Quoted 4 lines · David Howells
Quoted 2 lines · Toke Høiland-Jørgensen
Reviewed-by Toke Høiland-Jørgensen <[email protected]>
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
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
Reviewed-by Toke Høiland-Jørgensen <[email protected]>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
Greg KH
maintainerQuoted 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
Reviewed-by Toke Høiland-Jørgensen <[email protected]>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
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
---
commit11078a592e6dcea6b9f30e822d3d30e3defc99caAuthor: Tianjia Zhang <[email protected]> Date: Thu Jan 7 17:28:55 2021 +0800X.509: Fix crash caused by NULL pointer
On the following call path,
sig->pkey_algois not assigned inasymmetric_key_verify_signature(), which causes runtime crash inpublic_key_verify_signature().
keyctl_pkey_verify
asymmetric_key_verify_signature
verify_signature
public_key_verify_signatureThis 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+Reported-by Tobias Markus <[email protected]>Signed-off-by Tianjia Zhang <[email protected]>Signed-off-by David Howells <[email protected]>crypto/asymmetric_keys/public_key.c +2
-1@@ -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;