CVE-2018-14647.patch 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. From 610b4b0dbaedd3099ab76acf678e9cc845d99a76 Mon Sep 17 00:00:00 2001
  2. From: stratakis <cstratak@redhat.com>
  3. Date: Mon, 25 Feb 2019 22:04:09 +0100
  4. Subject: [PATCH] [3.5] bpo-34623: Use XML_SetHashSalt in _elementtree (#9933)
  5. * bpo-34623: Use XML_SetHashSalt in _elementtree (GH-9146)
  6. The C accelerated _elementtree module now initializes hash randomization
  7. salt from _Py_HashSecret instead of libexpat's default CPRNG.
  8. Signed-off-by: Christian Heimes <christian@python.org>
  9. https://bugs.python.org/issue34623
  10. (cherry picked from commit cb5778f00ce48631c7140f33ba242496aaf7102b)
  11. Co-authored-by: Christian Heimes <christian@python.org>
  12. CVE: CVE-2018-14647
  13. Upstream-Status: Backport
  14. [https://github.com/python/cpython/commit/41b48e71ac8a71f56694b548f118bd20ce203410]
  15. Signed-off-by: Dan Tran <dantran@microsoft.com>
  16. ---
  17. Include/pyexpat.h | 4 +++-
  18. .../next/Security/2018-09-10-16-05-39.bpo-34623.Ua9jMv.rst | 2 ++
  19. Modules/_elementtree.c | 5 +++++
  20. Modules/pyexpat.c | 5 +++++
  21. 4 files changed, 15 insertions(+), 1 deletion(-)
  22. create mode 100644 Misc/NEWS.d/next/Security/2018-09-10-16-05-39.bpo-34623.Ua9jMv.rst
  23. diff --git a/Include/pyexpat.h b/Include/pyexpat.h
  24. index 44259bf6d7..07020b5dc9 100644
  25. --- a/Include/pyexpat.h
  26. +++ b/Include/pyexpat.h
  27. @@ -3,7 +3,7 @@
  28. /* note: you must import expat.h before importing this module! */
  29. -#define PyExpat_CAPI_MAGIC "pyexpat.expat_CAPI 1.0"
  30. +#define PyExpat_CAPI_MAGIC "pyexpat.expat_CAPI 1.1"
  31. #define PyExpat_CAPSULE_NAME "pyexpat.expat_CAPI"
  32. struct PyExpat_CAPI
  33. @@ -48,6 +48,8 @@ struct PyExpat_CAPI
  34. enum XML_Status (*SetEncoding)(XML_Parser parser, const XML_Char *encoding);
  35. int (*DefaultUnknownEncodingHandler)(
  36. void *encodingHandlerData, const XML_Char *name, XML_Encoding *info);
  37. + /* might be none for expat < 2.1.0 */
  38. + int (*SetHashSalt)(XML_Parser parser, unsigned long hash_salt);
  39. /* always add new stuff to the end! */
  40. };
  41. diff --git a/Misc/NEWS.d/next/Security/2018-09-10-16-05-39.bpo-34623.Ua9jMv.rst b/Misc/NEWS.d/next/Security/2018-09-10-16-05-39.bpo-34623.Ua9jMv.rst
  42. new file mode 100644
  43. index 0000000000..cbaa4b7506
  44. --- /dev/null
  45. +++ b/Misc/NEWS.d/next/Security/2018-09-10-16-05-39.bpo-34623.Ua9jMv.rst
  46. @@ -0,0 +1,2 @@
  47. +CVE-2018-14647: The C accelerated _elementtree module now initializes hash
  48. +randomization salt from _Py_HashSecret instead of libexpat's default CSPRNG.
  49. diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
  50. index 5dba9f70a9..90c6daf64a 100644
  51. --- a/Modules/_elementtree.c
  52. +++ b/Modules/_elementtree.c
  53. @@ -3282,6 +3282,11 @@ _elementtree_XMLParser___init___impl(XMLParserObject *self, PyObject *html,
  54. PyErr_NoMemory();
  55. return -1;
  56. }
  57. + /* expat < 2.1.0 has no XML_SetHashSalt() */
  58. + if (EXPAT(SetHashSalt) != NULL) {
  59. + EXPAT(SetHashSalt)(self->parser,
  60. + (unsigned long)_Py_HashSecret.expat.hashsalt);
  61. + }
  62. if (target) {
  63. Py_INCREF(target);
  64. diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
  65. index adc9b6cde8..948ab1b703 100644
  66. --- a/Modules/pyexpat.c
  67. +++ b/Modules/pyexpat.c
  68. @@ -1882,6 +1882,11 @@ MODULE_INITFUNC(void)
  69. capi.SetStartDoctypeDeclHandler = XML_SetStartDoctypeDeclHandler;
  70. capi.SetEncoding = XML_SetEncoding;
  71. capi.DefaultUnknownEncodingHandler = PyUnknownEncodingHandler;
  72. +#if XML_COMBINED_VERSION >= 20100
  73. + capi.SetHashSalt = XML_SetHashSalt;
  74. +#else
  75. + capi.SetHashSalt = NULL;
  76. +#endif
  77. /* export using capsule */
  78. capi_object = PyCapsule_New(&capi, PyExpat_CAPSULE_NAME, NULL);
  79. --
  80. 2.22.0.vfs.1.1.57.gbaf16c8