Skip to content

Commit 2dd2769

Browse files
[AUTO-CHERRYPICK] ceph: Fix high CVE-2024-38517 and CVE-2024-39684 - branch main (#9858)
Co-authored-by: Vince Perri <5596945+vinceaperri@users.noreply.github.com>
1 parent d86b17b commit 2dd2769

3 files changed

Lines changed: 71 additions & 2 deletions

File tree

SPECS/ceph/CVE-2024-38517.patch

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
From 9138794bd0e51fe444f14803f891924798a651ac Mon Sep 17 00:00:00 2001
2+
From: Vince Perri <5596945+vinceaperri@users.noreply.github.com>
3+
Date: Mon, 15 Jul 2024 18:33:06 +0000
4+
Subject: [PATCH] Prevent int underflow when parsing exponents
5+
6+
From 8269bc2bc289e9d343bae51cdf6d23ef0950e001 Mon Sep 17 00:00:00 2001
7+
From: Florin Malita <fmalita@gmail.com>
8+
Date: Tue, 15 May 2018 22:48:07 -0400
9+
Subject: [PATCH] Prevent int underflow when parsing exponents
10+
11+
When parsing negative exponents, the current implementation takes
12+
precautions for |exp| to not underflow int.
13+
14+
But that is not sufficient: later on [1], |exp + expFrac| is also
15+
stored to an int - so we must ensure that the sum stays within int
16+
representable values.
17+
18+
Update the exp clamping logic to take expFrac into account.
19+
20+
[1] https://github.com/Tencent/rapidjson/blob/master/include/rapidjson/reader.h#L1690
21+
---
22+
src/rapidjson/include/rapidjson/reader.h | 11 ++++++++++-
23+
src/rapidjson/test/unittest/readertest.cpp | 1 +
24+
2 files changed, 11 insertions(+), 1 deletion(-)
25+
26+
diff --git a/src/rapidjson/include/rapidjson/reader.h b/src/rapidjson/include/rapidjson/reader.h
27+
index 19f8849b1..a9f502307 100644
28+
--- a/src/rapidjson/include/rapidjson/reader.h
29+
+++ b/src/rapidjson/include/rapidjson/reader.h
30+
@@ -1302,9 +1302,18 @@ private:
31+
if (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
32+
exp = static_cast<int>(s.Take() - '0');
33+
if (expMinus) {
34+
+ // (exp + expFrac) must not underflow int => we're detecting when -exp gets
35+
+ // dangerously close to INT_MIN (a pessimistic next digit 9 would push it into
36+
+ // underflow territory):
37+
+ //
38+
+ // -(exp * 10 + 9) + expFrac >= INT_MIN
39+
+ // <=> exp <= (expFrac - INT_MIN - 9) / 10
40+
+ RAPIDJSON_ASSERT(expFrac <= 0);
41+
+ int maxExp = (expFrac + 2147483639) / 10;
42+
+
43+
while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
44+
exp = exp * 10 + static_cast<int>(s.Take() - '0');
45+
- if (exp >= 214748364) { // Issue #313: prevent overflow exponent
46+
+ if (RAPIDJSON_UNLIKELY(exp > maxExp)) {
47+
while (RAPIDJSON_UNLIKELY(s.Peek() >= '0' && s.Peek() <= '9')) // Consume the rest of exponent
48+
s.Take();
49+
}
50+
diff --git a/src/rapidjson/test/unittest/readertest.cpp b/src/rapidjson/test/unittest/readertest.cpp
51+
index 64a1f9c3c..65163de60 100644
52+
--- a/src/rapidjson/test/unittest/readertest.cpp
53+
+++ b/src/rapidjson/test/unittest/readertest.cpp
54+
@@ -242,6 +242,7 @@ static void TestParseDouble() {
55+
TEST_DOUBLE(fullPrecision, "1e-214748363", 0.0); // Maximum supported negative exponent
56+
TEST_DOUBLE(fullPrecision, "1e-214748364", 0.0);
57+
TEST_DOUBLE(fullPrecision, "1e-21474836311", 0.0);
58+
+ TEST_DOUBLE(fullPrecision, "1.00000000001e-2147483638", 0.0);
59+
TEST_DOUBLE(fullPrecision, "0.017976931348623157e+310", 1.7976931348623157e+308); // Max double in another form
60+
61+
// Since
62+
--
63+
2.34.1
64+

SPECS/ceph/CVE-2024-39684.nopatch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CVE-2024-39684 is a duplicate of CVE-2024-38517

SPECS/ceph/ceph.spec

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Summary: User space components of the Ceph file system
66
Name: ceph
77
Version: 16.2.10
8-
Release: 4%{?dist}
8+
Release: 5%{?dist}
99
License: LGPLv2 and LGPLv3 and CC-BY-SA and GPLv2 and Boost and BSD and MIT and Public Domain and GPLv3 and ASL-2.0
1010
URL: https://ceph.io/
1111
Vendor: Microsoft Corporation
@@ -16,8 +16,9 @@ Patch1: CVE-2021-28361.patch
1616
Patch2: CVE-2022-3650.patch
1717
Patch3: CVE-2022-3854.patch
1818
Patch4: CVE-2023-43040.patch
19+
Patch5: CVE-2024-38517.patch
1920

20-
#
21+
#
2122
# Copyright (C) 2004-2019 The Ceph Project Developers. See COPYING file
2223
# at the top-level directory of this distribution and at
2324
# https://github.com/ceph/ceph/blob/master/COPYING
@@ -1810,6 +1811,9 @@ exit 0
18101811
%config %{_sysconfdir}/prometheus/ceph/ceph_default_alerts.yml
18111812

18121813
%changelog
1814+
* Mon Jul 15 2024 Vince Perri <viperri@microsoft.com> - 16.2.10-5
1815+
- Patch CVE-2024-38517
1816+
18131817
* Fri May 17 2024 Henry Beberman <henry.beberman@microsoft.com> - 16.2.10-4
18141818
- Patch CVE-2023-43040
18151819

0 commit comments

Comments
 (0)