Skip to content

Commit bef8a9c

Browse files
[AUTO-CHERRYPICK] Fix expat CVE-2024-50602 fasttrack 3.0 - branch 3.0-dev (#10895)
Co-authored-by: sindhu-karri <33163197+sindhu-karri@users.noreply.github.com>
1 parent bc236a1 commit bef8a9c

6 files changed

Lines changed: 176 additions & 16 deletions

File tree

SPECS/expat/CVE-2024-50602.patch

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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

SPECS/expat/expat.spec

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
Summary: An XML parser library
33
Name: expat
44
Version: 2.6.3
5-
Release: 1%{?dist}
5+
Release: 2%{?dist}
66
License: MIT
77
Vendor: Microsoft Corporation
88
Distribution: Azure Linux
99
Group: System Environment/GeneralLibraries
1010
URL: https://libexpat.github.io/
1111
Source0: https://github.com/libexpat/libexpat/releases/download/R_%{underscore_version}/%{name}-%{version}.tar.bz2
12+
Patch0: CVE-2024-50602.patch
1213
Requires: %{name}-libs = %{version}-%{release}
1314

1415
%description
@@ -29,7 +30,7 @@ Group: System Environment/Libraries
2930
This package contains minimal set of shared expat libraries.
3031

3132
%prep
32-
%autosetup -p2
33+
%autosetup -p1
3334

3435
%build
3536
%configure \
@@ -66,6 +67,9 @@ rm -rf %{buildroot}/%{_docdir}/%{name}
6667
%{_libdir}/libexpat.so.1*
6768

6869
%changelog
70+
* Wed Oct 30 2024 Sindhu Karri <lakarri@microsoft.com> - 2.6.3-2
71+
- Fix CVE-2024-50602 with a patch
72+
6973
* Tue Sep 04 2024 Gary Swalling <gaswal@microsoft.com> - 2.6.3-1
7074
- Upgrade to 2.6.3 to fix CVE-2024-45490, CVE-2024-45491, CVE-2024-45492
7175

toolkit/resources/manifests/package/pkggen_core_aarch64.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ elfutils-libelf-0.189-3.azl3.aarch64.rpm
9999
elfutils-libelf-devel-0.189-3.azl3.aarch64.rpm
100100
elfutils-libelf-devel-static-0.189-3.azl3.aarch64.rpm
101101
elfutils-libelf-lang-0.189-3.azl3.aarch64.rpm
102-
expat-2.6.3-1.azl3.aarch64.rpm
103-
expat-devel-2.6.3-1.azl3.aarch64.rpm
104-
expat-libs-2.6.3-1.azl3.aarch64.rpm
102+
expat-2.6.3-2.azl3.aarch64.rpm
103+
expat-devel-2.6.3-2.azl3.aarch64.rpm
104+
expat-libs-2.6.3-2.azl3.aarch64.rpm
105105
libpipeline-1.5.7-1.azl3.aarch64.rpm
106106
libpipeline-devel-1.5.7-1.azl3.aarch64.rpm
107107
gdbm-1.23-1.azl3.aarch64.rpm

toolkit/resources/manifests/package/pkggen_core_x86_64.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ elfutils-libelf-0.189-3.azl3.x86_64.rpm
9999
elfutils-libelf-devel-0.189-3.azl3.x86_64.rpm
100100
elfutils-libelf-devel-static-0.189-3.azl3.x86_64.rpm
101101
elfutils-libelf-lang-0.189-3.azl3.x86_64.rpm
102-
expat-2.6.3-1.azl3.x86_64.rpm
103-
expat-devel-2.6.3-1.azl3.x86_64.rpm
104-
expat-libs-2.6.3-1.azl3.x86_64.rpm
102+
expat-2.6.3-2.azl3.x86_64.rpm
103+
expat-devel-2.6.3-2.azl3.x86_64.rpm
104+
expat-libs-2.6.3-2.azl3.x86_64.rpm
105105
libpipeline-1.5.7-1.azl3.x86_64.rpm
106106
libpipeline-devel-1.5.7-1.azl3.x86_64.rpm
107107
gdbm-1.23-1.azl3.x86_64.rpm

toolkit/resources/manifests/package/toolchain_aarch64.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ elfutils-libelf-0.189-3.azl3.aarch64.rpm
9292
elfutils-libelf-devel-0.189-3.azl3.aarch64.rpm
9393
elfutils-libelf-devel-static-0.189-3.azl3.aarch64.rpm
9494
elfutils-libelf-lang-0.189-3.azl3.aarch64.rpm
95-
expat-2.6.3-1.azl3.aarch64.rpm
96-
expat-debuginfo-2.6.3-1.azl3.aarch64.rpm
97-
expat-devel-2.6.3-1.azl3.aarch64.rpm
98-
expat-libs-2.6.3-1.azl3.aarch64.rpm
95+
expat-2.6.3-2.azl3.aarch64.rpm
96+
expat-debuginfo-2.6.3-2.azl3.aarch64.rpm
97+
expat-devel-2.6.3-2.azl3.aarch64.rpm
98+
expat-libs-2.6.3-2.azl3.aarch64.rpm
9999
file-5.45-1.azl3.aarch64.rpm
100100
file-debuginfo-5.45-1.azl3.aarch64.rpm
101101
file-devel-5.45-1.azl3.aarch64.rpm

toolkit/resources/manifests/package/toolchain_x86_64.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ elfutils-libelf-0.189-3.azl3.x86_64.rpm
9595
elfutils-libelf-devel-0.189-3.azl3.x86_64.rpm
9696
elfutils-libelf-devel-static-0.189-3.azl3.x86_64.rpm
9797
elfutils-libelf-lang-0.189-3.azl3.x86_64.rpm
98-
expat-2.6.3-1.azl3.x86_64.rpm
99-
expat-debuginfo-2.6.3-1.azl3.x86_64.rpm
100-
expat-devel-2.6.3-1.azl3.x86_64.rpm
101-
expat-libs-2.6.3-1.azl3.x86_64.rpm
98+
expat-2.6.3-2.azl3.x86_64.rpm
99+
expat-debuginfo-2.6.3-2.azl3.x86_64.rpm
100+
expat-devel-2.6.3-2.azl3.x86_64.rpm
101+
expat-libs-2.6.3-2.azl3.x86_64.rpm
102102
file-5.45-1.azl3.x86_64.rpm
103103
file-debuginfo-5.45-1.azl3.x86_64.rpm
104104
file-devel-5.45-1.azl3.x86_64.rpm

0 commit comments

Comments
 (0)