|
| 1 | +From 22f1d9704ac38c7102e7a68272b07355cad4925a Mon Sep 17 00:00:00 2001 |
| 2 | +From: Sindhu Karri <lakarri@microsoft.com> |
| 3 | +Date: Tue, 29 Oct 2024 10:17:59 +0000 |
| 4 | +Subject: [PATCH] CVE-2024-50602 |
| 5 | + |
| 6 | +--- |
| 7 | +From 51c7019069b862e88d94ed228659e70bddd5de09 Mon Sep 17 00:00:00 2001 |
| 8 | +From: Sebastian Pipping <sebastian@pipping.org> |
| 9 | +Date: Mon, 21 Oct 2024 01:42:54 +0200 |
| 10 | +Subject: [PATCH 1/3] lib: Make XML_StopParser refuse to stop/suspend an |
| 11 | + unstarted parser |
| 12 | + |
| 13 | + |
| 14 | +From 5fb89e7b3afa1c314b34834fe729cd063f65a4d4 Mon Sep 17 00:00:00 2001 |
| 15 | +From: Sebastian Pipping <sebastian@pipping.org> |
| 16 | +Date: Mon, 21 Oct 2024 01:46:11 +0200 |
| 17 | +Subject: [PATCH 2/3] lib: Be explicit about XML_PARSING in XML_StopParser |
| 18 | + |
| 19 | +From b3836ff534c7cc78128fe7b935aad3d4353814ed Mon Sep 17 00:00:00 2001 |
| 20 | +From: Sebastian Pipping <sebastian@pipping.org> |
| 21 | +Date: Sun, 20 Oct 2024 23:24:27 +0200 |
| 22 | +Subject: [PATCH 3/3] tests: Cover XML_StopParser's new handling of status |
| 23 | + XML_INITIALIZED |
| 24 | + |
| 25 | +Prior to the fix to XML_StopParser, test test_misc_resumeparser_not_crashing |
| 26 | +would crash with a NULL pointer dereference in function normal_updatePosition. |
| 27 | +This was the AddressSanitizer output: |
| 28 | + |
| 29 | +> AddressSanitizer:DEADLYSIGNAL |
| 30 | +> ================================================================= |
| 31 | +> ==19700==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x5623e07ad85f bp 0x7ffcf40da650 sp 0x7ffcf40da590 T0) |
| 32 | +> ==19700==The signal is caused by a READ memory access. |
| 33 | +> ==19700==Hint: address points to the zero page. |
| 34 | +> #0 0x5623e07ad85f in normal_updatePosition [..]/lib/xmltok_impl.c:1781:13 |
| 35 | +> #1 0x5623e07a52ff in initUpdatePosition [..]/lib/xmltok.c:1031:3 |
| 36 | +> #2 0x5623e0762760 in XML_ResumeParser [..]/lib/xmlparse.c:2297:3 |
| 37 | +> #3 0x5623e074f7c1 in test_misc_resumeparser_not_crashing() misc_tests_cxx.cpp |
| 38 | +> #4 0x5623e074e228 in srunner_run_all ([..]/build_asan_fuzzers/tests/runtests_cxx+0x136228) |
| 39 | +> #5 0x5623e0753d2d in main ([..]/build_asan_fuzzers/tests/runtests_cxx+0x13bd2d) |
| 40 | +> #6 0x7f802a39af79 (/lib64/libc.so.6+0x25f79) |
| 41 | +> #7 0x7f802a39b034 in __libc_start_main (/lib64/libc.so.6+0x26034) |
| 42 | +> #8 0x5623e064f340 in _start ([..]/build_asan_fuzzers/tests/runtests_cxx+0x37340) |
| 43 | +> |
| 44 | +> AddressSanitizer can not provide additional info. |
| 45 | +> SUMMARY: AddressSanitizer: SEGV [..]/lib/xmltok_impl.c:1781:13 in normal_updatePosition |
| 46 | +> ==19700==ABORTING |
| 47 | + |
| 48 | +And this the UndefinedBehaviorSanitizer output: |
| 49 | + |
| 50 | +> [..]/lib/xmltok_impl.c:1781:13: runtime error: load of null pointer of type 'const char' > SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior [..]/lib/xmltok_impl.c:1781:13 in |
| 51 | +--- |
| 52 | + lib/expat.h | 4 +++- |
| 53 | + lib/xmlparse.c | 11 ++++++++++- |
| 54 | + tests/misc_tests.c | 24 ++++++++++++++++++++++++ |
| 55 | + 3 files changed, 37 insertions(+), 2 deletions(-) |
| 56 | + |
| 57 | +diff --git a/lib/expat.h b/lib/expat.h |
| 58 | +index d0d6015..3ba6130 100644 |
| 59 | +--- a/lib/expat.h |
| 60 | ++++ b/lib/expat.h |
| 61 | +@@ -130,7 +130,9 @@ enum XML_Error { |
| 62 | + /* Added in 2.3.0. */ |
| 63 | + XML_ERROR_NO_BUFFER, |
| 64 | + /* Added in 2.4.0. */ |
| 65 | +- XML_ERROR_AMPLIFICATION_LIMIT_BREACH |
| 66 | ++ XML_ERROR_AMPLIFICATION_LIMIT_BREACH, |
| 67 | ++ /* Added in 2.6.4. */ |
| 68 | ++ XML_ERROR_NOT_STARTED, |
| 69 | + }; |
| 70 | + |
| 71 | + enum XML_Content_Type { |
| 72 | +diff --git a/lib/xmlparse.c b/lib/xmlparse.c |
| 73 | +index d9285b2..983f6df 100644 |
| 74 | +--- a/lib/xmlparse.c |
| 75 | ++++ b/lib/xmlparse.c |
| 76 | +@@ -2234,6 +2234,9 @@ XML_StopParser(XML_Parser parser, XML_Bool resumable) { |
| 77 | + if (parser == NULL) |
| 78 | + return XML_STATUS_ERROR; |
| 79 | + switch (parser->m_parsingStatus.parsing) { |
| 80 | ++ case XML_INITIALIZED: |
| 81 | ++ parser->m_errorCode = XML_ERROR_NOT_STARTED; |
| 82 | ++ return XML_STATUS_ERROR; |
| 83 | + case XML_SUSPENDED: |
| 84 | + if (resumable) { |
| 85 | + parser->m_errorCode = XML_ERROR_SUSPENDED; |
| 86 | +@@ -2244,7 +2247,7 @@ XML_StopParser(XML_Parser parser, XML_Bool resumable) { |
| 87 | + case XML_FINISHED: |
| 88 | + parser->m_errorCode = XML_ERROR_FINISHED; |
| 89 | + return XML_STATUS_ERROR; |
| 90 | +- default: |
| 91 | ++ case XML_PARSING: |
| 92 | + if (resumable) { |
| 93 | + #ifdef XML_DTD |
| 94 | + if (parser->m_isParamEntity) { |
| 95 | +@@ -2255,6 +2258,9 @@ XML_StopParser(XML_Parser parser, XML_Bool resumable) { |
| 96 | + parser->m_parsingStatus.parsing = XML_SUSPENDED; |
| 97 | + } else |
| 98 | + parser->m_parsingStatus.parsing = XML_FINISHED; |
| 99 | ++ break; |
| 100 | ++ default: |
| 101 | ++ assert(0); |
| 102 | + } |
| 103 | + return XML_STATUS_OK; |
| 104 | + } |
| 105 | +@@ -2519,6 +2525,9 @@ XML_ErrorString(enum XML_Error code) { |
| 106 | + case XML_ERROR_AMPLIFICATION_LIMIT_BREACH: |
| 107 | + return XML_L( |
| 108 | + "limit on input amplification factor (from DTD and entities) breached"); |
| 109 | ++ /* Added in 2.6.4. */ |
| 110 | ++ case XML_ERROR_NOT_STARTED: |
| 111 | ++ return XML_L("parser not started"); |
| 112 | + } |
| 113 | + return NULL; |
| 114 | + } |
| 115 | +diff --git a/tests/misc_tests.c b/tests/misc_tests.c |
| 116 | +index 2ee9320..1766e41 100644 |
| 117 | +--- a/tests/misc_tests.c |
| 118 | ++++ b/tests/misc_tests.c |
| 119 | +@@ -496,6 +496,28 @@ START_TEST(test_misc_char_handler_stop_without_leak) { |
| 120 | + } |
| 121 | + END_TEST |
| 122 | + |
| 123 | ++START_TEST(test_misc_resumeparser_not_crashing) { |
| 124 | ++ XML_Parser parser = XML_ParserCreate(NULL); |
| 125 | ++ XML_GetBuffer(parser, 1); |
| 126 | ++ XML_StopParser(parser, /*resumable=*/XML_TRUE); |
| 127 | ++ XML_ResumeParser(parser); // could crash here, previously |
| 128 | ++ XML_ParserFree(parser); |
| 129 | ++} |
| 130 | ++END_TEST |
| 131 | ++ |
| 132 | ++START_TEST(test_misc_stopparser_rejects_unstarted_parser) { |
| 133 | ++ const XML_Bool cases[] = {XML_TRUE, XML_FALSE}; |
| 134 | ++ for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { |
| 135 | ++ const XML_Bool resumable = cases[i]; |
| 136 | ++ XML_Parser parser = XML_ParserCreate(NULL); |
| 137 | ++ assert_true(XML_GetErrorCode(parser) == XML_ERROR_NONE); |
| 138 | ++ assert_true(XML_StopParser(parser, resumable) == XML_STATUS_ERROR); |
| 139 | ++ assert_true(XML_GetErrorCode(parser) == XML_ERROR_NOT_STARTED); |
| 140 | ++ XML_ParserFree(parser); |
| 141 | ++ } |
| 142 | ++} |
| 143 | ++END_TEST |
| 144 | ++ |
| 145 | + void |
| 146 | + make_miscellaneous_test_case(Suite *s) { |
| 147 | + TCase *tc_misc = tcase_create("miscellaneous tests"); |
| 148 | +@@ -520,4 +542,6 @@ make_miscellaneous_test_case(Suite *s) { |
| 149 | + test_misc_create_external_entity_parser_with_null_context); |
| 150 | + tcase_add_test(tc_misc, test_misc_general_entities_support); |
| 151 | + tcase_add_test(tc_misc, test_misc_char_handler_stop_without_leak); |
| 152 | ++ tcase_add_test(tc_misc, test_misc_resumeparser_not_crashing); |
| 153 | ++ tcase_add_test(tc_misc, test_misc_stopparser_rejects_unstarted_parser); |
| 154 | + } |
| 155 | +-- |
| 156 | +2.33.8 |
0 commit comments