You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
5.2 KiB

  1. From be5de958e9052e322b0087c6dba81cdad0c3e031 Mon Sep 17 00:00:00 2001
  2. From: "Miss Islington (bot)"
  3. <31488909+miss-islington@users.noreply.github.com>
  4. Date: Tue, 15 Jan 2019 15:03:36 -0800
  5. Subject: [PATCH] bpo-35746: Fix segfault in ssl's cert parser (GH-11569)
  6. Fix a NULL pointer deref in ssl module. The cert parser did not handle CRL
  7. distribution points with empty DP or URI correctly. A malicious or buggy
  8. certificate can result into segfault.
  9. Signed-off-by: Christian Heimes <christian@python.org>
  10. https://bugs.python.org/issue35746
  11. (cherry picked from commit a37f52436f9aa4b9292878b72f3ff1480e2606c3)
  12. Co-authored-by: Christian Heimes <christian@python.org>
  13. ---
  14. Lib/test/talos-2019-0758.pem | 22 +++++++++++++++++++
  15. Lib/test/test_ssl.py | 22 +++++++++++++++++++
  16. .../2019-01-15-18-16-05.bpo-35746.nMSd0j.rst | 3 +++
  17. Modules/_ssl.c | 4 ++++
  18. 4 files changed, 51 insertions(+)
  19. create mode 100644 Lib/test/talos-2019-0758.pem
  20. create mode 100644 Misc/NEWS.d/next/Security/2019-01-15-18-16-05.bpo-35746.nMSd0j.rst
  21. diff --git a/Lib/test/talos-2019-0758.pem b/Lib/test/talos-2019-0758.pem
  22. new file mode 100644
  23. index 0000000000..13b95a77fd
  24. --- /dev/null
  25. +++ b/Lib/test/talos-2019-0758.pem
  26. @@ -0,0 +1,22 @@
  27. +-----BEGIN CERTIFICATE-----
  28. +MIIDqDCCApKgAwIBAgIBAjALBgkqhkiG9w0BAQswHzELMAkGA1UEBhMCVUsxEDAO
  29. +BgNVBAMTB2NvZHktY2EwHhcNMTgwNjE4MTgwMDU4WhcNMjgwNjE0MTgwMDU4WjA7
  30. +MQswCQYDVQQGEwJVSzEsMCoGA1UEAxMjY29kZW5vbWljb24tdm0tMi50ZXN0Lmxh
  31. +bC5jaXNjby5jb20wggEiMA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eqOvJGjsSWp3kL0y3GaQ+
  47. +10T1rfkKJub2+m9A9duin1fn6tHc2wSvB7m3DA==
  48. +-----END CERTIFICATE-----
  49. diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
  50. index f1b9565c8d..b6794ce3a8 100644
  51. --- a/Lib/test/test_ssl.py
  52. +++ b/Lib/test/test_ssl.py
  53. @@ -116,6 +116,7 @@ NONEXISTINGCERT = data_file("XXXnonexisting.pem")
  54. BADKEY = data_file("badkey.pem")
  55. NOKIACERT = data_file("nokia.pem")
  56. NULLBYTECERT = data_file("nullbytecert.pem")
  57. +TALOS_INVALID_CRLDP = data_file("talos-2019-0758.pem")
  58. DHFILE = data_file("ffdh3072.pem")
  59. BYTES_DHFILE = os.fsencode(DHFILE)
  60. @@ -365,6 +366,27 @@ class BasicSocketTests(unittest.TestCase):
  61. self.assertEqual(p['crlDistributionPoints'],
  62. ('http://SVRIntl-G3-crl.verisign.com/SVRIntlG3.crl',))
  63. + def test_parse_cert_CVE_2019_5010(self):
  64. + p = ssl._ssl._test_decode_cert(TALOS_INVALID_CRLDP)
  65. + if support.verbose:
  66. + sys.stdout.write("\n" + pprint.pformat(p) + "\n")
  67. + self.assertEqual(
  68. + p,
  69. + {
  70. + 'issuer': (
  71. + (('countryName', 'UK'),), (('commonName', 'cody-ca'),)),
  72. + 'notAfter': 'Jun 14 18:00:58 2028 GMT',
  73. + 'notBefore': 'Jun 18 18:00:58 2018 GMT',
  74. + 'serialNumber': '02',
  75. + 'subject': ((('countryName', 'UK'),),
  76. + (('commonName',
  77. + 'codenomicon-vm-2.test.lal.cisco.com'),)),
  78. + 'subjectAltName': (
  79. + ('DNS', 'codenomicon-vm-2.test.lal.cisco.com'),),
  80. + 'version': 3
  81. + }
  82. + )
  83. +
  84. def test_parse_cert_CVE_2013_4238(self):
  85. p = ssl._ssl._test_decode_cert(NULLBYTECERT)
  86. if support.verbose:
  87. diff --git a/Misc/NEWS.d/next/Security/2019-01-15-18-16-05.bpo-35746.nMSd0j.rst b/Misc/NEWS.d/next/Security/2019-01-15-18-16-05.bpo-35746.nMSd0j.rst
  88. new file mode 100644
  89. index 0000000000..dffe347eec
  90. --- /dev/null
  91. +++ b/Misc/NEWS.d/next/Security/2019-01-15-18-16-05.bpo-35746.nMSd0j.rst
  92. @@ -0,0 +1,3 @@
  93. +[CVE-2019-5010] Fix a NULL pointer deref in ssl module. The cert parser did
  94. +not handle CRL distribution points with empty DP or URI correctly. A
  95. +malicious or buggy certificate can result into segfault.
  96. diff --git a/Modules/_ssl.c b/Modules/_ssl.c
  97. index 9894ad821d..9baec8a9bc 100644
  98. --- a/Modules/_ssl.c
  99. +++ b/Modules/_ssl.c
  100. @@ -1516,6 +1516,10 @@ _get_crl_dp(X509 *certificate) {
  101. STACK_OF(GENERAL_NAME) *gns;
  102. dp = sk_DIST_POINT_value(dps, i);
  103. + if (dp->distpoint == NULL) {
  104. + /* Ignore empty DP value, CVE-2019-5010 */
  105. + continue;
  106. + }
  107. gns = dp->distpoint->name.fullname;
  108. for (j=0; j < sk_GENERAL_NAME_num(gns); j++) {
  109. --
  110. 2.17.1