From 429266feedb3eccc450d823d207cb1464c4c43dc Mon Sep 17 00:00:00 2001 From: Dan Andresan Date: Fri, 26 Oct 2018 12:01:51 +0200 Subject: python: Fix CVEs CVE: CVE-2017-1000158 CVE-2018-1060 CVE-2018-1061 CVE-2017-1000158 python in the upstream pyro is 2.7.13 CVE-2018-1060 - python in the upstream pyro is 2.7.13 CVE-2018-1061 - python in the upstream pyro is 2.7.13 Reference: CVE-2017-1000158 https://github.com/python/cpython/commit/c3c9db89273fabc62ea1b48389d9a3000c1c03ae CVE-2018-1060 https://github.com/python/cpython/commit/937ac1fe069a4dc8471dff205f553d82e724015b CVE-2018-1061 https://github.com/python/cpython/commit/937ac1fe069a4dc8471dff205f553d82e724015b Change-Id: I09dc5e7d1754c00d4bcdf57b1124370e3d790e5a Signed-off-by: Andreas Wellving Signed-off-by: Adrian Mangeac --- ...57-Check-prevent-integer-overflow-in-PySt.patch | 62 ++++++++ ...81-Fix-catastrophic-backtracking-vulns-GH.patch | 161 +++++++++++++++++++++ recipes-devtools/python/python_2.7.13.bbappend | 7 + 3 files changed, 230 insertions(+) create mode 100644 recipes-devtools/python/python/CVE-2017-1000158-2.7-bpo-30657-Check-prevent-integer-overflow-in-PySt.patch create mode 100644 recipes-devtools/python/python/CVE-2018-1060-CVE-2018-1061-2.7-bpo-32981-Fix-catastrophic-backtracking-vulns-GH.patch create mode 100644 recipes-devtools/python/python_2.7.13.bbappend diff --git a/recipes-devtools/python/python/CVE-2017-1000158-2.7-bpo-30657-Check-prevent-integer-overflow-in-PySt.patch b/recipes-devtools/python/python/CVE-2017-1000158-2.7-bpo-30657-Check-prevent-integer-overflow-in-PySt.patch new file mode 100644 index 0000000..b94ae06 --- /dev/null +++ b/recipes-devtools/python/python/CVE-2017-1000158-2.7-bpo-30657-Check-prevent-integer-overflow-in-PySt.patch @@ -0,0 +1,62 @@ +From cab6444ff39a91084bdac08d0ae66734cea943f6 Mon Sep 17 00:00:00 2001 +From: Andreas Wellving +Date: Mon, 22 Oct 2018 10:13:00 +0200 +Subject: [PATCH] [2.7] bpo-30657: Check & prevent integer overflow in PyString_DecodeEscape (#2174) + +CVE: CVE-2017-1000158 +Upstream-Status: Backport [https://github.com/python/cpython/commit/c3c9db89273fabc62ea1b48389d9a3000c1c03ae] + +Signed-off-by: Andreas Wellving +--- + Misc/ACKS | 1 + + Misc/NEWS | 3 +++ + Objects/stringobject.c | 8 +++++++- + 3 files changed, 11 insertions(+), 1 deletion(-) + +diff --git a/Misc/ACKS b/Misc/ACKS +index 952d6dd..6ea6639 100644 +--- a/Misc/ACKS ++++ b/Misc/ACKS +@@ -151,6 +151,7 @@ Gregory Bond + Matias Bordese + Jonas Borgström + Jurjen Bos ++Jay Bosamiya + Peter Bosch + Dan Boswell + Eric Bouck +diff --git a/Misc/NEWS b/Misc/NEWS +index b779e82..ab0b687 100644 +--- a/Misc/NEWS ++++ b/Misc/NEWS +@@ -21,6 +21,9 @@ What's New in Python 2.7.13 release candidate 1? + Core and Builtins + ----------------- + ++- bpo-30657: Fixed possible integer overflow in PyString_DecodeEscape. ++ Patch by Jay Bosamiya. ++ + - Issue #28847: dumbdbm no longer writes the index file in when it is not + changed and supports reading read-only files. + +diff --git a/Objects/stringobject.c b/Objects/stringobject.c +index 4e38735..6c31c5b 100644 +--- a/Objects/stringobject.c ++++ b/Objects/stringobject.c +@@ -612,7 +612,13 @@ PyObject *PyString_DecodeEscape(const char *s, + char *p, *buf; + const char *end; + PyObject *v; +- Py_ssize_t newlen = recode_encoding ? 4*len:len; ++ Py_ssize_t newlen; ++ /* Check for integer overflow */ ++ if (recode_encoding && (len > PY_SSIZE_T_MAX / 4)) { ++ PyErr_SetString(PyExc_OverflowError, "string is too large"); ++ return NULL; ++ } ++ newlen = recode_encoding ? 4*len:len; + v = PyString_FromStringAndSize((char *)NULL, newlen); + if (v == NULL) + return NULL; + + diff --git a/recipes-devtools/python/python/CVE-2018-1060-CVE-2018-1061-2.7-bpo-32981-Fix-catastrophic-backtracking-vulns-GH.patch b/recipes-devtools/python/python/CVE-2018-1060-CVE-2018-1061-2.7-bpo-32981-Fix-catastrophic-backtracking-vulns-GH.patch new file mode 100644 index 0000000..6239503 --- /dev/null +++ b/recipes-devtools/python/python/CVE-2018-1060-CVE-2018-1061-2.7-bpo-32981-Fix-catastrophic-backtracking-vulns-GH.patch @@ -0,0 +1,161 @@ +From fbfdc20005366facc079675ee7e217a0993ef2f9 Mon Sep 17 00:00:00 2001 +From: Andreas Wellving +Date: Mon, 22 Oct 2018 13:44:16 +0200 +Subject: [PATCH] [2.7] bpo-32981: Fix catastrophic backtracking vulns + (GH-5955) + +* Prevent low-grade poplib REDOS (CVE-2018-1060) + +The regex to test a mail server's timestamp is susceptible to +catastrophic backtracking on long evil responses from the server. + +Happily, the maximum length of malicious inputs is 2K thanks +to a limit introduced in the fix for CVE-2013-1752. + +A 2KB evil response from the mail server would result in small slowdowns +(milliseconds vs. microseconds) accumulated over many apop calls. +This is a potential DOS vector via accumulated slowdowns. + +Replace it with a similar non-vulnerable regex. + +The new regex is RFC compliant. +The old regex was non-compliant in edge cases. + +* Prevent difflib REDOS (CVE-2018-1061) + +The default regex for IS_LINE_JUNK is susceptible to +catastrophic backtracking. +This is a potential DOS vector. + +Replace it with an equivalent non-vulnerable regex. + +Also introduce unit and REDOS tests for difflib. + +CVE: CVE-2018-1060 +CVE: CVE-2018-1061 +Upstream-Status: Backport [https://github.com/python/cpython/commit/937ac1fe069a4dc8471dff205f553d82e724015b] + +Co-authored-by: Tim Peters +Co-authored-by: Christian Heimes . +(cherry picked from commit 0e6c8ee2358a2e23117501826c008842acb835ac) +Signed-off-by: Andreas Wellving +--- + Lib/difflib.py | 2 +- + Lib/poplib.py | 2 +- + Lib/test/test_difflib.py | 22 +++++++++++++++++++++- + Lib/test/test_poplib.py | 10 ++++++++++ + Misc/ACKS | 1 + + .../2018-03-02-10-24-52.bpo-32981.O_qDyj.rst | 4 ++++ + 6 files changed, 38 insertions(+), 3 deletions(-) + create mode 100644 Misc/NEWS.d/next/Security/2018-03-02-10-24-52.bpo-32981.O_qDyj.rst + +diff --git a/Lib/difflib.py b/Lib/difflib.py +index 1c6fbdb..788a92d 100644 +--- a/Lib/difflib.py ++++ b/Lib/difflib.py +@@ -1103,7 +1103,7 @@ class Differ: + + import re + +-def IS_LINE_JUNK(line, pat=re.compile(r"\s*#?\s*$").match): ++def IS_LINE_JUNK(line, pat=re.compile(r"\s*(?:#\s*)?$").match): + r""" + Return 1 for ignorable line: iff `line` is blank or contains a single '#'. + +diff --git a/Lib/poplib.py b/Lib/poplib.py +index b91e5f7..a238510 100644 +--- a/Lib/poplib.py ++++ b/Lib/poplib.py +@@ -274,7 +274,7 @@ class POP3: + return self._shortcmd('RPOP %s' % user) + + +- timestamp = re.compile(r'\+OK.*(<[^>]+>)') ++ timestamp = re.compile(br'\+OK.[^<]*(<.*>)') + + def apop(self, user, secret): + """Authorisation +diff --git a/Lib/test/test_difflib.py b/Lib/test/test_difflib.py +index 35f2c36..d8277b7 100644 +--- a/Lib/test/test_difflib.py ++++ b/Lib/test/test_difflib.py +@@ -269,13 +269,33 @@ class TestOutputFormat(unittest.TestCase): + self.assertEqual(fmt(3,6), '4,6') + self.assertEqual(fmt(0,0), '0') + ++class TestJunkAPIs(unittest.TestCase): ++ def test_is_line_junk_true(self): ++ for line in ['#', ' ', ' #', '# ', ' # ', '']: ++ self.assertTrue(difflib.IS_LINE_JUNK(line), repr(line)) ++ ++ def test_is_line_junk_false(self): ++ for line in ['##', ' ##', '## ', 'abc ', 'abc #', 'Mr. Moose is up!']: ++ self.assertFalse(difflib.IS_LINE_JUNK(line), repr(line)) ++ ++ def test_is_line_junk_REDOS(self): ++ evil_input = ('\t' * 1000000) + '##' ++ self.assertFalse(difflib.IS_LINE_JUNK(evil_input)) ++ ++ def test_is_character_junk_true(self): ++ for char in [' ', '\t']: ++ self.assertTrue(difflib.IS_CHARACTER_JUNK(char), repr(char)) ++ ++ def test_is_character_junk_false(self): ++ for char in ['a', '#', '\n', '\f', '\r', '\v']: ++ self.assertFalse(difflib.IS_CHARACTER_JUNK(char), repr(char)) + + def test_main(): + difflib.HtmlDiff._default_prefix = 0 + Doctests = doctest.DocTestSuite(difflib) + run_unittest( + TestWithAscii, TestAutojunk, TestSFpatches, TestSFbugs, +- TestOutputFormat, Doctests) ++ TestOutputFormat, TestJunkAPIs) + + if __name__ == '__main__': + test_main() +diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py +index 23d6887..d214375 100644 +--- a/Lib/test/test_poplib.py ++++ b/Lib/test/test_poplib.py +@@ -211,6 +211,16 @@ class TestPOP3Class(TestCase): + def test_rpop(self): + self.assertOK(self.client.rpop('foo')) + ++ def test_apop_REDOS(self): ++ # Replace welcome with very long evil welcome. ++ # NB The upper bound on welcome length is currently 2048. ++ # At this length, evil input makes each apop call take ++ # on the order of milliseconds instead of microseconds. ++ evil_welcome = b'+OK' + (b'<' * 1000000) ++ with test_support.swap_attr(self.client, 'welcome', evil_welcome): ++ # The evil welcome is invalid, so apop should throw. ++ self.assertRaises(poplib.error_proto, self.client.apop, 'a', 'kb') ++ + def test_top(self): + expected = ('+OK 116 bytes', + ['From: postmaster@python.org', 'Content-Type: text/plain', +diff --git a/Misc/ACKS b/Misc/ACKS +index 9cbc230..952d6dd 100644 +--- a/Misc/ACKS ++++ b/Misc/ACKS +@@ -314,6 +314,7 @@ Kushal Das + Jonathan Dasteel + Pierre-Yves David + A. Jesse Jiryu Davis ++Jamie (James C.) Davis + Merlijn van Deen + John DeGood + Ned Deily +diff --git a/Misc/NEWS.d/next/Security/2018-03-02-10-24-52.bpo-32981.O_qDyj.rst b/Misc/NEWS.d/next/Security/2018-03-02-10-24-52.bpo-32981.O_qDyj.rst +new file mode 100644 +index 0000000..9ebabb4 +--- /dev/null ++++ b/Misc/NEWS.d/next/Security/2018-03-02-10-24-52.bpo-32981.O_qDyj.rst +@@ -0,0 +1,4 @@ ++Regexes in difflib and poplib were vulnerable to catastrophic backtracking. ++These regexes formed potential DOS vectors (REDOS). They have been ++refactored. This resolves CVE-2018-1060 and CVE-2018-1061. ++Patch by Jamie Davis. + + diff --git a/recipes-devtools/python/python_2.7.13.bbappend b/recipes-devtools/python/python_2.7.13.bbappend new file mode 100644 index 0000000..d7ec5e2 --- /dev/null +++ b/recipes-devtools/python/python_2.7.13.bbappend @@ -0,0 +1,7 @@ +# look for files in the layer first +FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" + +SRC_URI += " \ + file://CVE-2017-1000158-2.7-bpo-30657-Check-prevent-integer-overflow-in-PySt.patch \ + file://CVE-2018-1060-CVE-2018-1061-2.7-bpo-32981-Fix-catastrophic-backtracking-vulns-GH.patch \ + " -- cgit v1.2.3-54-g00ecf