Blame SOURCES/00317-CVE-2019-5010.patch

dd3773
From c660debb97f4f422255a82fef2d77804552c043a Mon Sep 17 00:00:00 2001
dd3773
From: Christian Heimes <christian@python.org>
dd3773
Date: Tue, 15 Jan 2019 18:16:30 +0100
dd3773
Subject: [PATCH] bpo-35746: Fix segfault in ssl's cert parser
dd3773
dd3773
CVE-2019-5010, Fix a NULL pointer deref in ssl module. The cert parser did
dd3773
not handle CRL distribution points with empty DP or URI correctly. A
dd3773
malicious or buggy certificate can result into segfault.
dd3773
dd3773
Signed-off-by: Christian Heimes <christian@python.org>
dd3773
---
dd3773
 Lib/test/talos-2019-0758.pem                  | 22 +++++++++++++++++++
dd3773
 Lib/test/test_ssl.py                          | 22 +++++++++++++++++++
dd3773
 .../2019-01-15-18-16-05.bpo-35746.nMSd0j.rst  |  3 +++
dd3773
 Modules/_ssl.c                                |  4 ++++
dd3773
 4 files changed, 51 insertions(+)
dd3773
 create mode 100644 Lib/test/talos-2019-0758.pem
dd3773
 create mode 100644 Misc/NEWS.d/next/Security/2019-01-15-18-16-05.bpo-35746.nMSd0j.rst
dd3773
dd3773
diff --git a/Lib/test/talos-2019-0758.pem b/Lib/test/talos-2019-0758.pem
dd3773
new file mode 100644
dd3773
index 000000000000..13b95a77fd8a
dd3773
--- /dev/null
dd3773
+++ b/Lib/test/talos-2019-0758.pem
dd3773
@@ -0,0 +1,22 @@
dd3773
+-----BEGIN CERTIFICATE-----
dd3773
+MIIDqDCCApKgAwIBAgIBAjALBgkqhkiG9w0BAQswHzELMAkGA1UEBhMCVUsxEDAO
dd3773
+BgNVBAMTB2NvZHktY2EwHhcNMTgwNjE4MTgwMDU4WhcNMjgwNjE0MTgwMDU4WjA7
dd3773
+MQswCQYDVQQGEwJVSzEsMCoGA1UEAxMjY29kZW5vbWljb24tdm0tMi50ZXN0Lmxh
dd3773
+bC5jaXNjby5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC63fGB
dd3773
+J80A9Av1GB0bpt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10T1rfkKJub2+m9A9duin1fn6tHc2wSvB7m3DA==
dd3773
+-----END CERTIFICATE-----
dd3773
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
dd3773
index 7f6b93148f45..1fc657f4d867 100644
dd3773
--- a/Lib/test/test_ssl.py
dd3773
+++ b/Lib/test/test_ssl.py
dd3773
@@ -115,6 +115,7 @@ def data_file(*name):
dd3773
 BADKEY = data_file("badkey.pem")
dd3773
 NOKIACERT = data_file("nokia.pem")
dd3773
 NULLBYTECERT = data_file("nullbytecert.pem")
dd3773
+TALOS_INVALID_CRLDP = data_file("talos-2019-0758.pem")
dd3773
 
dd3773
 DHFILE = data_file("ffdh3072.pem")
dd3773
 BYTES_DHFILE = os.fsencode(DHFILE)
dd3773
@@ -348,6 +349,27 @@ def test_parse_cert(self):
dd3773
         self.assertEqual(p['crlDistributionPoints'],
dd3773
                          ('http://SVRIntl-G3-crl.verisign.com/SVRIntlG3.crl',))
dd3773
 
dd3773
+    def test_parse_cert_CVE_2019_5010(self):
dd3773
+        p = ssl._ssl._test_decode_cert(TALOS_INVALID_CRLDP)
dd3773
+        if support.verbose:
dd3773
+            sys.stdout.write("\n" + pprint.pformat(p) + "\n")
dd3773
+        self.assertEqual(
dd3773
+            p,
dd3773
+            {
dd3773
+                'issuer': (
dd3773
+                    (('countryName', 'UK'),), (('commonName', 'cody-ca'),)),
dd3773
+                'notAfter': 'Jun 14 18:00:58 2028 GMT',
dd3773
+                'notBefore': 'Jun 18 18:00:58 2018 GMT',
dd3773
+                'serialNumber': '02',
dd3773
+                'subject': ((('countryName', 'UK'),),
dd3773
+                            (('commonName',
dd3773
+                              'codenomicon-vm-2.test.lal.cisco.com'),)),
dd3773
+                'subjectAltName': (
dd3773
+                    ('DNS', 'codenomicon-vm-2.test.lal.cisco.com'),),
dd3773
+                'version': 3
dd3773
+            }
dd3773
+        )
dd3773
+
dd3773
     def test_parse_cert_CVE_2013_4238(self):
dd3773
         p = ssl._ssl._test_decode_cert(NULLBYTECERT)
dd3773
         if support.verbose:
dd3773
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
dd3773
new file mode 100644
dd3773
index 000000000000..dffe347eec84
dd3773
--- /dev/null
dd3773
+++ b/Misc/NEWS.d/next/Security/2019-01-15-18-16-05.bpo-35746.nMSd0j.rst
dd3773
@@ -0,0 +1,3 @@
dd3773
+[CVE-2019-5010] Fix a NULL pointer deref in ssl module. The cert parser did
dd3773
+not handle CRL distribution points with empty DP or URI correctly. A
dd3773
+malicious or buggy certificate can result into segfault.
dd3773
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
dd3773
index 4e3352d9e661..0e720e268d93 100644
dd3773
--- a/Modules/_ssl.c
dd3773
+++ b/Modules/_ssl.c
dd3773
@@ -1515,6 +1515,10 @@ _get_crl_dp(X509 *certificate) {
dd3773
         STACK_OF(GENERAL_NAME) *gns;
dd3773
 
dd3773
         dp = sk_DIST_POINT_value(dps, i);
dd3773
+        if (dp->distpoint == NULL) {
dd3773
+            /* Ignore empty DP value, CVE-2019-5010 */
dd3773
+            continue;
dd3773
+        }
dd3773
         gns = dp->distpoint->name.fullname;
dd3773
 
dd3773
         for (j=0; j < sk_GENERAL_NAME_num(gns); j++) {